NAME

Mojo::Collection::XS - Fast XS-based subclass of Mojo::Collection

SYNOPSIS

use Mojo::Collection::XS;

my $c = Mojo::Collection::XS->new(qw/foo bar baz/);

# Without parameters (uses $_)
$c->while(sub {
  say $_;
});

# With parameters
$c->while(sub ($e, $num) {
  say "$num: $e";
});

# Fast variants
$c->while_fast(sub ($e, $num) { ... });
$c->while_pure_fast(sub ($e, $num) { ... });
my $mapped = $c->map_fast(sub ($e, $num) { uc $e });
my $mapped_pure = $c->map_pure_fast(sub ($e, $num) { $e });
my $filtered = $c->grep_fast(sub ($e, $num) { $e =~ /foo/ });
$c->each_fast(sub ($e, $num) { ... });

DESCRIPTION

Mojo::Collection::XS is a subclass of Mojo::Collection with hot paths implemented in XS for better performance on large lists.

Callbacks must be code references; method-name strings are not supported.

METHODS

This class inherits all methods from Mojo::Collection and adds the following XS-backed helpers:

while_fast

$collection = $collection->while_fast(sub ($e, $num) {...});

Iterate over all elements, passing the element as $e and its 1-based index as $num. $_ is set to the current element (alias). Returns the same collection.

while_pure_fast

$collection = $collection->while_pure_fast(sub ($e, $num) {...});

Iterate over all elements without touching $_, passing only the element and its 1-based index. Returns the same collection.

map_fast

my $new = $collection->map_fast(sub ($e, $num) { ... });

Call the callback for each element and collect its list return into a new collection of the same class. $num is 1-based and $_ is set to the current element (alias).

map_pure_fast

my $new = $collection->map_pure_fast(sub ($e, $num) { ... });

Scalar-returning variant of map_fast. The callback is invoked in scalar context and each return value is collected into a new collection of the same class. $_ is not set.

grep_fast

my $new = $collection->grep_fast(sub ($e, $num) { ... });

Call the callback for each element and include the original element in the resulting collection when the callback returns a true value. $num is 1-based and $_ is set to the current element (alias).

each_fast

$collection = $collection->each_fast(sub ($e, $num) {...});

Iterate over all elements, passing the element and its 1-based index to the callback. $_ is set to the current element (alias). Returns the same collection.