File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
src/Illuminate/Collections/Traits Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -721,6 +721,22 @@ public function pipeInto($class)
721
721
return new $ class ($ this );
722
722
}
723
723
724
+ /**
725
+ * Pass the collection through a series of callable pipes and return the result.
726
+ *
727
+ * @param array<callable> $pipes
728
+ * @return mixed
729
+ */
730
+ public function pipeThrough ($ pipes )
731
+ {
732
+ return static ::make ($ pipes )->reduce (
733
+ function ($ carry , $ pipe ) {
734
+ return $ pipe ($ carry );
735
+ },
736
+ $ this ,
737
+ );
738
+ }
739
+
724
740
/**
725
741
* Pass the collection to the given callback and then return it.
726
742
*
Original file line number Diff line number Diff line change @@ -4007,6 +4007,25 @@ public function testPipeInto($collection)
4007
4007
$ this ->assertSame ($ data , $ instance ->value );
4008
4008
}
4009
4009
4010
+ /**
4011
+ * @dataProvider collectionClassProvider
4012
+ */
4013
+ public function testPipeThrough ($ collection )
4014
+ {
4015
+ $ data = new $ collection ([1 , 2 , 3 ]);
4016
+
4017
+ $ result = $ data ->pipeThrough ([
4018
+ function ($ data ) {
4019
+ return $ data ->merge ([4 , 5 ]);
4020
+ },
4021
+ function ($ data ) {
4022
+ return $ data ->sum ();
4023
+ },
4024
+ ]);
4025
+
4026
+ $ this ->assertEquals (15 , $ result );
4027
+ }
4028
+
4010
4029
/**
4011
4030
* @dataProvider collectionClassProvider
4012
4031
*/
You can’t perform that action at this time.
0 commit comments