Skip to content

Commit 5587b5d

Browse files
committed
Changes the example
I couldn't find a nice way to make it work with grep, so I've changed the example and the wording. Closes #3030
1 parent e68c068 commit 5587b5d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

doc/Type/Junction.pod6

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,28 @@ a negated junction:
156156
}
157157
158158
159-
=head1 Failures and Exceptions
159+
=head1 Failures and exceptions
160160
161161
L<Failures|/type/Failure> are just values like any other, as far as Junctions
162162
are concerned:
163163
164164
my $j = +any "not a number", "42", "2.1";
165-
(gather $j».take).grep(Numeric).say; # OUTPUT: «(42 2.1)␤»
165+
my @list = gather for $j -> $e {
166+
take $e if $e.defined;
167+
}
168+
@list.say; # OUTPUT: «[42 2.1]␤»
166169
167170
Above, we've used prefix C<+> operator on a L<Junction|/type/Junction> to coerce
168171
the strings inside of it to L<Numeric|/type/Numeric>. Since the operator returns
169172
a L<Failure|/type/Failure> when a L<Str|/type/Str> that doesn't
170173
contain a number
171174
gets coerced to C<Numeric>, one of the elements in the C<Junction> is a
172175
C<Failure>. Failures do not turn into exceptions until they are used or sunk,
173-
and we can L«C<.grep>|/routine/grep»
174-
it out. The exception I<will> be thrown, if you try to use the C<Failure> as a
176+
but we can check for definedness to avoid that. That is what we do in the
177+
loop that runs over the elements of the junction, adding them to a list only
178+
if they are defined.
179+
180+
The exception I<will> be thrown, if you try to use the C<Failure> as a
175181
value—just like as if this C<Failure> were on its own and not part of the
176182
C<Junction>:
177183

0 commit comments

Comments
 (0)