Last week: Coin Changer
This week it did not work out for me, I did the kata only once in PHP and that was not enough to get any particular insights. I’ll have to repeat it again some time soon! But on to the next one:
Eighth Kata: Functions Pipeline
The task: build a function
pipe()that takes any number of callables as arguments and returns a new callable.
The returned callable passes any arguments to the first callable, then the result of that to the next callable, and so on, and will return the final result.
So the processing order is left to right.
Example:// first apply strtolower(), then apply ucwords second. $f = pipe('strtolower', 'ucwords'); $f('FOO BAR') === ucwords(strtolower('FOO BAR'));
Optional follow up exercise:
implement a function
compose(), which behaves just like
pipe()except that the processing order is right to left. Implement it differently from
pipe()(e.g. without reversing the input array) and without calling
Note: In PHP the callables could be function name strings (e.g.
"strtolower"), object callables (e.g.
[$instance, "doFoo"]), objects that implement
\Closureinstances (so anything that sattisfied the
In other languages just choose the appropriate things.