Convenience functions for working with Result.
Check whether the result is Err without unwrapping it.
Turn a Result e a to an a, by applying the conversion
function specified to the e.
Convert a Result e a to a b by applying a function if
the Result is Ok or using the provided default value if it
is an Err.
Convert a Result e a to a b by applying either the first
function if the Result is an Err or the second function if the
Result is Ok. Both of these functions must return the same type.
Apply the first argument function to an Err and the second
argument function to an Ok of a Result.
Combine a list of results into a single result (holding a list).
Like the Boolean || this will return the first value that is
positive (Ok). However, unlike with ||, both values will be
computed anyway (there is no short-circuiting).
Ok 4 `or` Ok 5 == Ok 4
Err "Oh!" `or` Ok 5 == Ok 5
Ok 4 `or` Err "No!" == Ok 4
Err "Oh!" `or` Err "No!" == Err "No!"As the last example line shows, the second error is returned if both results are erroneous.
Non-strict version of or. The second argument will only be
evaluated if the first argument is an Err.
Piping-friendly version of orLazy. The first argument will only
be evaluated if the second argument is an Err. Example use:
String.toInt "Hello"
|> orElseLazy (\() -> String.toInt "42")Strict version of orElseLazy (and at the same time,
piping-friendly version of or).
orElse (Ok 4) (Ok 5) == Ok 5 -- crucial difference from `or`
orElse (Err "Oh!") (Ok 5) == Ok 5
orElse (Ok 4) (Err "No!") == Ok 4
orElse (Err "Oh!") (Err "No!") == Err "Oh!" -- also different from `or`Also:
String.toInt "Hello"
|> orElse (String.toInt "42")
Check whether the result is
Okwithout unwrapping it.