3 ms·
Kotlin and also C# ? operators only “return” from the expression being evaluated. Most documentation says “return” a bit ambiguously but that’s what they mean.
by cormacrelf 4y ago
Kotlin and also C# ? operators only “return” from the expression being evaluated. Most documentation says “return” a bit ambiguously but that’s what they mean. AFAIK Rust is the first language to use ? in such a way as to return from a function, and that’s quite different. Kotlin ? can technically be emulated in Rust with an IIFE (immediately invoked function expression) like so:
// never do this, it’s rude
let x = (|| potentially().nullable()?.invocations())();
Or with Option::map, and_then and friends:
// this is the way
let x = potentially().nullable().map(|y| y.invocations());
- MrBuddyCasino 4y agoThat made it click, thanks!