import { Result } from "https://deno.land/x/eitherway@0.10.0/lib/core/mod.ts";
Functions
Use this to lift the result of an infallible function into a | |
Use this to lift the result of a fallible function into a | |
Use this to lift a function into a | |
Use this to lift a fallible function into a |
import { type Result } from "https://deno.land/x/eitherway@0.10.0/lib/core/mod.ts";
Result<T, E>
Result<T, E>
is the composeable equivalent to the union <T | E>
, where
<T>
represents the success and <E>
the failure case
It's the type level represenation of the union Ok<T> | Err<E>
Furthermore the namespace Results
exposes a few functions
to ease working with collections of Result<T, E>
(indexed and plain
Iterables)
Examples
Example 1
Example 1
import { assert } from "./assert.ts";
import { Err, Ok, Result } from "./result.ts";
type StrOrTypeError = string | TypeError;
const str = "thing" as StrOrTypeError;
const num = 42;
const rangeErr = RangeError();
const tag = Object.prototype.toString.call(Result);
const res: Result<string, TypeError> = Result(str);
const ok: Result<number, never> = Result(num);
const err: Result<never, RangeError> = Result(rangeErr);
assert(res instanceof Result);
assert(res.isOk());
assert(ok instanceof Result);
assert(ok.isOk());
assert(err instanceof Result);
assert(err.isErr());
assert(tag === "[object eitherway::Result]");
import { Result } from "https://deno.land/x/eitherway@0.10.0/lib/core/mod.ts";