core: adding option::or, a function to return the leftmost of two some() values or none if both are none
This commit is contained in:
parent
c321cdbac6
commit
62ea688e50
1 changed files with 10 additions and 0 deletions
|
|
@ -93,6 +93,16 @@ pure fn chain_ref<T, U>(opt: &option<T>,
|
|||
match *opt { some(ref x) => f(x), none => none }
|
||||
}
|
||||
|
||||
pure fn or<T>(+opta: option<T>, +optb: option<T>) -> option<T> {
|
||||
/*!
|
||||
* Returns the leftmost some() value, or none if both are none.
|
||||
*/
|
||||
match opta {
|
||||
some(_) => opta,
|
||||
_ => optb
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn while_some<T>(+x: option<T>, blk: fn(+T) -> option<T>) {
|
||||
//! Applies a function zero or more times until the result is none.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue