Hyperlinkv0.8.0-beta.28

Predicate

Predicate.mapInputconsteffect/Predicate.ts:341
<B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>
<A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>

Transforms the input of a predicate using a mapping function.

When to use

Use when you have a predicate on A and want to check B values by mapping each B to an A, such as checking lengths or projections.

Details

Returns a new predicate that applies f before self. There is no additional short-circuiting beyond what self does.

Example (Checking string length)

import { Predicate } from "effect"

const isLongerThan2 = Predicate.mapInput((s: string) => s.length)(
  (n: number) => n > 2
)

console.log(isLongerThan2("hello"))
combinatorsPredicateandnot
export const mapInput: {
  <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>
  <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>
} = dual(2, <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B> => (b) => self(f(b)))