Skip to main content
Module

x/fun/fn_either.ts>bimap

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function bimap
import { bimap } from "https://deno.land/x/fun@v2.0.0/fn_either.ts";

Map over the left and right return values of a FnEither.

Examples

Example 1

import * as FE from "./fn_either.ts";
import * as E from "./either.ts";
import { pipe } from "./fn.ts";

const boundedValue = (n: number) => n > 10 || n < 0 ? E.left(n) : E.right(n);

const log = pipe(
  boundedValue,
  FE.bimap(n => `Out of bounds: ${n}`, n => `Received a good value: ${n}`),
);

const result1 = log(1); // Right("Received a good value: 1")
const result2 = log(20); // Left("Out of bounds: 20")

Parameters

fbj: (b: B) => J
fai: (a: A) => I

Returns

<D = unknown>(ua: FnEither<D, B, A>) => FnEither<D, J, I>