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

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)
function fromPredicate<A, B extends A>(refinement: Refinement<A, B>): (a: A) => Either<A, B>;
function fromPredicate<A>(predicate: Predicate<A>): (a: A) => Either<A, A>;
function fromPredicate<A>(predicate: Predicate<A>): (a: A) => Either<A, A>;
§
fromPredicate<A, B extends A>(refinement: Refinement<A, B>): (a: A) => Either<A, B>
[src]

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)

§Type Parameters

§
B extends A
[src]

§Parameters

§
refinement: Refinement<A, B>
[src]

§Return Type

§
(a: A) => Either<A, B>
[src]
§
fromPredicate<A>(predicate: Predicate<A>): (a: A) => Either<A, A>
[src]

§Type Parameters

§Parameters

§
predicate: Predicate<A>
[src]

§Return Type

§
(a: A) => Either<A, A>
[src]
§
fromPredicate<A>(predicate: Predicate<A>): (a: A) => Either<A, A>
[src]

§Type Parameters

§Parameters

§
predicate: Predicate<A>
[src]

§Return Type

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