the attribute was B<not> empty (no elements). Now it returns true if the
attribute B<is> empty. It was also renamed to C<is_empty>, to reflect this.
-=item C<find> was renamed to C<first>, and C<first> was renamed to C<head>
+=item C<find> was renamed to C<first>, and C<first> and C<last> were removed
L<List::Util> refers to the functionality that we used to provide under C<find>
as L<first|List::Util/first>, so that will likely be more familiar (and will
-fit in better if we decide to add more List::Util functions). C<head> is an
-obvious choice to replace what used to be called C<first>.
+fit in better if we decide to add more List::Util functions). C<first> and
+C<last> were removed, since their functionality is easily duplicated with
+curries of C<get>.
=item Helpers that take a coderef of one argument now use C<$_>
};
}
-sub head : method {
- my ( $attr, $reader, $writer ) = @_;
- return sub {
- $reader->( $_[0] )->[0];
- };
-}
-
-sub tail : method {
- my ( $attr, $reader, $writer ) = @_;
- return sub {
- my $arr = $reader->( $_[0] );
- return @{ $arr }[1..$#{ $arr }];
- };
-}
-
-sub last : method {
- my ( $attr, $reader, $writer ) = @_;
- return sub {
- $reader->( $_[0] )->[-1];
- };
-}
-
sub push : method {
my ( $attr, $reader, $writer ) = @_;
map_options => 'map',
filter_options => 'grep',
find_option => 'first',
- first_option => 'head',
- all_but_first_option => 'tail',
- last_option => 'last',
get_option => 'get',
join_options => 'join',
count_options => 'count',
Empties the entire array, like C<@array = ()>.
-=item B<head>
-
-Returns the first element of the array.
-
- my $first = $stuff->first_option;
- print "$first\n"; # prints "foo"
-
-=item B<tail>
-
-Returns all elements of the array after the first.
-
- my @tail = $stuff->all_but_first_option;
- print join(', ', @tail), "\n"; # prints "bar, baz, boo"
-
-=item B<last>
-
-Returns the last element of the array.
-
- my $last = $stuff->last_option;
- print "$last\n"; # prints "boo"
-
=item B<accessor>
This method provides a get/set accessor for the array, based on array indexes.
use strict;
use warnings;
-use Test::More tests => 34;
+use Test::More tests => 31;
use Test::Exception;
use Test::Moose 'does_ok';
'options' => 'elements',
'join_options' => 'join',
'get_option_at' => 'get',
- 'get_first_option' => 'head',
- 'all_but_first_option' => 'tail',
- 'get_last_option' => 'last',
'sorted_options' => 'sort',
'less_than_five' => [ grep => [ $less = sub { $_ < 5 } ] ],
'up_by_one' => [ map => [ $up = sub { $_ + 1 } ] ],
ok( !$stuff->has_no_options, '... we have options' );
is( $stuff->num_options, 10, '... got 2 options' );
cmp_ok( $stuff->get_option_at(0), '==', 1, '... get option 0' );
-cmp_ok( $stuff->get_first_option, '==', 1, '... get head' );
-is_deeply( [ $stuff->all_but_first_option ], [ 2 .. 10 ], '... get tail' );
-cmp_ok( $stuff->get_last_option, '==', 10, '... get last' );
is_deeply(
[ $stuff->filter_options( sub { $_ % 2 == 0 } ) ],
'options' => 'elements',
'join_options' => 'join',
'get_option_at' => 'get',
- 'get_first_option' => 'head',
- 'all_but_first_option' => 'tail',
- 'get_last_option' => 'last',
'sorted_options' => 'sort',
'less_than_five' => [ grep => [$less] ],
'up_by_one' => [ map => [$up] ],