gleither

Types

Monad representing a Left or Right

pub type Either(left, right) {
  Left(val: left)
  Right(val: right)
}

Constructors

  • Left(val: left)

    left

  • Right(val: right)

    right

Functions

pub fn flat_map(
  either: Either(a, b),
  func: fn(b) -> Either(a, b),
) -> Either(a, b)

alias for flat_map_right

pub fn flat_map_left(
  either: Either(a, b),
  func: fn(a) -> Either(a, b),
) -> Either(a, b)

map and flatten a Left

pub fn flat_map_right(
  either: Either(a, b),
  func: fn(b) -> Either(a, b),
) -> Either(a, b)

map and flatten a Right

pub fn flatten(either: Either(a, Either(a, b))) -> Either(a, b)

alias for flatten_right

pub fn flatten_left(
  either: Either(Either(a, b), b),
) -> Either(a, b)

flatten a nested Left

pub fn flatten_right(
  either: Either(a, Either(a, b)),
) -> Either(a, b)

flatten a nested Right

pub fn full_flat_map(
  either: Either(a, b),
  left_func: fn(a) -> Either(a, b),
  right_func: fn(b) -> Either(a, b),
) -> Either(a, b)

flat_map either potential value

pub fn full_map(
  either: Either(a, b),
  left_func: fn(a) -> c,
  right_func: fn(b) -> d,
) -> Either(c, d)

map either potential value

pub fn get(either: Either(a, b)) -> Option(b)

alias for get_right

pub fn get_left(either: Either(a, b)) -> Option(a)

get the value of a Left or None

pub fn get_left_with_default(
  either: Either(a, b),
  default: a,
) -> a

get the value of a Left or default

pub fn get_right(either: Either(a, b)) -> Option(b)

get the value of a Right or None

pub fn get_right_with_default(
  either: Either(a, b),
  default: b,
) -> b

get the value of a Right or default

pub fn get_with_default(either: Either(a, b), default: b) -> b

alias for get_right_with_default

pub fn is_left(either: Either(a, b)) -> Bool

Returns True if the supplied value is a Left

pub fn is_right(either: Either(a, b)) -> Bool

Returns True if the supplied value is a Right

pub fn map(
  either: Either(a, b),
  func: fn(b) -> c,
) -> Either(a, c)

alias for map_right

pub fn map_left(
  either: Either(a, b),
  func: fn(a) -> c,
) -> Either(c, b)

apply a function to the Left or preserve the Right

pub fn map_right(
  either: Either(a, b),
  func: fn(b) -> c,
) -> Either(a, c)

apply a function to the Right or preserve the Left

pub fn swap(either: Either(a, b)) -> Either(b, a)

Convert a Left to a Right and vice versa

Search Document