NAME
Ekorn::Pipeline::Stages::Batch - stages gathering values: batch and collect
SYNOPSIS
use Ekorn::Pipeline;
use Ekorn::Pipeline::Stages::Batch; # batch and collect
# Values 500 at a time
my $batches = Ekorn::Pipeline->new(batch(500))->iterator($source);
while (my($batch) = $batches->()) { ... }
# Every value, as one result
my($all) = Ekorn::Pipeline->new(collect)->(@values);
# One value made from every value
my($names) = Ekorn::Pipeline->new(
sub { $_->{name} },
collect { join ', ', @_ },
)->(@users);
DESCRIPTION
Stages that gather values, and pass them on together. Both are made with Ekorn::Pipeline::Gather, so what they hold starts afresh on each run, and both pass on what they still hold once the values run out. Each function returns a stage, and checks what it's given when it's called, not on each value.
FUNCTIONS
Both are exported by default, and with :all.
batch
batch($size)
Passes values on in batches of $size, each an array reference. Once the values run out, the last batch, which may be shorter, goes on. There's no empty batch: without values, there's no batch at all.
collect
collect
collect { ... }
Holds every value, and once they run out, passes on an array reference of them, or, given a block, what the block returns, called once with the values as its arguments. What it returns goes through the stages after it, as what a stage returns does: nothing, one value, or several. It's called even without values, so collect still gives a result: an empty array, or what the block makes of none.
collect holds every value until the end, so the whole result is in memory at once; batch holds no more than one batch.
DIAGNOSTICS
- Expected a batch size of 1 or more
-
batchwas given something other than a whole number above 0. - Expected a code reference
-
collectwas given something other than a block or code reference.
SEE ALSO
Ekorn::Pipeline, Ekorn::Pipeline::Gather
AUTHOR
Iain Campbell <cpanic@cpan.org>
LICENSE
Copyright (c) 2024-2026 by Iain Campbell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.