RosettaCodeData/Task/Map-range/Perl-6/map-range-2.pl6

9 lines
245 B
Raku
Raw Permalink Normal View History

2013-04-10 22:43:41 -07:00
sub getmapper(Range $a, Range $b) {
2015-11-18 06:14:39 +00:00
my ($a1, $a2) = $a.bounds;
my ($b1, $b2) = $b.bounds;
2013-04-10 22:43:41 -07:00
return -> $s { $b1 + (($s-$a1) * ($b2-$b1) / ($a2-$a1)) }
}
my &mapper = getmapper(0 .. 10, -1 .. 0);
for ^11 -> $x {say "$x maps to &mapper($x)"}