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