A type that represents one of two alternatives
either
- The either typeeither
- Applies a function based on the given either valueflip
- Flips between left and right of a given eitheris_left
- Checks whether the given value is a leftis_right
- Checks whether the given value is a rightlefts
- Extracts from a vector of either all the left valuespartition
- Extracts from a vector of either all the left values and right valuesrights
- Extracts from a vector of either all the right valuesto_result
- Converts either::t to a result::teither
The either type
left(T)
right(U)
either
fn either<T, U,
V>(f_left: fn(T) -> V, f_right: fn(U) -> V, value: either<T, U>) ->
V
Applies a function based on the given either value
If value
is left(T) then f_left
is applied to its contents, if value
is right(U) then f_right
is applied to its contents, and the result is returned.
flip
pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T>
Flips between left and right of a given either
is_left
pure fn is_left<T, U>(eith: either<T, U>) -> bool
Checks whether the given value is a left
is_right
pure fn is_right<T, U>(eith: either<T, U>) -> bool
Checks whether the given value is a right
lefts
fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T]
Extracts from a vector of either all the left values
partition
fn partition<T: copy, U: copy>(eithers: ~[either<T, U>]) ->
{lefts: ~[T], rights: ~[U],}
Extracts from a vector of either all the left values and right values
Returns a structure containing a vector of left values and a vector of right values.
rights
fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U]
Extracts from a vector of either all the right values
to_result
pure fn to_result<T: copy, U: copy>(eith: either<T, U>) -> result<U, T>
Converts either::t to a result::t
Converts an either
type to a result
type, making the "right" choice an ok result, and the "left" choice a fail