NAME
Ekorn::Pipeline::Stages::Flow - stages taking or dropping values: take, drop, take_while and drop_while
SYNOPSIS
use Ekorn::Pipeline;
use Ekorn::Pipeline::Stages::Flow; # take and drop
# The third page of ten
my @page = Ekorn::Pipeline->new(drop(20), take(10))->(@names);
use Ekorn::Pipeline::Stages::Flow qw(:DEFAULT take_while drop_while);
# A mail's headers: its lines up to the first blank one
my $headers = Ekorn::Pipeline->new(take_while { m( \S )x })
->iterator(sub { scalar(<$fh>) // () });
DESCRIPTION
Stages that decide which values go on, by their place or by a test, whatever the values are. Each function returns a stage, and checks what it's given when it's called, not on each value. Those that keep state, take, drop and drop_while, are made with Ekorn::Pipeline::Gather, so they start afresh on each run: each call of a pipeline with values, and each iterator made from it.
take and take_while end the pipeline with Ekorn::Pipeline::Stop once they have passed on all they will, so an iterator calls its source no more.
FUNCTIONS
take and drop are exported by default; take_while and drop_while on request, or all four with :all. To have the defaults and one more, name :DEFAULT too:
use Ekorn::Pipeline::Stages::Flow qw(:DEFAULT take_while);
take
take($count)
Passes on the first $count values, then stops the pipeline. With fewer values, passes them all on. take(0) passes on none, but still sees the first value, as a stage isn't called until there is one.
drop
drop($count)
Drops the first $count values, and passes on the rest. With take, it gives a page:
drop(20), take(10) # the 21st to the 30th
take_while
take_while { ... }
Passes on values while the block is true of them, given each in $_ and as its argument, then stops the pipeline at the first it's false of, which isn't passed on.
drop_while
drop_while { ... }
Drops values while the block is true of them, given each in $_ and as its argument, and passes on the rest, from the first it's false of. Once it's false, the block isn't called again on that run.
DIAGNOSTICS
- Expected a count of 0 or more
-
takeordropwas given something other than a whole number. - Expected a code reference
-
take_whileordrop_whilewas given something other than a block or code reference.
SEE ALSO
Ekorn::Pipeline, Ekorn::Pipeline::Gather, Ekorn::Pipeline::Stop
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.