Skip to content

57 Trailing callbacks ​

A final function argument can appear as a trailing block. The first call names the lambda parameter with in; the second uses the inferred parameter name.

norm
Integer calculate(Integer input, Integer action(Integer value)) {
  return action(input)
}

main() {
  Integer doubled = calculate(input: 7) { value in
    value * 2
  }
  printLine(doubled)
  printLine(calculate(input: 4) { value * 3 })
}

Expected output:

text
14
12

Try it: Move the input value from 4 to 5 and predict the result.

Precise rules: Reference.

Norm 0.25