Subroutines & signatures

Currying with .assuming

Full

Fix some of a routine's arguments to make a new, smaller routine.

.assuming curries a routine: it binds some arguments now and returns a new Callable that takes the rest. It's partial application without writing a wrapper closure.

Fixing an argument #

sub add($a, $b) { $a + $b }
my &add5 = &add.assuming(5);
say add5(10);
Output
15

add5 is add with its first argument fixed at 5, so add5(10) is add(5, 10).

Currying into a pipeline #

Because the result is a plain Callable, a curried routine drops straight into map, grep, or a feed — a tidy way to specialise a general routine at the call site.

sub scale($factor, $x) { $factor * $x }
my &double = &scale.assuming(2);
say (1, 2, 3).map(&double);
Output
(2 4 6)

Notes #