short of having a language mechanism for doing an 'uninitialized' let, conditional operators could work:
let x : Something = condition ? foo() : bar()
but yeah, it would be nice to defer initialization of an immutable.
let x : Something = condition ? foo() : bar()
but yeah, it would be nice to defer initialization of an immutable.
let x: Something = {
if condition {
someSideEffect()
return foo()
} else {
anotherSideEffect()
return bar()
}
}()
But it's kind of ugly. let x: Something = if condition {
// do stuff
foo()
} else {
// do other stuff
bar()
}let x : Something = outer_conditional ? baz() : conditional ? foo() : bar()
let x = conditional1 ? bar() :
conditional2 ? baz() :
conditional3 ? quux() :
someDefault