either_or
Types
Values
pub fn classify(
a: a,
classifier classifier: fn(a) -> Bool,
) -> EitherOr(a, a)
Given a value z of type z and a function fn(z) -> Bool constructs a value of type EitherOr(z, z) by outputting Either(z) if f(z) is True, else Or(z).
pub const discriminate: fn(List(a), fn(a) -> Bool) -> List(
EitherOr(a, a),
)
Alias for map_classify.
pub fn flat_map_either(
v: EitherOr(a, b),
f: fn(a) -> EitherOr(c, b),
) -> EitherOr(c, b)
Compose map_either and flatten.
pub fn flat_map_eo(
v: EitherOr(a, b),
f1: fn(a) -> EitherOr(c, d),
f2: fn(b) -> EitherOr(c, d),
) -> EitherOr(c, d)
Apply a map of codomain EitherOr(c, d) to either side of an EitherOr(a, b) and flatten
Symmetric to flat_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 flat_map_oe(
v: EitherOr(a, b),
f2: fn(b) -> EitherOr(c, d),
f1: fn(a) -> EitherOr(c, d),
) -> EitherOr(c, d)
Aplly a map of codomain EitherOr(c, d) to either side of an EitherOr(a, b) and flatten
Symmetric to flat_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 flat_map_or(
v: EitherOr(a, b),
with f: fn(b) -> EitherOr(a, c),
) -> EitherOr(a, c)
Compose map_or and flatten.
pub fn flatten(
either: EitherOr(EitherOr(a, b), EitherOr(a, b)),
) -> EitherOr(a, b)
Flatten a EitherOr(EitherOr(a, b), EitherOr(a, b)) value.
pub fn flatten_either(
either: EitherOr(EitherOr(a, b), b),
) -> EitherOr(a, b)
Flatten a EitherOr(EitherOr(a, b), b) value.
pub fn flatten_or(
either: EitherOr(a, EitherOr(a, b)),
) -> EitherOr(a, b)
Flatten a 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 constructs a value of type EitherOr(z, z) by outputting Either(z) if b is True, else Or(z).
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)
Converts an EitherOr(a, b) value into Some(x) if the value has the form Either(x), else None.
pub fn get_or(v: EitherOr(a, b)) -> option.Option(b)
Converts an EitherOr(a, b) value into Some(x) if the value has the form Or(x), else 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)). Introduces an element of the form Either([]: List(a)) between each consecutive pair of ‘Or(b)’ elements symoblizing an empty of ‘Either’ payloads sitting between pair of consecutive ‘Or(b)’ elements.
pub fn group_eithers_no_empty_lists(
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)). Discards elements of the form Either([]) from the final list.
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))). Introduces an element of the form Or([]: List(a)) between each consecutive pair of ‘Either(a)’ elements, symoblizing an empty of ‘Or’ payloads sitting between pair of consecutive ‘Either(a)’ elements.
pub fn group_ors_no_empty_lists(
ze_list: List(EitherOr(a, b)),
) -> List(EitherOr(a, List(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)). Discards elements of the form Or([]) from the final list.
pub fn is_either(v: EitherOr(a, b)) -> Bool
Given an EitherOr value returns True if and only if the value is an Either variant.
pub fn is_or(v: EitherOr(a, b)) -> Bool
Given an EitherOr value returns True if and only if the value is an Or variant.
pub fn map_classify(
list: List(z),
classifier classifier: fn(z) -> Bool,
) -> List(EitherOr(z, z))
Given a List(z) of arbitrary type and a function f: fn(z) -> Bool, returns a List(EitherOr(z, z)) by mapping over the list with classify(_, f), i.e., by replacing each value z of the list with Either(z) if f(z) True, Or(z) otherwise.
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))
Given a List(EitherOr(a, b)) and a function f: fn(a) -> c returns a List(EitherOr(c, b)) by applying map_either(_, f) to each element of the list.
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_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_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_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_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))
Given a List(EitherOr(a, b)) and a function f: fn(b) -> c returns a List(EitherOr(a, c)) by applying map_or(_, f) to each element of the list.
pub fn map_resolve(
v: List(EitherOr(a, b)),
on_either f: fn(a) -> c,
on_or g: fn(b) -> c,
) -> List(c)
Given a List(EitherOr(a, b)) and functions f: fn(a) -> c, g: fn(b) -> c, returns a List(c) by mapping each element of the form Either(a) to f(a) and each element of the form Or(b) to g(b).
pub fn remove_eithers_unwrap_ors(
ze_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 of the form Or(b).
pub fn remove_ors_unwrap_eithers(
ze_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 of the form Either(a).
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, f1(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 Either constructor for the Or constructor and vice-versa.
pub fn to_result(z: EitherOr(a, b)) -> Result(a, b)
Converts an EitherOr(a, b) into a Result(a, b).
pub fn unwrap_either(v: EitherOr(a, b), default: a) -> a
Given an EitherOr value returns x if the value has the form Either(x) otherwise returns the supplied default.