1 package Moose::Autobox::Code;
2 use Moose::Role 'with';
7 with 'Moose::Autobox::Ref';
11 return sub { $f->(@a, @_) }
16 return sub { $f->(@_, @a) }
20 my ($f, $f2, @rest) = @_;
22 return (sub { $f2->($f->(@_)) })->compose(@rest);
27 return sub { $f->(@_) || $f2->(@_) }
32 return sub { $f->(@_) && $f2->(@_) }
42 (sub { my $h = shift; sub { $f->(($h->u())->())->(@_) } }->u())->();
47 #require Data::Dump::Streamer;
48 #return Data::Dump::Streamer::Dump($self)->Out();
59 Moose::Autobox::Code - the Code role
65 my $adder = sub { $_[0] + $_[1] };
66 my $add_2 = $adder->curry(2);
68 $add_2->(2); # returns 4
70 # create a recursive subroutine
71 # using the Y combinator
77 return $n * $f->($n - 1);
81 factorial(10) # returns 3628800
86 This is a role to describe operations on the Code type.
92 =item B<curry (@values)>
94 =item B<rcurry (@values)>
96 =item B<conjoin (\&sub)>
98 =item B<disjoin (\&sub)>
100 =item B<compose (@subs)>
102 This will take a list of C<@subs> and compose them all into a single
103 subroutine where the output of one sub will be the input of another.
107 This implements the Y combinator.
111 This implements the U combinator.
125 =item L<http://en.wikipedia.org/wiki/Fixed_point_combinator>
131 All complex software has bugs lurking in it, and this module is no
132 exception. If you find a bug please either email me, or add the bug
137 Stevan Little E<lt>stevan@iinteractive.comE<gt>
139 =head1 COPYRIGHT AND LICENSE
141 Copyright 2006 by Infinity Interactive, Inc.
143 L<http://www.iinteractive.com>
145 This library is free software; you can redistribute it and/or modify
146 it under the same terms as Perl itself.