use Kavorka qw(fun); use Scalar::Induce qw(induce void); fun repeat(\$val!, \$times!) { induce { \$_-- ? \$val : void undef \$_ } \$times; } repeat('foo', 5); # ('foo', 'foo', 'foo', 'foo', 'foo') repeat({bar => 42}, 3); # 0 HASH(0x138be78) # bar => 42 # 1 HASH(0x138be78) # -> REUSED_ADDRESS # 2 HASH(0x138be78) # -> REUSED_ADDRESS fun range(:\$from = 1, :\$to!, :\$step = 1) { induce { my \$curr = \$_; undef \$_ if (\$_ += \$step) > \$to; return \$curr; } \$from; } range(step => 1.1, from => 4, to => 17); # (4, 5.1, 6.2, 7.3, 8.4, 9.5, 10.6, 11.7, 12.8, 13.9, 15, 16.1) range(to => 7); # (1, 2, 3, 4, 5, 6, 7) fun partition(\$n!, @l!) { induce { my @part = splice @\$_, 0, \$n; undef \$_ unless @\$_; return \@part; } \@l } partition(3, qw(Aragorn Boromir Frodo Gandalf Gimli Legolas Merry Pippin Sam)); # ( # ['Aragorn', 'Boromir', 'Frodo'], # ['Gandalf', 'Gimli', 'Legolas'], # ['Merry', 'Pippin', 'Sam'] # ) fun factor(\$n!) { induce { for my \$i (2..\$_/2) { unless (\$_ % \$i) { \$_ /= \$i; return \$i; } } my \$curr = \$_; undef \$_; return \$curr; } \$n } factor(138600); # (2, 2, 2, 3, 3, 5, 7, 11)