Skip to content

Commit

Permalink
core: adding option::or, a function to return the leftmost of two som…
Browse files Browse the repository at this point in the history
…e() values or none if both are none
  • Loading branch information
Daniel Patterson committed Aug 21, 2012
1 parent c321cdb commit 62ea688
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libcore/option.rs
Expand Up @@ -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.
Expand Down

0 comments on commit 62ea688

Please sign in to comment.