gleyre
Types
Analog of the Result – analagous to a Result(a, Report).
pub type Outcome(a) {
Okay(a)
Err(Report)
}
Constructors
-
Okay(a) -
Err(Report)
Values
pub fn all(outcomes: List(Outcome(a))) -> Outcome(List(a))
Like result.all(), either returns the first Err() value in the
list, or the whole list of positive outcomes.
pub fn annotate(report: Report, message: String) -> Report
Add a layer of messaging to an error variant.
pub fn from(std_result: Result(a, b)) -> Outcome(a)
Convert from a regular Result by using string.inspect() if the
Result is an error.
pub fn into(outcome: Outcome(a)) -> Result(a, String)
Turn you Outcome back into a regular Gleam Error.
pub fn is_err(outcome: Outcome(a)) -> Bool
Like result.is_error(), returns True if it’s an Err variant.
pub fn is_okay(outcome: Outcome(a)) -> Bool
Like result.is_ok(), returns True if it’s an Okay variant.
pub fn map(outcome: Outcome(a), f: fn(a) -> b) -> Outcome(b)
Like result.map() – applies the given function if the outcome is
Okay.
pub fn replace(outcome: Outcome(a), replacement: b) -> Outcome(b)
Like result.replace(), replaces the Outcome’s value if it’s Okay.
pub fn to_string(report: Report) -> String
Turn a Report into a formatted message displaying the layers of
error messaging.
pub fn try(
outcome: Outcome(a),
next: fn(a) -> Outcome(b),
) -> Outcome(b)
Like result.try; for exploiting use sugar.
fn fallible_function(data: Kind) -> Outcome(OtherKind) {
use step_one <- gleyre.try(other_fallible_function(data))
use step_two <- gleyre.try(yet_another(step_one))
Okay(step_two)
}
pub fn try_or_wrap(
outcome: Outcome(a),
message: String,
next: fn(a) -> Outcome(b),
) -> Outcome(b)
For the use-case, but also adds an extra level of messaging to the error.
pub fn unwrap(outcome: Outcome(a), default: a) -> a
Like result.unwrap(), returns the Okay variant or the provided default.
pub fn wrap(outcome: Outcome(a), message: String) -> Outcome(a)
If the Outcome is an error, this adds another layer of message to it.
pub fn yield_errors(report: Report) -> Yielder(String)
Iterate down through the layers of error messages.
pub fn yield_indexed(report: Report) -> Yielder(#(String, Int))
Iterate down through the indexed layers of error messages.