Punie / elm-reader / Reader.Except

Sometimes, you may want to build up a computation using Reader env value where the value is a result that may or may not fail. Elm already provides us with the Result err value that provides this functionality. However, working with nested ADT can be cumbersome. This module exposes the type Except env err val which is just a type alias for a Reader env (Result err val) and provides some useful functions for mapping over or chaining such nested computations.

The Except type


type alias Except env err val =
Reader env (Result err val)

The Except type wraps the result from a Reader into a Result.

Construction

succeed : a -> Except env err a

Embed a successful value inside a Reader.

fail : err -> Except env err a

Embeds a failure inside a Reader.

Transformations and chaining

map : (a -> b) -> Except env err a -> Except env err b

Apply a function to the resulting value of the Reader if successful.

andMap : Except env err a -> Except env err (a -> b) -> Except env err b

Apply a function embeded in an Except to a successful value in an Except.

andThen : (a -> Except env err b) -> Except env err a -> Except env err b

Chain Excepts together.

andResult : (a -> Result err b) -> Except env err a -> Except env err b

Chain Except with a Result.

join : Except env err (Except env err a) -> Except env err a

Discards one level of Except