Skip to main content
Module

x/eitherway/mod.ts>Task.from

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

Use this to create a task from a function which returns a Result<T, E> or PromiseLike<Result<T, E> value.

This function should be infallible by contract.

Use Task.fromFallible if this is not the case.

Examples

Example 1

import { Ok, Result, Task } from "https://deno.land/x/eitherway/mod.ts";

async function produceRes(): Promise<Result<number, TypeError>> {
 return Ok(42);
}

const task = Task.from(produceRes);

Parameters

fn: () => Result<T, E> | PromiseLike<Result<T, E>>