Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/eitherway/lib/core/result.ts>asInfallible

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

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

If the lifted function or Promise throws an exception, the error will be propagated

Examples

Example 1

import { assert } from "./assert.ts"
import { Err, Ok, Result, asInfallible } from "./result.ts"

//Let's re-implement `Result.from`

const customFromImpl = <T>(fn: () => T) => Result.fromFallible(fn, asInfallible);
const getNumber = () => 42;

const fromOriginal = Result.from(getNumber);
const fromCustom = customFromImpl(getNumber);

assert(fromOriginal.isOk() === fromCustom.isOk());

Parameters

e: unknown

Returns

never