File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -156,22 +156,28 @@ a negated junction:
156
156
}
157
157
158
158
159
- = head1 Failures and Exceptions
159
+ = head1 Failures and exceptions
160
160
161
161
L < Failures|/type/Failure > are just values like any other, as far as Junctions
162
162
are concerned:
163
163
164
164
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]»
166
169
167
170
Above, we've used prefix C < + > operator on a L < Junction|/type/Junction > to coerce
168
171
the strings inside of it to L < Numeric|/type/Numeric > . Since the operator returns
169
172
a L < Failure|/type/Failure > when a L < Str|/type/Str > that doesn't
170
173
contain a number
171
174
gets coerced to C < Numeric > , one of the elements in the C < Junction > is a
172
175
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
175
181
value—just like as if this C < Failure > were on its own and not part of the
176
182
C < Junction > :
177
183
You can’t perform that action at this time.
0 commit comments