cat/instances/alternative

Values

pub fn list_alternative(
  ,
) -> alternative.Alternative(types.ListF, List(a))

Alternative instance for List.

Examples

list_alternative().or([1, 2, 3], [4, 5, 6])
// -> [1, 2, 3]
list_alternative().or([1, 2, 3], [])
// -> [1, 2, 3]
list_alternative().or([], [4, 5, 6])
// -> [4, 5, 6]
list_alternative().or([], [])
// -> []
pub fn monoid_functor_alternative(
  mono: monoid.Monoid(fa),
  arg: functor.Functor(f, a, b, fa, fb),
) -> alternative.Alternative(f, fa)

Alternative instance for Monoid + Functor.

Examples

let inst = monoid_functor_alternative(list_monoid(), list_functor())
inst.or(inst.empty, [1, 2, 3])
// -> [1, 2, 3]
inst.or([1, 2], [3, 4, 5])
// -> [1, 2, 3, 4, 5]
pub fn option_alternative(
  ,
) -> alternative.Alternative(types.OptionF, option.Option(a))

Alternative instance for Option.

Examples

option_alternative().or(Some(2), Some(3))
// -> Some(2)
option_alternative().or(Some(2), None)
// -> Some(2)
option_alternative().or(None, Some(3))
// -> Some(3)
option_alternative().or(None, None)
// -> None
pub fn result_alternative(
  error: e,
) -> alternative.Alternative(types.ResultF(e), Result(a, e))

Alternative instance for Result.

Examples

result_alternative("").or(Ok(2), Ok(3))
// -> Ok(2)
result_alternative("").or(Ok(2), Error("Nan"))
// -> Ok(2)
result_alternative("").or(Error("Nan"), Ok(3))
// -> Ok(3)
result_alternative("err").or(Error("Nan"), Error("Nan"))
// -> Error("Nan")
Search Document