Commit | Line | Data |
---|---|---|
e6bb88b0 | 1 | |
2 | package Moose::Autobox::List; | |
3 | use Moose::Role 'with', 'requires'; | |
6cf5bcf2 | 4 | use autobox; |
e6bb88b0 | 5 | |
6 | our $VERSION = '0.01'; | |
7 | ||
6cf5bcf2 | 8 | with 'Moose::Autobox::Indexed'; |
e6bb88b0 | 9 | |
5dc78481 | 10 | requires qw/ |
6cf5bcf2 | 11 | head |
12 | tail | |
5dc78481 | 13 | length |
14 | join | |
15 | grep map sort | |
16 | reverse | |
5dc78481 | 17 | /; |
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 { | |
34 | [ $array->[$_], $other->[$_] ] | |
35 | }); | |
36 | } | |
e6bb88b0 | 37 | |
38 | 1; |