The type which would be wrapped in an Ok
variant of Result
.
The type wrapped in this Err
variant of Result
.
Create an instance of Result.Err
with new
.
Note: While you may create the Result
type via normal
JavaScript class construction, it is not recommended for the functional
style for which the library is intended. Instead, use Result.err
.
// Avoid:
const anErr = new Result.Err('alas, failure');
// Prefer:
const anErr = Result.err('alas, failure');
Note that you may explicitly pass Unit
to the Err
constructor to create
a Result<T, Unit>
. However, you may not call the Err
constructor with
null
or undefined
to get that result (the type system won't allow you to
construct it that way). Instead, for convenience, you can simply call
Result.err()
, which will construct the type correctly.
The value to wrap in a Result.Err
.
Note: null
and undefined
are allowed by the type signature so that the
constructor may throw
on those rather than constructing a type like
Result<number, undefined>
.
The wrapped error value.
Err
is always Variant.Err
.
Method variant for Result.and
Method variant for Result.andThen
Method variant for Result.chain
Method variant for Result.equals
Method variant for Result.flatMap
Method variant for Result.isErr
Method variant for Result.isOk
Method variant for Result.map
Method variant for Result.mapErr
Method variant for Result.mapOr
Method variant for Result.mapOrElse
Method variant for Result.match
Method variant for Result.orElse
Method variant for Result.toJSON
Method variant for Result.toMaybe
Method variant for Result.toString
Method variant for Result.unsafelyUnwrap
Method variant for Result.unsafelyUnwrapErr
Method variant for Result.unwrapOr
Method variant for Result.unwrapOrElse
Unwrap the contained error . A convenience method for functional idioms.
A common scenario where you might want to use this is in a pipeline of functions:
import Result, { Ok } from 'true-myth/result';
function getMessages(results: Array<Result<string, Error>>): Array<number> {
return maybeStrings
.filter(Result.isErr)
.map(Err.unwrapErr)
.map(e => e.message);
}
Generated using TypeDoc
An
Err
instance is the failure variant instance of theResult
type, representing a failure outcome from an operation which may fail. For a full discussion, see the module docs.