NAME

STIX::Common::List - Collection utility

SYNOPSIS

use STIX::Common::List;
my $collection = STIX::Common::List->new( qw[foo bar baz] );

DESCRIPTION

STIX::Common::List is a collection utility.

METHODS

STIX::Common::List->new( ARRAY )

Create a new collection.

my $c = STIX::Common::List->new( [foo bar baz] );
$c->add

Alias for "push".

$c->each

Evaluate callback for each element in collection.

foreach my $item ($c->each) {
    [...]
}

my $collection = $c->each(sub {...});

$c->each(sub {
    my ($value, $idx) = @_;
    [...]
});
$c->clear

Reset the collection.

$c->first

Get the first element of collection.

$c->get

Get item from N index position.

my $item = $c->get(5);
$c->grep

Filter items.

my $filtered = $c->grep(sub { $_ eq 'foo' });
$c->push

Add a new item in collection.

$c->push('foo');
$c->push(sub {...});
$c->join

Join elements in collection.

$c->join(', ');
$c->last

Get the last element of collection.

$c->map

Evaluate the callback and create a new collection.

STIX::Common::List->new(1,2,3)->map(sub { $_ * 2 });
$c->pop

Remove and return the last element of collection.

my $item = $c->pop;
$c->push

Add one or more elements in collection.

$c->push('foo', 'bar', 'baz');
$c->set

Set item value in N index position.

$c->set(5, 'foo');
$c->shift

Take the first element from the collection-

my $item = $c->shift;
$c->size

Number of item elements.

$c->unshift

Add one or more elements at the beginning of the collection.

$c->unshift('baz');
$c->to_array

Return the collection ARRAY.

$c->TO_JSON

Convert the collenction in JSON.

SUPPORT

Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at https://github.com/giterlizzi/perl-STIX/issues. You will be notified automatically of any progress on your issue.

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

https://github.com/giterlizzi/perl-STIX

git clone https://github.com/giterlizzi/perl-STIX.git

AUTHOR

  • Giuseppe Di Terlizzi <gdt@cpan.org>

LICENSE AND COPYRIGHT

This software is copyright (c) 2024 by Giuseppe Di Terlizzi.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.