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

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)

§Type Parameters

§
B extends A
[src]

§Parameters

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

§Return Type

§
fromPredicate<A>(predicate: Predicate<A>): FnEither<A, A, A>
[src]

§Type Parameters

§Parameters

§
predicate: Predicate<A>
[src]

§Return Type

§
fromPredicate<A>(predicate: Predicate<A>): FnEither<A, A, A>
[src]

§Type Parameters

§Parameters

§
predicate: Predicate<A>
[src]

§Return Type