Coalesce
public protocol Coalesce[Default]Raw protocol backing the ?? operator.
Implemented by Optional[T] (with Default = T, Output = T) and by
Result[T, E] (with Default = T, Output = T). The operand is a
thunk so the default expression is only evaluated when needed — this
matters when the default has side effects or is expensive to compute.
Examples
let name: String? = .None;
name ?? "anonymous" // "anonymous"
let cached: String? = .Some("hi");
cached ?? expensiveLookup() // "hi" — expensiveLookup() not calledAssociated Types
type Output
type OutputMethods
func coalesce(() -> Default) -> Output
func coalesce(() -> Default) -> OutputReturns the contained value, or the result of default() if absent.
Defined in lang/std/core/coalesce.ks