Skip to content

Commit 64121a9

Browse files
committed
Make eager examples showcase "eager" eval more
The existing examples did not really showcase the "eagerness" of the evaluation.
1 parent dcb567d commit 64121a9

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

doc/Type/Any.pod6

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,12 @@ Defined as:
244244
245245
method eager(--> Seq:D) is nodal
246246
247-
Interprets the invocant as a list, evaluates it eagerly, and returns that
248-
list.
247+
Interprets the invocant as a C<List>, evaluates it eagerly, and returns that
248+
C<List>.
249249
250-
say (1..10).eager; # OUTPUT: «(1 2 3 4 5 6 7 8 9 10)␤»
250+
my $range = 1..5;
251+
say $range; # OUTPUT: «1..5␤»
252+
say $range.eager; # OUTPUT: «(1 2 3 4 5)␤»
251253
252254
=head2 method elems
253255

doc/Type/List.pod6

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,12 @@ Defined as:
646646
multi method eager(List:D: --> List:D)
647647
multi sub eager(*@elems --> List:D)
648648
649-
Evaluates all elements in the list eagerly, and returns them as a list.
649+
Evaluates all elements in the C<List> eagerly, and returns them as a C<List>.
650650
651-
say (1,2,3,4,5).eager; # OUTPUT: «(1 2 3 4 5)␤»
651+
my \ll = (lazy 1..5).cache;
652+
653+
say ll[]; # OUTPUT: «(...)␤»
654+
say ll.eager # OUTPUT: «(1 2 3 4 5)␤»
652655
653656
=head2 routine reverse
654657

doc/Type/Seq.pod6

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ sequence, and marks it as consumed.
8383
If called on an already consumed sequence, throws an error of type
8484
L<X::Seq::Consumed>.
8585
86+
my $s = lazy 1..5;
87+
88+
say $s.is-lazy; # OUTPUT: «True␤»
89+
say $s.eager; # OUTPUT: «(1 2 3 4 5)␤»
90+
91+
say $s.eager;
92+
CATCH {
93+
when X::Seq::Consumed {
94+
say 'Throws exception if already consumed';
95+
}
96+
}
97+
# OUTPUT: «Throws exception if already consumed␤»
98+
8699
87100
=head2 method from-loop
88101

0 commit comments

Comments
 (0)