prep next release
[gitmo/Moose-Autobox.git] / lib / Moose / Autobox / List.pm
1
2 package Moose::Autobox::List;
3 use Moose::Role 'with', 'requires';
4 use Moose::Autobox;
5
6 our $VERSION = '0.10';
7
8 with 'Moose::Autobox::Value';
9
10 requires 'head';
11 requires 'tail';
12 requires 'length'; 
13 requires 'join'; 
14 requires 'grep'; 
15 requires 'map'; 
16 requires 'sort';
17 requires 'reverse';
18
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->at($_), $other->at($_) ]
35             });
36 }
37
38 1;
39
40 __END__
41
42 =pod
43
44 =head1 NAME 
45
46 Moose::Autobox::List - the List role
47
48 =head1 DESCRIPTION
49
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
55 =head1 METHODS
56
57 =over 4
58
59 =item B<reduce>
60
61 =item B<zip>
62
63 =back
64
65 =over 4
66
67 =item B<meta>
68
69 =back
70
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
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-2008 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