Skip to main content
Module

x/eitherway/mod.ts

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

Namespaces

Utility functions to work with Option<T>[]

Utilities to work with collections of Result<T, E>

Classes

The canonical runtime exception type used internally

Task<T, E>

Functions

Use this as errMapFn to indicate that a function or Promise to be lifted into a Result or Task context is infallible

Use this to narrow an unknown error to a Panic<unknown>

Use this to lift a fetch-like function into a Task context.

Use this to apply an Option<T> to a handler of type Option<MapFn>

Alias for Option()

Use this if all falsy values should be evaluated to None

Use this if instances of Error should be evaluated to None

Use this to return the provided instance of Option<T> Mostly usefull for flattening or en lieu of a no-op

Use this to compose functions and Option constructors

Same as Option.lift but with a safety net.

Type predicate - use this to check if all values in an array are None

Type predicate - use this to check if all values in an array are Some<T>

Use this to either throw <E> directly or wrap it in a Panic<E> if <E> is not a subtype of the native Error type

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.

Use this to signal some kind of success irrespective of the wrapped type as alternative to Some<void>

Use this to cast a unknown value to a known type.

Interfaces

This is the interface of the return value of Task.deferred

The base interface implemented by Some and None

Base interface implemented by Ok<T> and Err<E>

Type Aliases

An artificial bottom type en lieu of unknown and nullish types

Err

Representation of how type T will be passed on to searialization to JSON.stringify()

None

None represents the absence of a value and is the opinionated, composable equivalent of undefined.

Ok

Option

Option<T> represents:

  • EITHER the encapsulation of a value of type <T> via Some<T>
  • OR the absence of a value via None

Result<T, E>

Some

String representation of type T, i.e. the return type of .toString()

Use this to infer the encapsulated <E> types from a tuple of Task<T,E>

Use this to infer the encapsulated <E> type from a Task<T,E>

Use this to infer a union of all encapsulated <E> types from a tuple of Task<T,E>

Use this to infer the encapsulated <T> types from a tuple of Task<T,E>

Use this to infer the encapsulated <T> type from a Task<T,E>

Use this to infer a union of all encapsulated <T> types from a tuple of Task<T,E>

Value representation of type T, i.e. the return type of .valueOf()