Skip to content

52 Function values ​

A named function can be stored in Function<Integer(Integer)> and invoked later. apply accepts the same function value as a parameter.

norm
Integer double(Integer number) {
  return number * 2
}

Integer apply(Function<Integer(Integer)> action, Integer input) {
  return action(input)
}

main() {
  Function<Integer(Integer)> saved = double
  printLine(saved(4))
  printLine(apply(action: saved, input: 7))
}

Expected output:

text
8
14

Try it: Pass double directly to apply without the saved variable.

Precise rules: Reference.

Norm 0.25