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