outcome
Types
Functions
pub fn as_defect(result: Result(a, b)) -> Result(a, Problem(b))
Convert Result(a, e)
to Result(a, Problem(e))
with severity as Defect
Example
Error("Something went wrong")
|> outcome.as_defect
pub fn as_failure(result: Result(a, b)) -> Result(a, Problem(b))
Convert Result(a, e)
to Result(a, Problem(e))
with severity as Failure
.
Example
Error("Invalid input")
|> outcome.as_failure
pub fn context(
outcome outcome: Result(a, Problem(b)),
context context: String,
) -> Result(a, Problem(b))
Add context to an Outcome. This will add a Context entry to the stack.
Example
Error("Something went wrong")
|> outcome.as_defect
|> outcome.context("In find user function")
pub fn map_error(
outcome: Result(a, Problem(b)),
mapper: fn(b) -> b,
) -> Result(a, Problem(b))
Map the error value
pub fn pretty_print(
problem: Problem(a),
to_s: fn(a) -> String,
) -> String
Pretty print a Problem, including the stack. The latest problem appears at the top of the stack.
Example
Error("Something went wrong")
|> outcome.as_defect
|> outcome.context("In find user function")
|> outcome.context("More context")
|> outcome.pretty_print(function.identity)
Defect: Something went wrong
stack:
In find user function
More context
pub fn print_line(
problem: Problem(a),
to_s: fn(a) -> String,
) -> String
Print problem in one line
Example
Error("Something went wrong")
|> outcome.as_defect
|> outcome.context("In find user function")
|> outcome.print_line(function.identity)
Defect: Something went wrong < In find user function
pub fn tap(
outcome: Result(a, Problem(b)),
fun: fn(Problem(b)) -> c,
) -> Result(a, Problem(b))
Use tap functions to log the errors.
This yields the Problem
type.
pub fn tap_defect(
outcome: Result(a, Problem(b)),
fun: fn(b) -> c,
) -> Result(a, Problem(b))
Yield your error type. Only called if the severity is Defect.
pub fn tap_error(
outcome: Result(a, Problem(b)),
fun: fn(b) -> c,
) -> Result(a, Problem(b))
This yields your error type.
pub fn tap_failure(
outcome: Result(a, Problem(b)),
fun: fn(b) -> c,
) -> Result(a, Problem(b))
Yield your error type. Only called if the severity is Failure.
pub fn to_simple_result(
outcome: Result(a, Problem(b)),
) -> Result(a, b)
Remove the Problem
wrapping in the error value
Example
let result = Error("Fail") |> outcome.as_defect
outcome.to_simple_result(result) == Error("Fail")