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 | |
7fc99864 |
35 | #sub dump { |
36 | #my ($self) = @_; |
37 | #require Data::Dump::Streamer; |
38 | #return Data::Dump::Streamer::Dump($self)->Out(); |
39 | #} |
40 | |
31d40d73 |
41 | 1; |
42 | |
43 | __END__ |
44 | |
45 | =pod |
46 | |
47 | =head1 NAME |
48 | |
49 | Moose::Autobox::Code - the Code role |
50 | |
51 | =head1 SYNOPOSIS |
52 | |
53 | use Moose::Autobox; |
54 | use autobox; |
55 | |
56 | my $adder = sub { $_[0] + $_[1] }; |
5272f13f |
57 | my $add_2 = $adder->curry(2); |
31d40d73 |
58 | |
59 | $add_2->(2); # returns 4 |
60 | |
61 | =head1 DESCRIPTION |
62 | |
8937074a |
63 | This is a role to describe operations on the Code type. |
64 | |
260cc81f |
65 | =head1 METHODS |
66 | |
67 | =over 4 |
68 | |
5272f13f |
69 | =item B<curry (@values)> |
70 | |
71 | =item B<rcurry (@values)> |
72 | |
73 | =item B<conjoin (\&sub)> |
260cc81f |
74 | |
5272f13f |
75 | =item B<disjoin (\&sub)> |
260cc81f |
76 | |
5272f13f |
77 | =item B<compose (@subs)> |
260cc81f |
78 | |
5272f13f |
79 | This will take a list of C<@subs> and compose them all into a single |
80 | subroutine where the output of one sub will be the input of another. |
260cc81f |
81 | |
5272f13f |
82 | =back |
83 | |
84 | =over 4 |
260cc81f |
85 | |
5272f13f |
86 | =item B<meta> |
260cc81f |
87 | |
88 | =back |
89 | |
31d40d73 |
90 | =head1 BUGS |
91 | |
92 | All complex software has bugs lurking in it, and this module is no |
93 | exception. If you find a bug please either email me, or add the bug |
94 | to cpan-RT. |
95 | |
96 | =head1 AUTHOR |
97 | |
98 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
99 | |
100 | =head1 COPYRIGHT AND LICENSE |
101 | |
102 | Copyright 2006 by Infinity Interactive, Inc. |
103 | |
104 | L<http://www.iinteractive.com> |
105 | |
106 | This library is free software; you can redistribute it and/or modify |
107 | it under the same terms as Perl itself. |
108 | |
f6e003cc |
109 | =cut |