File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020const map = '\Pitchart\Phunktional\map ' ;
2121const reject = '\Pitchart\Phunktional\reject ' ;
2222const sort = '\Pitchart\Phunktional\sort ' ;
23+ const reverse = '\Pitchart\Phunktional\reverse ' ;
24+ const pad = '\Pitchart\Phunktional\pad ' ;
2325
2426/**
2527 * Runs a boolean function on each element and only puts those that pass into the output.
@@ -338,3 +340,34 @@ function partition(int $size)
338340 return \array_chunk ($ array , $ size );
339341 };
340342}
343+
344+ /**
345+ * Reverses a list
346+ *
347+ * @return \Closure
348+ *
349+ * @see \array_reverse()
350+ */
351+ function reverse ()
352+ {
353+ return function (array $ array ) {
354+ return \array_reverse ($ array );
355+ };
356+ }
357+
358+ /**
359+ * Pad array to the specified length with a value
360+ *
361+ * @param int $size
362+ * @param $value
363+ *
364+ * @return \Closure
365+ *
366+ * @see \array_pad()
367+ */
368+ function pad (int $ size , $ value )
369+ {
370+ return function (array $ array ) use ($ size , $ value ) {
371+ return \array_pad ($ array , $ size , $ value );
372+ };
373+ }
Original file line number Diff line number Diff line change @@ -220,5 +220,9 @@ public function arrayFunctionsBuildersProvider()
220220 yield from ['reject constant ' => [(p \filter)($ filtering )]];
221221 yield from ['sort ' => [p \sort (function (int $ a , int $ b ) { return $ a > $ b ? 1 : ($ b > $ a ? -1 : 0 ); })]];
222222 yield from ['sort constant ' => [(p \sort)(function (int $ a , int $ b ) { return $ a > $ b ? 1 : ($ b > $ a ? -1 : 0 ); })]];
223+ yield from ['reverse ' => [p \reverse ()]];
224+ yield from ['reverse constant ' => [(p \reverse)()]];
225+ yield from ['pad ' => [p \pad (10 , 0 )]];
226+ yield from ['pad constant ' => [(p \pad)(10 , 0 )]];
223227 }
224228}
You can’t perform that action at this time.
0 commit comments