Skip to main content
Module

x/fun/mod.ts>async_either.fold

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function async_either.fold
import { async_either } from "https://deno.land/x/fun@v2.0.0-alpha.6/mod.ts";
const { fold } = async_either;

Fold away the inner Either from the AsyncEither leaving us with the result of our computation in the form of a Async

import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import * as TE from "./async_either.ts";
import * as T from "./async.ts";
import { flow, identity } from "./fn.ts";

const hello = flow(
  TE.fold(() => "World", identity),
  T.map((name) => `Hello ${name}!`),
);

assertEquals(await hello(TE.right("Functional!"))(), "Hello Functional!!");
assertEquals(await hello(TE.left(Error))(), "Hello World!");

Parameters

onLeft: (left: L) => B
onRight: (right: R) => B

Returns

(ta: AsyncEither<L, R>) => Async<B>