<A, B extends A>(refinement: Predicate.Refinement<A, B>): (
a: A
) => Array<B>
<A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>Lifts a predicate into an array: returns [value] if the predicate holds,
[] otherwise.
Example (Wrapping values conditionally)
import { Array } from "effect"
const isEven = (n: number) => n % 2 === 0
const to = Array.liftPredicate(isEven)
console.log(to(1)) // []
console.log(to(2)) // [2]export const const liftPredicate: {
<A, B extends A>(
refinement: Predicate.Refinement<A, B>
): (a: A) => Array<B>
<A>(predicate: Predicate.Predicate<A>): <
B extends A
>(
b: B
) => Array<B>
}
Lifts a predicate into an array: returns [value] if the predicate holds,
[] otherwise.
Example (Wrapping values conditionally)
import { Array } from "effect"
const isEven = (n: number) => n % 2 === 0
const to = Array.liftPredicate(isEven)
console.log(to(1)) // []
console.log(to(2)) // [2]
liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.
<function (type parameter) A in <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>A, function (type parameter) B in <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>B extends function (type parameter) A in <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>A>(refinement: Predicate.Refinement<A, B>refinement: import PredicatePredicate.interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) A in <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>A, function (type parameter) B in <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>B>): (a: Aa: function (type parameter) A in <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>A) => interface Array<T>Array<function (type parameter) B in <A, B extends A>(refinement: Predicate.Refinement<A, B>): (a: A) => Array<B>B>
<function (type parameter) A in <A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>A>(predicate: Predicate.Predicate<A>predicate: import PredicatePredicate.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>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>A>): <function (type parameter) B in <B extends A>(b: B): Array<B>B extends function (type parameter) A in <A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>A>(b: B extends Ab: function (type parameter) B in <B extends A>(b: B): Array<B>B) => interface Array<T>Array<function (type parameter) B in <B extends A>(b: B): Array<B>B>
} = <function (type parameter) A in <A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>A>(predicate: Predicate.Predicate<A>predicate: import PredicatePredicate.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>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>A>) => <function (type parameter) B in <B extends A>(b: B): Array<B>B extends function (type parameter) A in <A>(predicate: Predicate.Predicate<A>): <B extends A>(b: B) => Array<B>A>(b: B extends Ab: function (type parameter) B in <B extends A>(b: B): Array<B>B): interface Array<T>Array<function (type parameter) B in <B extends A>(b: B): Array<B>B> => predicate: Predicate.Predicate<A>predicate(b: B extends Ab) ? [b: B extends Ab] : []