<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"))export const const mapInput: {
<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"))
mapInput: {
<function (type parameter) B in <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>B, function (type parameter) A in <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>A>(f: (b: B) => Af: (b: Bb: function (type parameter) B in <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>B) => function (type parameter) A in <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>A): (self: Predicate<A>self: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>A>) => interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) B in <B, A>(f: (b: B) => A): (self: Predicate<A>) => Predicate<B>B>
<function (type parameter) A in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>A, function (type parameter) B in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>B>(self: Predicate<A>self: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>A>, f: (b: B) => Af: (b: Bb: function (type parameter) B in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>B) => function (type parameter) A in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>A): interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) B in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>B>
} = dual<(...args: Array<any>) => any, <A, B>(self: Predicate<A>, f: (b: B) => A) => Predicate<B>>(arity: 2, body: <A, B>(self: Predicate<A>, f: (b: B) => A) => Predicate<B>): ((...args: Array<any>) => any) & (<A, B>(self: Predicate<A>, f: (b: B) => A) => Predicate<B>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, <function (type parameter) A in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>A, function (type parameter) B in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>B>(self: Predicate<A>self: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>A>, f: (b: B) => Af: (b: Bb: function (type parameter) B in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>B) => function (type parameter) A in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>A): interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) B in <A, B>(self: Predicate<A>, f: (b: B) => A): Predicate<B>B> => (b: Bb) => self: Predicate<A>self(f: (b: B) => Af(b: Bb)))