Commit | Line | Data |
e6bb88b0 |
1 | |
2 | package Moose::Autobox::List; |
3 | use Moose::Role 'with', 'requires'; |
7dad2765 |
4 | use Moose::Autobox; |
e6bb88b0 |
5 | |
7dad2765 |
6 | our $VERSION = '0.02'; |
e6bb88b0 |
7 | |
31d40d73 |
8 | with 'Moose::Autobox::Value'; |
e6bb88b0 |
9 | |
680d0745 |
10 | requires 'head'; |
11 | requires 'tail'; |
12 | requires 'length'; |
13 | requires 'join'; |
14 | requires 'grep'; |
15 | requires 'map'; |
16 | requires 'sort'; |
17 | requires 'reverse'; |
5dc78481 |
18 | |
6cf5bcf2 |
19 | sub 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 | |
27 | sub 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 |
38 | 1; |
39 | |
40 | __END__ |
41 | |
42 | =pod |
43 | |
44 | =head1 NAME |
45 | |
46 | Moose::Autobox::List - the List role |
47 | |
31d40d73 |
48 | =head1 DESCRIPTION |
49 | |
8937074a |
50 | This is a role to describes a List interface. This is not |
51 | meant to be any specific Perl type, but instead an interface |
52 | that certain Perl types might implement. Currenly only |
53 | L<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 | |
95 | All complex software has bugs lurking in it, and this module is no |
96 | exception. If you find a bug please either email me, or add the bug |
97 | to cpan-RT. |
98 | |
99 | =head1 AUTHOR |
100 | |
101 | Stevan Little E<lt>stevan@iinteractive.comE<gt> |
102 | |
103 | =head1 COPYRIGHT AND LICENSE |
104 | |
105 | Copyright 2006 by Infinity Interactive, Inc. |
106 | |
107 | L<http://www.iinteractive.com> |
108 | |
109 | This library is free software; you can redistribute it and/or modify |
110 | it under the same terms as Perl itself. |
111 | |
112 | =cut |