mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-22 02:00:00 +03:00
Merge pull request #3236 from dbp/or
core: adding option::or(a,b) that returns the leftmost some() or none otherwise
This commit is contained in:
@@ -93,6 +93,16 @@ enum 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.
|
||||
|
||||
Reference in New Issue
Block a user