Skip to content

Commit 4acd2ad

Browse files
committed
update andthen example for clarity
Closes #4398
1 parent 633c243 commit 4acd2ad

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

doc/Language/operators.rakudoc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,20 +3432,11 @@ right-hand side won't get executed, unless left-hand side is defined (tip:
34323432
L<C<Failure>|/type/Failure>s are never defined, so you can handle them with
34333433
this operator).
34343434

3435-
sub load-data {
3436-
rand > .5 or return; # simulated load data failure; return Nil
3437-
(rand > .3 ?? 'error' !! 'good data') xx 10 # our loaded data
3435+
"does this match?" ~~ /this/ andthen {
3436+
$_.say # Using explicit $_ here only for clarity, .say works too
34383437
}
3439-
load-data.first: /good/ andthen say "$_ is good";
3440-
# OUTPUT: «(good data is good)␤»
3441-
3442-
load-data() andthen .return; # return loaded data, if it's defined
3443-
die "Failed to load data!!";
3444-
3445-
The above example will print C<good data is good> only if the subroutine
3446-
returned any items that match C</good/> and will die unless loading data
3447-
returned a defined value. The aliasing behavior lets us pipe the values across
3448-
the operator.
3438+
"does that match?" ~~ /this/ andthen say 'oops';
3439+
# OUTPUT: «this␤»
34493440

34503441
The C<andthen> operator is a close relative of the L«C<with> statement
34513442
modifier|/language/control#with_orwith_without», and some compilers

0 commit comments

Comments
 (0)