Skip to main content
Module

x/eitherway/mod.ts>Result.fromFallible

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

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

Examples

Example 1

import { assert } from "./assert.ts";
import { Err, Ok, Result } from "./mod.ts";

const castToErr = <E>(e: unknown): E => e as E;
const produceArr = () => [1,2,3];

const res: Result<number[], TypeError> = Result.fromFallible(produceArr, castToErr<TypeError>);

assert(res.isOk());

Parameters

fn: () => T
errMapFn: (e: unknown) => E