Lyricdev
GitHub

LYR-PAR0058

'&' before a lambda parameter's pattern

error · spec 03-types

A lambda parameter written as a pattern in parentheses carries the place mark &: (&(a, b)) => ….

Explanation

&n makes a parameter take the caller's place, which is one named thing. A pattern takes the value apart into new bindings; there is no single place it could stand for.

Take the place with a name, (&p) => …, or take the value apart without the mark.

Wrong

fn main(): void {
    let f = (&(a, b)) => a;
}
fn main(): void {
    let f = ((a, b): (int, int)) => a + b;
    let _ = f((1, 2));
}