Functions
Applies f to a present value; absent stays absent.
value: The optional to map.f: Applied to the present value.
println(some(2).map(|x| x * 10)) // some(20)The value when present, otherwise other.
value: The preferred optional.other: Used whenvalueis absent.
let absent: Optional<int> = none
println(absent.or(some(9))) // some(9)The value when present, otherwise whatever f produces.
value: The preferred optional.f: Called only whenvalueis absent.
The present value, otherwise the result of calling f.
value: The optional to unwrap.f: Called only whenvalueis absent.
let absent: Optional<int> = none
println(absent.unwrap_or_else(|| 7)) // 7Keeps a present value only when predicate accepts it.
value: The optional to test.predicate: Applied to the present value.
println(some(4).filter(|x| x > 3)) // some(4)
println(some(2).filter(|x| x > 3)) // none