Skip to main content
Module

x/fun/async_either.ts>match

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 match
import { match } from "https://deno.land/x/fun@v2.0.0-alpha.10/async_either.ts";

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.match(() => "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