fromPredicate
import { fromPredicate } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/either.ts";Create an Either from a predicate function. If the predicate returns true for the input value, the result is Right with the value. If false, the result is Left with the original value.
@example
import * as E from "./either.ts";
const isPositive = E.fromPredicate((n: number) => n > 0);
const result1 = isPositive(5); // Right(5)
const result2 = isPositive(-3); // Left(-3)
const result3 = isPositive(0); // Left(0)
§
Create an Either from a predicate function. If the predicate returns true for the input value, the result is Right with the value. If false, the result is Left with the original value.
@example
import * as E from "./either.ts";
const isPositive = E.fromPredicate((n: number) => n > 0);
const result1 = isPositive(5); // Right(5)
const result2 = isPositive(-3); // Left(-3)
const result3 = isPositive(0); // Left(0)
§Parameters
§
refinement: Refinement<A, B>
[src]