diff --git a/src/libcore/option.rs b/src/libcore/option.rs index c122fb9e46f8..bae84796b167 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -93,6 +93,16 @@ pure fn chain_ref(opt: &option, match *opt { some(ref x) => f(x), none => none } } +pure fn or(+opta: option, +optb: option) -> option { + /*! + * Returns the leftmost some() value, or none if both are none. + */ + match opta { + some(_) => opta, + _ => optb + } +} + #[inline(always)] pure fn while_some(+x: option, blk: fn(+T) -> option) { //! Applies a function zero or more times until the result is none.