Home / Docs / Standard library / Prelude
or_else
Release v0.4.0Edition 0.1 and later
A function of the prelude, in scope in every module. Edition 0.1 and later.
una
pub or_else[T](o: Option[T], default: T) -> TThe value v when o is Some(v), and default when o is None; default is an argument like any other, evaluated before the call (spec/14 §1).
Parameters
o: the optiondefault: the value forNone, evaluated before the call
Returns
T: the value of Some, and default for None.
See also
Example
src/shop.una
module shop
--- The first item of a cart, or a placeholder.
pub main() -> Unit
uses @console: Console[print]
=
let empty: List[Text] = []
let shown = empty.first().or_else(default: "nothing yet")
@console.print(shown)una run . prints:
Output
nothing yetSpecification
Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.