dataprep/validated

Types

Applicative functor for error accumulation.

pub type Validated(a, e) {
  Valid(a)
  Invalid(non_empty_list.NonEmptyList(e))
}

Constructors

Values

pub fn and_then(
  v: Validated(a, e),
  f: fn(a) -> Validated(b, e),
) -> Validated(b, e)

Monadic bind. Sequential, short-circuits on error. Use for dependent operations (e.g. parse then validate). Does NOT accumulate errors – that is intentional.

pub fn from_result(r: Result(a, e)) -> Validated(a, e)

Convert from Result.

pub fn map(v: Validated(a, e), f: fn(a) -> b) -> Validated(b, e)

Transform the success value (functor map).

pub fn map2(
  f: fn(a, b) -> c,
  va: Validated(a, e),
  vb: Validated(b, e),
) -> Validated(c, e)

Combine two Validated values, accumulating all errors.

pub fn map3(
  f: fn(a, b, c) -> d,
  va: Validated(a, e),
  vb: Validated(b, e),
  vc: Validated(c, e),
) -> Validated(d, e)

Combine three Validated values, accumulating all errors.

pub fn map4(
  f: fn(a, b, c, d) -> out,
  va: Validated(a, e),
  vb: Validated(b, e),
  vc: Validated(c, e),
  vd: Validated(d, e),
) -> Validated(out, e)

Combine four Validated values, accumulating all errors.

pub fn map5(
  f: fn(a, b, c, d, e_) -> out,
  va: Validated(a, e),
  vb: Validated(b, e),
  vc: Validated(c, e),
  vd: Validated(d, e),
  ve: Validated(e_, e),
) -> Validated(out, e)

Combine five Validated values, accumulating all errors.

pub fn map_error(
  v: Validated(a, e1),
  f: fn(e1) -> e2,
) -> Validated(a, e2)

Transform every error value.

pub fn to_result(v: Validated(a, e)) -> Result(a, List(e))

Convert to Result (collapses errors into a list).

Search Document