FR
PréludeChargé par défaut — aucun import nécessaire.

Result operations

Synopsis
mapOk : (a -> b) -> Result e a -> Result e b

Transform the success value, leaving an Error untouched. mapOk f (Ok x) = Ok (f x) ; mapOk f (Error e) = Error e

mapError : (e -> f) -> Result e a -> Result f a

Transform the error value, leaving an Ok untouched.

andThen : (a -> Result e b) -> Result e a -> Result e b

Chain a fallible computation: run f on the success value, short-circuit on the first Error. This is monadic bind for Result e. xs |> andThen f reads left-to-right.

result : (e -> c) -> (a -> c) -> Result e a -> c

Eliminate a Result: provide a handler for each side (error first). result onError onOk r collapses r to a single value.

withDefault : a -> Result e a -> a

The success value, or a default if it was an Error.

toMaybe : Result e a -> Maybe a

Forget the error, keeping just the optional success value.

okOr : e -> Maybe a -> Result e a

Turn an optional value into a Result, using e as the error for Nothing.