Skip to content

Commit 62ea688

Browse files
author
Daniel Patterson
committed
core: adding option::or, a function to return the leftmost of two some() values or none if both are none
1 parent c321cdb commit 62ea688

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libcore/option.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ pure fn chain_ref<T, U>(opt: &option<T>,
9393
match *opt { some(ref x) => f(x), none => none }
9494
}
9595

96+
pure fn or<T>(+opta: option<T>, +optb: option<T>) -> option<T> {
97+
/*!
98+
* Returns the leftmost some() value, or none if both are none.
99+
*/
100+
match opta {
101+
some(_) => opta,
102+
_ => optb
103+
}
104+
}
105+
96106
#[inline(always)]
97107
pure fn while_some<T>(+x: option<T>, blk: fn(+T) -> option<T>) {
98108
//! Applies a function zero or more times until the result is none.

0 commit comments

Comments
 (0)