either_or

Package Version Hex Docs

Implements a generic choice type named EitherOr with variants Either and Or. See also gleither.

pub type EitherOr(a, b) {
  Either(a)
  Or(b)
}

Installation

gleam add either_or@3

Example

Classify a list, then collect the values from each side:

import either_or

pub fn main() {
  let values =
    [-2, 3, -1, 4]
    |> either_or.map_classify(fn(number) { number >= 0 })

  either_or.partition(values)
  // #([3, 4], [-2, -1])
}

Either contains values for which the predicate returned True; Or contains the rest. partition preserves the original order of both groups.

What it provides

See the API documentation for the complete reference.

Development

gleam test

License

Apache-2.0

Search Document