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

flatmapFirst

import { flatmapFirst } 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, but keep the original Right value if the function succeeds. This is useful for validation or side effects.

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

const validatePositive = (n: number) =>
  n > 0 ? E.right(n) : E.left("Number must be positive");

const result1 = E.flatmapFirst(validatePositive)(E.right(5));
// Right(5)

const result2 = E.flatmapFirst(validatePositive)(E.right(-3));
// Left("Number must be positive")
function flatmapFirst<A, I = never, J = never>(faui: (a: A) => Either<J, I>): <B = never>(ta: Either<B, A>) => Either<B | J, A>;
§
flatmapFirst<A, I = never, J = never>(faui: (a: A) => Either<J, I>): <B = never>(ta: Either<B, A>) => Either<B | J, A>
[src]

§Type Parameters

§
I = never
[src]
§
J = never
[src]

§Parameters

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

§Return Type

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