1Moose::Autobox::Code(3)User Contributed Perl DocumentatioMnoose::Autobox::Code(3)
2
3
4
6 Moose::Autobox::Code - the Code role
7
9 use Moose::Autobox;
10
11 my $adder = sub { $_[0] + $_[1] };
12 my $add_2 = $adder->curry(2);
13
14 $add_2->(2); # returns 4
15
16 # create a recursive subroutine
17 # using the Y combinator
18 *factorial = sub {
19 my $f = shift;
20 sub {
21 my $n = shift;
22 return 1 if $n < 2;
23 return $n * $f->($n - 1);
24 }
25 }->y;
26
27 factorial(10) # returns 3628800
28
30 This is a role to describe operations on the Code type.
31
33 curry (@values)
34 rcurry (@values)
35 conjoin (\&sub)
36 disjoin (\&sub)
37 compose (@subs)
38 This will take a list of @subs and compose them all into a single
39 subroutine where the output of one sub will be the input of
40 another.
41
42 y This implements the Y combinator.
43
44 u This implements the U combinator.
45
46 meta
47
49 <http://en.wikipedia.org/wiki/Fixed_point_combinator>
50 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/20469
51 <http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/20469>
52
54 All complex software has bugs lurking in it, and this module is no
55 exception. If you find a bug please either email me, or add the bug to
56 cpan-RT.
57
59 Stevan Little <stevan@iinteractive.com>
60
62 Copyright 2006-2008 by Infinity Interactive, Inc.
63
64 <http://www.iinteractive.com>
65
66 This library is free software; you can redistribute it and/or modify it
67 under the same terms as Perl itself.
68
69
70
71perl v5.12.2 2010-04-23 Moose::Autobox::Code(3)