more-docs
[gitmo/Moose-Autobox.git] / lib / Moose / Autobox / List.pm
CommitLineData
e6bb88b0 1
2package Moose::Autobox::List;
3use Moose::Role 'with', 'requires';
6cf5bcf2 4use autobox;
e6bb88b0 5
6our $VERSION = '0.01';
7
31d40d73 8with 'Moose::Autobox::Value';
e6bb88b0 9
5dc78481 10requires qw/
31d40d73 11 head
6cf5bcf2 12 tail
5dc78481 13 length
14 join
31d40d73 15 grep
16 map
17 sort
5dc78481 18 reverse
5dc78481 19/;
20
6cf5bcf2 21sub reduce {
22 my ($array, $func) = @_;
23 my $a = $array->values;
24 my $acc = $a->head;
25 $a->tail->map(sub { $acc = $func->($acc, $_) });
26 return $acc;
27}
28
29sub zip {
30 my ($array, $other) = @_;
31 ($array->length < $other->length
32 ? $other
33 : $array)
34 ->keys
35 ->map(sub {
31d40d73 36 [ $array->at($_), $other->at($_) ]
6cf5bcf2 37 });
38}
e6bb88b0 39
31d40d73 401;
41
42__END__
43
44=pod
45
46=head1 NAME
47
48Moose::Autobox::List - the List role
49
31d40d73 50=head1 DESCRIPTION
51
8937074a 52This is a role to describes a List interface. This is not
53meant to be any specific Perl type, but instead an interface
54that certain Perl types might implement. Currenly only
55L<Moose::Autobox::Array> implements this.
56
260cc81f 57=head1 METHODS
58
59=over 4
60
260cc81f 61=item B<reduce>
62
63=item B<zip>
64
65=back
66
5272f13f 67=over 4
68
69=item B<meta>
70
71=back
72
260cc81f 73=head1 REQUIRED METHODS
74
75=over 4
76
77=item B<head>
78
79=item B<tail>
80
81=item B<join>
82
83=item B<length>
84
85=item B<map>
86
87=item B<grep>
88
89=item B<reverse>
90
91=item B<sort>
92
93=back
94
31d40d73 95=head1 BUGS
96
97All complex software has bugs lurking in it, and this module is no
98exception. If you find a bug please either email me, or add the bug
99to cpan-RT.
100
101=head1 AUTHOR
102
103Stevan Little E<lt>stevan@iinteractive.comE<gt>
104
105=head1 COPYRIGHT AND LICENSE
106
107Copyright 2006 by Infinity Interactive, Inc.
108
109L<http://www.iinteractive.com>
110
111This library is free software; you can redistribute it and/or modify
112it under the same terms as Perl itself.
113
114=cut