either_or
Types
Values
pub fn classify(
a: a,
predicate predicate: fn(a) -> Bool,
) -> EitherOr(a, a)
Alias for of from_predicate.
pub fn discriminate(
from list: List(z),
with predicate: fn(z) -> Bool,
) -> List(EitherOr(z, z))
Alias for map_classify(_, f).
pub fn flat_map_either(
v: EitherOr(a, b),
f: fn(a) -> EitherOr(c, b),
) -> EitherOr(c, b)
Compose map_either and flatten_either.
pub fn flat_map_or(
v: EitherOr(a, b),
with f: fn(b) -> EitherOr(a, c),
) -> EitherOr(a, c)
Compose map_or and flatten_or.
pub fn flatten(
t: EitherOr(EitherOr(a, b), EitherOr(a, b)),
) -> EitherOr(a, b)
Flatten a EitherOr(EitherOr(a, b), EitherOr(a, b)) value.
Isomorphic to the special case of unwrap in which the type
a has the form EitherOr(c, d) for some types c and d.
pub fn flatten_either(
t: EitherOr(EitherOr(a, b), b),
) -> EitherOr(a, b)
Flatten an EitherOr(EitherOr(a, b), b)-value.
pub fn flatten_or(
t: EitherOr(a, EitherOr(a, b)),
) -> EitherOr(a, b)
Flatten an EitherOr(a, EitherOr(a, b))-value.
pub fn from_bool(z: z, b: Bool) -> EitherOr(z, z)
Given a value z of arbitrary type and a bool b returns
Either(z) if b == True else returns Or(z).
pub fn from_predicate(
a: a,
predicate predicate: fn(a) -> Bool,
) -> EitherOr(a, a)
Lazy form of from_bool.
pub fn from_result(z: Result(a, b)) -> EitherOr(a, b)
Converts a Result(a, b) into an EitherOr(a, b).
pub fn get_either(v: EitherOr(a, b)) -> option.Option(a)
Given a value of type EitherOr(a, b) returns Some(a) if
the value has the form Either(a) else returns None.
pub fn get_or(v: EitherOr(a, b)) -> option.Option(b)
Given a value of type EitherOr(a, b) returns Some(x) if
the value has the form Or(x) else returns None.
pub fn group_eithers(
ze_list: List(EitherOr(a, b)),
) -> List(EitherOr(List(a), b))
Aggregates the payloads of consecutive Either instances
from a List(EitherOr(a, b)) into single Either(List(a))
elements, such as to turn a List(EitherOr(a, b)) into a
List(EitherOr(List(a), b)).
pub fn group_ors(
ze_list: List(EitherOr(a, b)),
) -> List(EitherOr(a, List(b)))
Aggregates the payloads of consecutive Or instances
from a List(EitherOr(a, b)) into single Or(List(b))
elements such as to turn a List(EitherOr(a, b)) into a
List(EitherOr(a, List(b))).
pub fn is_either(v: EitherOr(a, b)) -> Bool
Given a value of type EitherOr(a, b) returns True if and
only if the value is an Either variant.
pub fn is_or(v: EitherOr(a, b)) -> Bool
Given a value of type EitherOr(a, b) value returns True if and
only if the value is an Or variant.
pub fn keep_eithers(list: List(EitherOr(a, b))) -> List(a)
Given a List(EitherOr(a, b)) removes all elements
of the form Or(b) and unwraps the remaining elements.
pub fn keep_ors(list: List(EitherOr(a, b))) -> List(b)
Given a List(EitherOr(a, b)) removes all elements
of the form Either(a) and unwraps the remaining elements.
pub fn map_classify(
from list: List(z),
with predicate: fn(z) -> Bool,
) -> List(EitherOr(z, z))
Given a List(z) and a function f: z -> Bool returns
a List(EitherOr(z, z)) by mapping over the list with
classify(_, f).
pub fn map_either(
v: EitherOr(a, b),
f: fn(a) -> c,
) -> EitherOr(c, b)
Given a value of type EitherOr(a, b) and a
function f: a -> c returns Either(f(a)) if the
value has the form Either(a) and returns Or(b)
if the value has the form Or(b).
pub fn map_eithers(
v: List(EitherOr(a, b)),
f: fn(a) -> c,
) -> List(EitherOr(c, b))
Applies map_either to each element of a list of
EitherOr(a, b) elements.
pub fn map_eo(
v: EitherOr(a, b),
on_either: fn(a) -> a_prime,
on_or: fn(b) -> b_prime,
) -> EitherOr(a_prime, b_prime)
Apply separate maps to each payload of an EitherOr
value.
Symmetric to map_oe.
Both functions are offered to in order to allow
the happy path to be pursued with either Either
or Or variants via the use <- syntax.
pub fn map_oe(
v: EitherOr(a, b),
on_or: fn(b) -> b_prime,
on_either: fn(a) -> a_prime,
) -> EitherOr(a_prime, b_prime)
Apply separate maps to each payload of an EitherOr
value.
Symmetric to map_eo.
Both functions are offered to in order to allow
the happy path to be pursued with either Either
or Or variants via the use <- syntax.
pub fn map_or(
v: EitherOr(a, b),
with f: fn(b) -> c,
) -> EitherOr(a, c)
Given a value of type EitherOr(a, b) and a
function f: b -> c returns Or(f(b)) if the
value has the form Or(b) and returns Either(a)
if the value has the form Either(a).
pub fn map_ors(
v: List(EitherOr(a, b)),
f: fn(b) -> c,
) -> List(EitherOr(a, c))
Applies map_or to each element of a list of
EitherOr(a, b) elements.
pub fn map_resolve(
v: List(EitherOr(a, b)),
on_either f: fn(a) -> c,
on_or g: fn(b) -> c,
) -> List(c)
Applies resolve_eo to each element of a list
of EitherOr(a, b) elements.
pub fn partition(
from list: List(EitherOr(a, b)),
) -> #(List(a), List(b))
Splits a List(EitherOr(a, b)) into a #(List(a), List(b))
while maintaining the order in each sublist.
See also partition_reversed.
pub fn partition_reversed(
from list: List(EitherOr(a, b)),
) -> #(List(a), List(b))
Splits a List(EitherOr(a, b)) into a #(List(a), List(b))
while inverting the order in each sublist. Faster than
either_or.partition, which maintains the
original order.
pub fn resolve_eo(
t: EitherOr(a, b),
on_either f1: fn(a) -> c,
on_or f2: fn(b) -> c,
) -> c
Given a value of type EitherOr(a, b) and functions
f1: a -> c, f2: b -> c, returns f1(a) if the
value has the form Either(a) and returns f2(b)
if the value has the form Or(b).
Symmetric to resolve_oe.
Both functions are offered to in order to allow
the happy path to be pursued with either Either
or Or variants via the use <- syntax.
pub fn resolve_oe(
t: EitherOr(a, b),
on_or f1: fn(b) -> c,
on_either f2: fn(a) -> c,
) -> c
Given a value of type EitherOr(a, b) and functions
f1: b -> c, f2: a -> c, returns f1(a) if the
value has the form Either(a) and returns f2(b)
if the value has the form Or(b).
Symmetric to resolve_eo.
Both functions are offered to in order to allow
the happy path to be pursued with either Either
or Or variants via the use <- syntax.
pub fn swap(v: EitherOr(a, b)) -> EitherOr(b, a)
Given a value of type EitherOr(a, b) returns a
value of type EitherOr(b, a) by swapping the payloads.
pub fn to_result(z: EitherOr(a, b)) -> Result(a, b)
Converts an EitherOr(a, b) into a Result(a, b).
pub fn unwrap(v: EitherOr(a, a)) -> a
Given a value of type EitherOr(a, a) returns the payload
of type a regardless of the variant.
pub fn unwrap_either(v: EitherOr(a, b), default: a) -> a
Given a value of type EitherOr(a, b) and default of type a
returns x if the value has the form Either(x) else returns
the default.