user
Given two ranges:

:   :   :   * [

              a

              1
              ,

              a

              2
              ]
              {\displaystyle {\displaystyle [a\_{1},a\_{2}]}}
                 and
            * [

              b

              1
              ,

              b

              2
              ]
              {\displaystyle {\displaystyle [b\_{1},b\_{2}]}}
              ;
            * then a value   

              s
              {\displaystyle {\displaystyle s}}
                 in range   

              [

              a

              1
              ,

              a

              2
              ]
              {\displaystyle {\displaystyle [a\_{1},a\_{2}]}}
            * is linearly mapped to a value   

              t
              {\displaystyle {\displaystyle t}}
                 in range   

              [

              b

              1
              ,

              b

              2
              ]
              {\displaystyle {\displaystyle [b\_{1},b\_{2}]}}

  where:

:   :   :   * t
              =

              b

              1
              +

              (
              s
              −

              a

              1
              )
              (

              b

              2
              −

              b

              1
              )

              (

              a

              2
              −

              a

              1
              )
              {\displaystyle {\displaystyle t=b\_{1}+{(s-a\_{1})(b\_{2}-b\_{1}) \over (a\_{2}-a\_{1})}}}

Task

Write a function/subroutine/... that takes two ranges and a real number, and returns the mapping of the real number from the first to the second range.

Use this function to map values from the range    `[0, 10]`    to the range    `[-1, 0].`

Extra credit

Show additional idiomatic ways of performing the mapping, using tools available to the language.
assistant
(formerly Perl 6)
Return a closure that does the mapping without have to supply the ranges every time.

```
sub getmapper(Range $a, Range  $b) {
  my ($a1, $a2) = $a.bounds;
  my ($b1, $b2) = $b.bounds;
  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)"}

```

Output:

```
0 maps to -1
1 maps to -0.9
2 maps to -0.8
3 maps to -0.7
4 maps to -0.6
5 maps to -0.5
6 maps to -0.4
7 maps to -0.3
8 maps to -0.2
9 maps to -0.1
10 maps to 0
```