Skip to content

Commit 5ac4ae0

Browse files
committed
Elaborate on Supply.(flat|do|map|grep|uniq|squish)
1 parent de83968 commit 5ac4ae0

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

S17-concurrency.pod

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,20 +547,56 @@ process, working synchronously, C<grep> on a Supply has values I<pushed>
547547
through it, and pushes those that match the filter onwards to anything that
548548
taps it.
549549

550-
The following methods are available on a C<Supply>:
550+
The following methods are available on an instantiated C<Supply> (C<$s> in
551+
these examples):
551552

552553
=over
553554

554555
=item flat
555556

557+
my $f = $s.flat;
558+
559+
Produces a C<Supply> in which all values of the original supply are flattened.
560+
561+
=item do
562+
563+
my $seen;
564+
my $d = $s.do( {$seen++} );
565+
566+
Produces a C<Supply> that is identical to the original supply, but will execute
567+
the given code for its side-effects.
568+
556569
=item grep
557570

571+
my $g = $s.grep( * > 5 );
572+
573+
Produces a C<Supply> that only provides values that are greater than 5.
574+
558575
=item map
559576

577+
my $m = $s.map( * * 5 );
578+
579+
Produces a C<Supply> that provides its original's Supply values multiplied by 5.
580+
581+
my $m2 = $s.map( { $_ xx 2 } );
582+
583+
Produces a C<Supply> that provides its original's Supply values twice.
584+
560585
=item uniq
561586

587+
my $u = $s.uniq( :as( {$_} ), :with( &[===] ) );
588+
589+
Produces a C<Supply> that only provides unique values, as defined by the
590+
optional C<as> and C<with> named parameters (same as L<List.uniq>).
591+
562592
=item squish
563593

594+
my $q = $s.squish( :as( {$_} ), :with( &[===] ) );
595+
596+
Produces a C<Supply> that only provides sequentially different values, as
597+
defined by the optional C<as> and C<with> named parameters (same as
598+
L<List.squish>).
599+
564600
=back
565601

566602
There are some others that will only publish a result or results if C<done> is

0 commit comments

Comments
 (0)