File tree 3 files changed +23
-71
lines changed
3 files changed +23
-71
lines changed Original file line number Diff line number Diff line change @@ -872,36 +872,6 @@ public function random($number = null)
872
872
return new static (Arr::random ($ this ->items , $ number ));
873
873
}
874
874
875
- /**
876
- * Reduce the collection to a single value.
877
- *
878
- * @param callable $callback
879
- * @param mixed $initial
880
- * @return mixed
881
- */
882
- public function reduce (callable $ callback , $ initial = null )
883
- {
884
- return array_reduce ($ this ->items , $ callback , $ initial );
885
- }
886
-
887
- /**
888
- * Reduce an associative collection to a single value.
889
- *
890
- * @param callable $callback
891
- * @param mixed $initial
892
- * @return mixed
893
- */
894
- public function reduceWithKeys (callable $ callback , $ initial = null )
895
- {
896
- $ result = $ initial ;
897
-
898
- foreach ($ this ->items as $ key => $ value ) {
899
- $ result = $ callback ($ result , $ value , $ key );
900
- }
901
-
902
- return $ result ;
903
- }
904
-
905
875
/**
906
876
* Replace the collection items with the given items.
907
877
*
Original file line number Diff line number Diff line change @@ -827,42 +827,6 @@ public function random($number = null)
827
827
return is_null ($ number ) ? $ result : new static ($ result );
828
828
}
829
829
830
- /**
831
- * Reduce the collection to a single value.
832
- *
833
- * @param callable $callback
834
- * @param mixed $initial
835
- * @return mixed
836
- */
837
- public function reduce (callable $ callback , $ initial = null )
838
- {
839
- $ result = $ initial ;
840
-
841
- foreach ($ this as $ value ) {
842
- $ result = $ callback ($ result , $ value );
843
- }
844
-
845
- return $ result ;
846
- }
847
-
848
- /**
849
- * Reduce an associative collection to a single value.
850
- *
851
- * @param callable $callback
852
- * @param mixed $initial
853
- * @return mixed
854
- */
855
- public function reduceWithKeys (callable $ callback , $ initial = null )
856
- {
857
- $ result = $ initial ;
858
-
859
- foreach ($ this as $ key => $ value ) {
860
- $ result = $ callback ($ result , $ value , $ key );
861
- }
862
-
863
- return $ result ;
864
- }
865
-
866
830
/**
867
831
* Replace the collection items with the given items.
868
832
*
Original file line number Diff line number Diff line change @@ -704,16 +704,21 @@ public function pipeInto($class)
704
704
}
705
705
706
706
/**
707
- * Pass the collection to the given callback and then return it .
707
+ * Reduce the collection to a single value .
708
708
*
709
709
* @param callable $callback
710
- * @return $this
710
+ * @param mixed $initial
711
+ * @return mixed
711
712
*/
712
- public function tap (callable $ callback )
713
+ public function reduce (callable $ callback, $ initial = null )
713
714
{
714
- $ callback ( clone $ this ) ;
715
+ $ result = $ initial ;
715
716
716
- return $ this ;
717
+ foreach ($ this as $ key => $ value ) {
718
+ $ result = $ callback ($ result , $ value , $ key );
719
+ }
720
+
721
+ return $ result ;
717
722
}
718
723
719
724
/**
@@ -733,6 +738,19 @@ public function reject($callback = true)
733
738
});
734
739
}
735
740
741
+ /**
742
+ * Pass the collection to the given callback and then return it.
743
+ *
744
+ * @param callable $callback
745
+ * @return $this
746
+ */
747
+ public function tap (callable $ callback )
748
+ {
749
+ $ callback (clone $ this );
750
+
751
+ return $ this ;
752
+ }
753
+
736
754
/**
737
755
* Return only unique items from the collection array.
738
756
*
You can’t perform that action at this time.
0 commit comments