in reply to Re: Functional Composition
in thread Functional Composition
You're right of course, but I chose perl builtins to keep the example short. If you consider that each of those 'fn's could be arbitrarily complex and require braces around their arguments that would become
perl -E"say(join('-', split('', reverse(ucfirst('hello')))))"
Plus I have to admit I kind of screwed up, "functional composition" really means "take two functions and produce a third", like
compose(sub{ ucfirst $[0] }, sub { $_[0] . "\n" });
would return a function that would ucfirst its arg and append a newline, whereas my code invokes the functions directly. Still, it looks pretty.
perl -e 'print sub { "Hello @{[shift->()]}!\n" }->(sub{"World"})'
|
---|