[go: up one dir, main page]

kex oops docs ↗ kex.run ↗

All codes › Parse

KEXEP-0118

error AmpFunctionCapture

[KEXEP-0118]: Error, `&name` is no longer valid: write `~name` to capture a named function ('&' is receiver shorthand only, as in `&.method`)

& is only for calling a method on each element, as in &.upperCase. To pass a function you defined, such as double, capture it with ~.

let double(n: Integer) -> Integer = n * 2

main do
  IO.printLine([1, 2, 3].map(&double))
end
example.kex:4:31: [KEXEP-0118]: Error, `&double` is no longer valid: write `~double` to capture a named function ('&' is receiver shorthand only, as in `&.method`)
  |
4 |   IO.printLine([1, 2, 3].map(&double))
  |                               ^^^^^^

Fixing it

let double(n: Integer) -> Integer = n * 2

main do
  IO.printLine([1, 2, 3].map(~double))
end

~double is the function itself. &.double also works here, because n.double is the same call as double(n).

Edit this explanation

Is this diagnostic reported where it should not be, missing where it should be, or saying the wrong thing? Report it on the compiler's issue tracker.