Hoare.Result (hoare v0.1.0)

Copy Markdown View Source

Combinators over {:ok, value} | {:error, reason}.

The tagged tuple is the ecosystem's result type, so nothing is wrapped: with is the bind, and these name the few compositions a transition needs so it can be a value. kleisli/1 composes a list of arrows into one.

Summary

Functions

Composes arrows left to right into one arrow; the empty list is the identity.

Types

arrow(a, b)

@type arrow(a, b) :: (a -> t(b))

error()

@type error() :: {:error, term()}

ok(value)

@type ok(value) :: {:ok, value}

t(value)

@type t(value) :: ok(value) | error()

Functions

bind(error, fun)

@spec bind(t(a), arrow(a, b)) :: t(b) when a: term(), b: term()

kleisli(arrows)

@spec kleisli([arrow(term(), term())]) :: arrow(term(), term())

Composes arrows left to right into one arrow; the empty list is the identity.

map_error(ok, fun)

@spec map_error(t(a), (term() -> term())) :: t(a) when a: term()

tap_error(ok, fun)

@spec tap_error(t(a), (term() -> term())) :: t(a) when a: term()

tap_ok(ok, fun)

@spec tap_ok(t(a), (a -> term())) :: t(a) when a: term()