Data::Perl::Role::Collection::Array(3pm) | User Contributed Perl Documentation | Data::Perl::Role::Collection::Array(3pm) |
Data::Perl::Role::Collection::Array - Wrapping class for Perl's built in array structure.
version 0.002009
use Data::Perl qw/array/; my $array = array(1, 2, 3); $array->push(5); $array->grep(sub { $_ > 2 })->map(sub { $_ ** 2 })->elements; # (3, 5);
This class provides a wrapper and methods for interacting with an array. All methods that return a list do so via a Data::Perl::Collection::Array object.
$stuff = Data::Perl::Collection::Array->new(qw/foo bar baz boo/); print $stuff->count; # prints 4
This method does not accept any arguments.
$stuff->is_empty ? die "No options!\n" : print "Good boy.\n";
This method does not accept any arguments.
my @options = $stuff->elements; print "@options\n"; # prints "foo bar baz boo"
This method does not accept any arguments.
my $option = $stuff->get(1); print "$option\n"; # prints "bar"
If the specified element does not exist, this will return "undef".
This method accepts just one argument.
This method does not accept any arguments.
This method accepts any number of arguments.
This method does not accept any arguments.
This method accepts any number of arguments.
This method requires at least one argument.
my $found = $stuff->find_option( sub {/^b/} ); print "$found\n"; # prints "bar"
This method requires a single argument.
This method requires a single argument.
my @found = $stuff->grep( sub {/^b/} ); print "@found\n"; # prints "bar baz boo"
This method requires a single argument.
my @mod_options = $stuff->map( sub { $_ . "-tag" } ); print "@mod_options\n"; # prints "foo-tag bar-tag baz-tag boo-tag"
This method requires a single argument.
my $found = $stuff->reduce( sub { $_[0] . $_[1] } ); print "$found\n"; # prints "foobarbazboo"
This method requires a single argument.
You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b in this subroutine, you will need to use $_[0] and $_[1]. The returned list is provided as a Collection::Array object.
# ascending ASCIIbetical my @sorted = $stuff->sort(); # Descending alphabetical order my @sorted_options = $stuff->sort( sub { lc $_[1] cmp lc $_[0] } ); print "@sorted_options\n"; # prints "foo boo baz bar"
This method accepts a single argument.
You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. The returned list is provided as a Collection::Array object.
This method accepts a single argument.
This method does not accept any arguments.
This method does not accept any arguments.
This method does not accept any arguments.
my $joined = $stuff->join(':'); print "$joined\n"; # prints "foo:bar:baz:boo"
This method requires a single argument.
$joined = $stuff->print(*STDERR, ';'); # prints foo;bar;baz to STDERR
This method returns the value at $index after the set.
This method requires two arguments.
This method returns the deleted value, either as an array or scalar as dependent on splice context semantics. Note that if no value exists, it will
return "undef".
This method requires one argument.
This method returns the new value at $index, either as an array or scalar as dependent on splice context semantics.
This method requires two arguments.
This method does not define a return value.
This method does not accept any arguments.
When called as a setter, this method returns the new value at $index.
This method accepts one or two arguments.
This method accepts one or two arguments.
Matthew Phillips <mattp@cpan.org>
This software is copyright (c) 2014 by Matthew Phillips <mattp@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2018-10-29 | perl v5.26.2 |