Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

flatmap

import { flatmap } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/either.ts";

Chain computations by applying a function that returns an Either to the Right value of an Either. Left values are unchanged.

@example
import * as E from "./either.ts";

const divide = (a: number) => (b: number) =>
  b === 0 ? E.left("Division by zero") : E.right(a / b);

const result1 = E.flatmap(divide(10))(E.right(2));
// Right(5)

const result2 = E.flatmap(divide(10))(E.right(0));
// Left("Division by zero")

const result3 = E.flatmap(divide(10))(E.left("Invalid input"));
// Left("Invalid input")
function flatmap<A, I, J>(fati: (a: A) => Either<J, I>): <B>(ta: Either<B, A>) => Either<B | J, I>;
§
flatmap<A, I, J>(fati: (a: A) => Either<J, I>): <B>(ta: Either<B, A>) => Either<B | J, I>
[src]

§Type Parameters

§Parameters

§
fati: (a: A) => Either<J, I>
[src]

§Return Type

§
<B>(ta: Either<B, A>) => Either<B | J, I>
[src]