3 ms·
An immediately invoked lambda pattern, but, check out how ugly that was compared to: let value = if a { true } else { match b { 1 => false, _ => undefined }
by tialaramex 4y ago
An immediately invoked lambda pattern, but, check out how ugly that was compared to:
let value = if a { true } else { match b { 1 => false, _ => undefined } };
And notice that because now we're a function our relationship to the world changed, how does your immediately invoked lambda do this?
let value = if a { true } else { match b { 1 => false, 2 => return foo, _ => undefined }};
With expression syntax returning from the function we're in is fine† but in your lambda you can't do that, you need control flow logic outside the lambda to handle it.
† You might wonder about the inferred type of this expression since it might return. The type of the return expression in Rust is ! aka Never, which is an empty type. In the same way that N + 0 == N in integer arithmetic, any type plus an empty type is the original type again in type arithmetic, so the type of the expression isn't altered.