Commit | Line | Data |
5f654d8e |
1 | package Moose::Autobox::Code; |
2 | use Moose::Role 'with'; |
252ab1a2 |
3 | use autobox; |
5f654d8e |
4 | |
5 | our $VERSION = '0.01'; |
6 | |
7 | with 'Moose::Autobox::Ref'; |
8 | |
9 | sub curry { |
10 | my ($f, @a) = @_; |
11 | return sub { $f->(@a, @_) } |
12 | } |
13 | |
14 | sub rcurry { |
15 | my ($f, @a) = @_; |
16 | return sub { $f->(@_, @a) } |
17 | } |
18 | |
19 | sub compose { |
20 | my ($f, $f2, @rest) = @_; |
21 | return $f if !$f2; |
22 | return (sub { $f2->($f->(@_)) })->compose(@rest); |
23 | } |
24 | |
25 | sub disjoin { |
26 | my ($f, $f2) = @_; |
27 | return sub { $f->(@_) || $f2->(@_) } |
28 | } |
29 | |
30 | sub conjoin { |
31 | my ($f, $f2) = @_; |
32 | return sub { $f->(@_) && $f2->(@_) } |
33 | } |
34 | |
31d40d73 |
35 | 1; |
36 | |
37 | __END__ |
38 | |
39 | =pod |
40 | |
41 | =head1 NAME |
42 | |
43 | Moose::Autobox::Code - the Code role |
44 | |
45 | =head1 SYNOPOSIS |
46 | |
47 | use Moose::Autobox; |
48 | use autobox; |
49 | |
50 | my $adder = sub { $_[0] + $_[1] }; |
51 | |
52 | $add_2 = $adder->curry(2); |
53 | |
54 | $add_2->(2); # returns 4 |
55 | |
56 | =head1 DESCRIPTION |
57 | |
8937074a |
58 | This is a role to describe operations on the Code type. |
59 | |
260cc81f |
60 | =head1 METHODS |
61 | |
62 | =over 4 |
63 | |
64 | =item B<meta> |
65 | |
66 | =item B<curry> |
67 | |
68 | =item B<rcurry> |
69 | |
70 | =item B<conjoin> |
71 | |
72 | =item B<disjoin> |
73 | |
74 | =item B<compose> |
75 | |
76 | =back |
77 | |
31d40d73 |
78 | =head1 BUGS |
79 | |
80 | All complex software has bugs lurking in it, and this module is no |
81 | exception. If you find a bug please either email me, or add the bug |
82 | to cpan-RT. |
83 | |
84 | =head1 AUTHOR |
85 | |
86 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
87 | |
88 | =head1 COPYRIGHT AND LICENSE |
89 | |
90 | Copyright 2006 by Infinity Interactive, Inc. |
91 | |
92 | L<http://www.iinteractive.com> |
93 | |
94 | This library is free software; you can redistribute it and/or modify |
95 | it under the same terms as Perl itself. |
96 | |
97 | =cut |