in reply to Re^4: Specializing Functions with Currying
in thread Specializing Functions with Currying
Why recurse when you can iterate instead? :)
use List::Util qw(reduce); sub compose { reduce { sub { $b->($a->(@_)) } } @_; }
Of course, that doesn't actually work because Perl's reduce uses global variables ($a,$b). But, we can roll our own:
sub compose { my $c = shift; foreach my $s (@_) { my $o = $c; $c = sub { $s->($o->(@_)) } } $c }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Specializing Functions with Currying
by stvn (Monsignor) on Aug 06, 2004 at 21:56 UTC | |
by jryan (Vicar) on Aug 06, 2004 at 22:21 UTC | |
by tilly (Archbishop) on Aug 06, 2004 at 22:29 UTC | |
by hardburn (Abbot) on Aug 09, 2004 at 13:08 UTC | |
by tilly (Archbishop) on Aug 09, 2004 at 18:44 UTC | |
by Aristotle (Chancellor) on Aug 09, 2004 at 13:19 UTC | |
by adrianh (Chancellor) on Aug 09, 2004 at 13:28 UTC | |
by BrowserUk (Patriarch) on Aug 09, 2004 at 13:50 UTC | |
| |
by stvn (Monsignor) on Aug 06, 2004 at 23:04 UTC | |
by jryan (Vicar) on Aug 06, 2004 at 23:20 UTC | |
by tilly (Archbishop) on Aug 06, 2004 at 23:39 UTC | |
| |
by stvn (Monsignor) on Aug 06, 2004 at 23:37 UTC | |
| |
by ihb (Deacon) on Aug 08, 2004 at 00:19 UTC |
In Section
Meditations