package Mapx; use strict; use warnings; use Exporter qw( import ); our @EXPORT = qw( mapx DONE_MAP ); use Scalar::Util qw( reftype blessed ); use constant DONE_MAP => \&mapx; sub mapx(&@) { my $cb = shift; my @rv; for (@_) { my @x = $cb->(); last if @x == 1 && reftype($x[0]) && !blessed($x[0]) && $x[0] == + DONE_MAP; push @rv, @x; } return @rv; } 1;
use strict; use warnings; use 5.010; use Mapx; sub x { my $target = shift; mapx { return DONE_MAP if $_ == $target; $_ } @_; } say for x( 5, 1..9 );
In reply to Re: Short-circuiting a map list.
by ikegami
in thread Short-circuiting a map list.
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |