Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

Partial Application

Omitting arguments

The previous section on lambdas used the code

    b.for_each (x -> say x)

in the first example. This is a common pattern where a lambda expression does nothing but passing its arguments on to a feature call. Alternatively, Fuzion permits omission of arguments to create a function automatically: In this case, we can omit the argument and just type

    b.for_each say

to get the same effect:

We can also omit zero arguments to get a lambda expression, so the following example calls repeat with an implicit lambda () -> code 21 3:

While the next example turns false passed to a function type argument into the implicit nullary lambda() -> false:

Partially applying Operators

Infix operators can be applied partially: using them as prefix operators, e.g., -12 results in the lambda parameter being placed as the missing left operand x -> x-12,

while using them as postfix operators 12- inserts the lambda parameter as the right operand x -> 12-x:

A single operator can be used as a partially applied prefix or postfix operator, but it has to be enclosed in parentheses, e.g., (-). So to negate all the elements of a sequence we can perform map (-) as follows:

When assigned to a function type with two arguments, a single operator, e.g., (*) is converted into a lambda with an infix operator x,y -> x*y. The following example uses reduce with the operation (*) to multiply all the elements in a sequence:

Partially applying Target

The target t of a dot-call t.f a b may be omitted to obtain a lambda expression with one argument that will be used as a target: .f a b expands to x -> x.f a b. The following code applies as_string to convert the integer elements of a sequence to strings using different bases: