fromPredicate
import { fromPredicate } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/fn_either.ts";Create a FnEither from a Predicate or a Refinement. If the Predicate or Refinement returns true then the FnEither returns Right, otherwise it returns Left.
@example
import * as FE from "./fn_either.ts";
import { pipe } from "./fn.ts";
const isPositive = (n: number) => n > 0;
const computation = FE.fromPredicate(isPositive);
const result1 = computation(0); // Left(0)
const result2 = computation(1); // Right(1)
§
Create a FnEither from a Predicate or a Refinement. If the Predicate or Refinement returns true then the FnEither returns Right, otherwise it returns Left.
@example
import * as FE from "./fn_either.ts";
import { pipe } from "./fn.ts";
const isPositive = (n: number) => n > 0;
const computation = FE.fromPredicate(isPositive);
const result1 = computation(0); // Left(0)
const result2 = computation(1); // Right(1)
§Parameters
§
refinement: Refinement<A, B>
[src]