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