-
-
Save zoffixznet/82ef0cfb76ef1cbb6717555fab557427 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub infix:<orelse>(+a) { | |
my $ai := a.iterator; | |
my Mu $current := $ai.pull-one; | |
return Nil if $current =:= IterationEnd; | |
nqp::until( | |
(($_ := $ai.pull-one) =:= IterationEnd), | |
nqp::stmts( | |
nqp::if( | |
$current.defined, | |
nqp::stmts( | |
nqp::if( $current.WHAT === Code, $current := $current() ), | |
return $current, | |
), | |
), | |
($current := $_ ~~ Callable | |
?? (.count ?? $_($current) !! $_()) | |
!! $_ | |
), | |
), | |
:nohandler, # do not handle control stuff in thunks | |
); | |
$current.WHAT === Code ?? $current() !! $current | |
} | |
# cpan@perlbuild2~/CPANPRC/rakudo (nom)$ ./perl6 -e 'note (Int andthen "foo" orelse Int);' | |
# -> ;; $_ is raw { #`(Block|70927672) ... } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment