Skip to main content
Module

x/eitherway/mod.ts>Result

Yet Another Option and Result Implementation - providing safe abstractions for fallible flows inspired by F# and Rust
Latest
namespace Result
Re-export
import { Result } from "https://deno.land/x/eitherway@0.10.0/mod.ts";

Functions

Use this to lift the result of an infallible function into a Result context.

Use this to lift the result of a fallible function into a Result context.

Use this to lift a function into a Result context, by composing the wrapped function with a Result constructor.

Use this to lift a fallible function into a Result context, by composing the wrapped function with a Result constructor and an error mapping function.

type alias Result
Re-export
import { type Result } from "https://deno.land/x/eitherway@0.10.0/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

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]");
definition: Ok<T> | Err<E>
function Result
Re-export
import { Result } from "https://deno.land/x/eitherway@0.10.0/mod.ts";