Skip to main content
Module

x/fun/mod.ts>fn_either.compose

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 fn_either.compose
import { fn_either } from "https://deno.land/x/fun@v2.0.0-alpha.12/mod.ts";
const { compose } = fn_either;

Compose two FnEithers, passing the right value of the first into the second.

Examples

Example 1

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

const isPositive = (n: number) => n > 0;
const isInteger = (n: number) => Number.isInteger(n);

const isPositiveInteger = pipe(
  FE.fromPredicate(isPositive),
  FE.compose(FE.fromPredicate(isInteger)),
);

const result1 = isPositiveInteger(0); // Left(0)
const result2 = isPositiveInteger(1); // Right(1)
const result3 = isPositiveInteger(1.1); // Left(1.1)

Parameters

second: FnEither<A, J, I>

Returns

<B, D>(first: FnEither<D, B, A>) => FnEither<D, B | J, I>