Skip to content

Commit ba2d03a

Browse files
committed
drafted some fixes for gather/take bitrot.
1 parent a0f87cf commit ba2d03a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

S04-control.pod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -765,22 +765,22 @@ C<take> is operating. These need not be identical contexts, since they
765765
may bind or coerce the resulting parcels differently:
766766

767767
my @y;
768-
@x = gather for 1..2 { # flat context for list of parcels
769-
my ($y) := take $_, $_ * 10; # item context promotes parcel to seq
768+
my @x = gather for 1..2 { # flat context for list of parcels
769+
my ($y) := \(take $_, $_ * 10); # binding forces item context
770770
push @y, $y;
771771
}
772-
# @x contains 4 Ints: 1,10,2,20 flattened by list assignment to @x
773-
# @y contains 2 Seqs: Seq(1,10),Seq(2,20) sliced by binding to positional $y
772+
# @x contains 4 Ints: 1,10,2,20 flattened by list assignment to @x
773+
# @y contains 2 Parcels: $(1,10),$(2,20) sliced by binding to positional $y
774774

775775
Likewise, we can just remember the gather's result parcel by binding and
776776
later coercing it:
777777

778-
my |$c := gather for 1..2 {
778+
my ($c) := \(gather for 1..2 {
779779
take $_, $_ * 10;
780-
}
780+
});
781781
# $c.flat produces 1,10,2,20 -- flatten fully into a list of Ints.
782-
# $c.lol produces Seq(1,10),Seq(2,20) -- list of Seqs, a 2-D list.
783-
# $c.item produces Seq((1,10),(2,20)) -- coerced to Seq of unresolved Parcels
782+
# $c.lol produces Lol.new($(1,10),$(2,20)) -- list of Parcels, a 2-D list.
783+
# $c.item produces ($(1,10),$(2,20)).list.item -- a list of Parcels, as an item.
784784

785785
Note that the C<take> itself is in sink context in this example because
786786
the C<for> loop is in the sink context provided inside the gather.

0 commit comments

Comments
 (0)