import type { TypeLambda } from "./HKT.ts"; import type { TupleOf, TupleOfAtLeast } from "./Types.ts"; /** * 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 {@link and}/{@link 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) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isPositive: Predicate.Predicate = (n) => n > 0 * * isPositive(1) // => true * ``` * * @see {@link Refinement} * @see {@link mapInput} * @see {@link and} * @stability stable * @category models * @since 2.0.0 */ export interface Predicate { (a: A): boolean; } /** * Type-level lambda for higher-kinded usage of {@link Predicate}. * * **When to use** * * Use when you are defining APIs that abstract over predicates with HKTs and * need a `TypeLambda` instance for predicate-based type classes. * * **Details** * * This is type-only, creates no runtime value, and does not affect emitted * JavaScript. * * **Example** (Type-level usage) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * type P = Predicate.Predicate * type TL = Predicate.PredicateTypeLambda * * const witness: P = (value) => value > 0 * witness(1) // => true * ``` * * @see {@link Predicate} * @stability stable * @category utility types * @since 2.0.0 */ export interface PredicateTypeLambda extends TypeLambda { readonly type: Predicate; } /** * 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 {@link 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) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isString: Predicate.Refinement = (u): u is string => typeof u === "string" * * const data: unknown = "hello" * if (isString(data)) { * data.toUpperCase() // => "HELLO" * } * ``` * * @see {@link Predicate} * @see {@link compose} * @see {@link isString} * @stability stable * @category models * @since 2.0.0 */ export interface Refinement { (a: A): a is B; } /** * Type-level utilities for working with {@link 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) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * type IsString = Predicate.Predicate * type Input = Predicate.Predicate.In * * const input: Input = "value" * ``` * * @see {@link Predicate} * @see {@link Refinement} * @stability stable * @since 3.6.0 */ export declare namespace Predicate { /** * Extracts the input type `A` from a `Predicate`. * * **When to use** * * Use when you want to infer the input type from a predicate type while * defining generic utilities over predicates. * * **Details** * * This is type-only and creates no runtime value. It resolves to `never` if * the type does not match `Predicate`. * * **Example** (Inferring the input type) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * type P = Predicate.Predicate * type Input = Predicate.Predicate.In

* * const input: Input = 1 * ``` * * @see {@link Predicate.Any} * @see {@link Refinement.In} * @category utility types * @since 3.6.0 */ type In = [T] extends [Predicate] ? _A : never; /** * A utility type representing any predicate type. * * **When to use** * * Use when you need a constraint for "any predicate" in generic code. * * **Details** * * This is type-only and creates no runtime value. * * **Example** (Using generic constraints) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * type AnyPredicate = Predicate.Predicate.Any * * const witness: AnyPredicate = () => true * witness("value") // => true * ``` * * @see {@link Predicate.In} * @category utility types * @since 3.6.0 */ type Any = Predicate; } /** * Type-level utilities for working with {@link 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) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * type IsString = Predicate.Refinement * type Input = Predicate.Refinement.In * type Output = Predicate.Refinement.Out * * const output: Output = "value" * ``` * * @see {@link Refinement} * @see {@link Predicate} * @stability stable * @since 3.6.0 */ export declare namespace Refinement { /** * Extracts the input type `A` from a `Refinement`. * * **When to use** * * Use when you want to infer the input type from a refinement type. * * **Details** * * This is type-only and creates no runtime value. It resolves to `never` if * the type does not match `Refinement`. * * **Example** (Inferring the input type) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * type R = Predicate.Refinement * type Input = Predicate.Refinement.In * * const input: Input = "value" * ``` * * @see {@link Refinement.Out} * @see {@link Predicate.In} * @category utility types * @since 3.6.0 */ type In = [T] extends [Refinement] ? _A : never; /** * Extracts the output type `B` from a `Refinement`. * * **When to use** * * Use when you want to infer the narrowed type from a refinement type. * * **Details** * * This is type-only and creates no runtime value. It resolves to `never` if * the type does not match `Refinement`. * * **Example** (Inferring the output type) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * type R = Predicate.Refinement * type Output = Predicate.Refinement.Out * * const output: Output = "value" * ``` * * @see {@link Refinement.In} * @category utility types * @since 3.6.0 */ type Out = [T] extends [Refinement] ? _B : never; /** * A utility type representing any refinement type. * * **When to use** * * Use when you need a constraint for "any refinement" in generic code. * * **Details** * * This is type-only and creates no runtime value. * * **Example** (Using generic constraints) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * type AnyRefinement = Predicate.Refinement.Any * * const witness: AnyRefinement = (_): _ is string => true * witness("value") // => true * ``` * * @see {@link Refinement.In} * @see {@link Refinement.Out} * @category utility types * @since 3.6.0 */ type Any = Refinement; } /** * 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) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isLongerThan2 = Predicate.mapInput((s: string) => s.length)( * (n: number) => n > 2 * ) * * isLongerThan2("hello") // => true * ``` * * @see {@link Predicate} * @see {@link and} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ export declare const mapInput: { /** * 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) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isLongerThan2 = Predicate.mapInput((s: string) => s.length)( * (n: number) => n > 2 * ) * * isLongerThan2("hello") // => true * ``` * * @see {@link Predicate} * @see {@link and} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (f: (b: B) => A): (self: Predicate) => Predicate; /** * 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) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isLongerThan2 = Predicate.mapInput((s: string) => s.length)( * (n: number) => n > 2 * ) * * isLongerThan2("hello") // => true * ``` * * @see {@link Predicate} * @see {@link and} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (self: Predicate, f: (b: B) => A): Predicate; }; /** * Checks whether a readonly array has exactly `n` elements. * * **When to use** * * Use when you need a `Predicate` guard for exact tuple length that narrows * `ReadonlyArray` to `TupleOf`. * * **Details** * * This only checks length, not element types, and returns a refinement on the * array type. * * **Example** (Checking exact length) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isPair = Predicate.isTupleOf(2) * * isPair([1, 2]) // => true * ``` * * @see {@link isTupleOfAtLeast} * @see {@link Tuple} * @stability stable * @category guards * @since 3.3.0 */ export declare const isTupleOf: { /** * Checks whether a readonly array has exactly `n` elements. * * **When to use** * * Use when you need a `Predicate` guard for exact tuple length that narrows * `ReadonlyArray` to `TupleOf`. * * **Details** * * This only checks length, not element types, and returns a refinement on the * array type. * * **Example** (Checking exact length) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isPair = Predicate.isTupleOf(2) * * isPair([1, 2]) // => true * ``` * * @see {@link isTupleOfAtLeast} * @see {@link Tuple} * @stability stable * @category guards * @since 3.3.0 */ (n: N): (self: ReadonlyArray) => self is TupleOf; /** * Checks whether a readonly array has exactly `n` elements. * * **When to use** * * Use when you need a `Predicate` guard for exact tuple length that narrows * `ReadonlyArray` to `TupleOf`. * * **Details** * * This only checks length, not element types, and returns a refinement on the * array type. * * **Example** (Checking exact length) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isPair = Predicate.isTupleOf(2) * * isPair([1, 2]) // => true * ``` * * @see {@link isTupleOfAtLeast} * @see {@link Tuple} * @stability stable * @category guards * @since 3.3.0 */ (self: ReadonlyArray, n: N): self is TupleOf; }; /** * Checks whether a readonly array has at least `n` elements. * * **When to use** * * Use when you need a `Predicate` guard for tuple-like minimum length that * narrows `ReadonlyArray` to `TupleOfAtLeast`. * * **Details** * * This only checks length, not element types, and returns a refinement on the * array type. * * **Example** (Checking minimum length) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasAtLeast2 = Predicate.isTupleOfAtLeast(2) * * hasAtLeast2([1, 2, 3]) // => true * ``` * * @see {@link isTupleOf} * @see {@link Tuple} * @stability stable * @category guards * @since 3.3.0 */ export declare const isTupleOfAtLeast: { /** * Checks whether a readonly array has at least `n` elements. * * **When to use** * * Use when you need a `Predicate` guard for tuple-like minimum length that * narrows `ReadonlyArray` to `TupleOfAtLeast`. * * **Details** * * This only checks length, not element types, and returns a refinement on the * array type. * * **Example** (Checking minimum length) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasAtLeast2 = Predicate.isTupleOfAtLeast(2) * * hasAtLeast2([1, 2, 3]) // => true * ``` * * @see {@link isTupleOf} * @see {@link Tuple} * @stability stable * @category guards * @since 3.3.0 */ (n: N): (self: ReadonlyArray) => self is TupleOfAtLeast; /** * Checks whether a readonly array has at least `n` elements. * * **When to use** * * Use when you need a `Predicate` guard for tuple-like minimum length that * narrows `ReadonlyArray` to `TupleOfAtLeast`. * * **Details** * * This only checks length, not element types, and returns a refinement on the * array type. * * **Example** (Checking minimum length) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasAtLeast2 = Predicate.isTupleOfAtLeast(2) * * hasAtLeast2([1, 2, 3]) // => true * ``` * * @see {@link isTupleOf} * @see {@link Tuple} * @stability stable * @category guards * @since 3.3.0 */ (self: ReadonlyArray, n: N): self is TupleOfAtLeast; }; /** * Checks whether a value is truthy. * * **When to use** * * Use when you want a predicate that mirrors JavaScript truthiness and filters * out falsy values like `0`, `""`, and `false`. * * **Details** * * This uses `!!input` and treats `0`, `""`, `false`, `null`, and `undefined` * as false. * * **Example** (Filtering truthy values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const values = [0, 1, "", "ok", false] * const truthy = values.filter(Predicate.isTruthy) // => [1, "ok"] * ``` * * @see {@link isNullish} * @see {@link isNotNullish} * @stability stable * @category predicates * @since 2.0.0 */ export declare function isTruthy(input: unknown): boolean; /** * Checks whether a value is a `Set`. * * **When to use** * * Use when you need a `Predicate` runtime guard for `Set` values. * * **Details** * * Uses `instanceof Set`. * * **Example** (Guarding a Set) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = new Set([1, 2]) * * if (Predicate.isSet(data)) { * data.size // => 2 * } * ``` * * @see {@link isMap} * @see {@link isIterable} * @stability stable * @category guards * @since 2.0.0 */ export declare function isSet(input: unknown): input is Set; /** * Checks whether a value is a `Map`. * * **When to use** * * Use when you need a `Predicate` runtime guard for `Map` values. * * **Details** * * Uses `instanceof Map`. * * **Example** (Guarding a Map) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = new Map([["a", 1]]) * * if (Predicate.isMap(data)) { * data.size // => 1 * } * ``` * * @see {@link isSet} * @see {@link isIterable} * @stability stable * @category guards * @since 2.0.0 */ export declare function isMap(input: unknown): input is Map; /** * Checks whether a value is a `string`. * * **When to use** * * Use when you need a `Predicate` guard to narrow an `unknown` value to a * string. * * **Details** * * Uses `typeof input === "string"`. * * **Example** (Guarding strings) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = "hi" * * if (Predicate.isString(data)) { * data.toUpperCase() // => "HI" * } * ``` * * @see {@link isNumber} * @see {@link isBoolean} * @see {@link Refinement} * @stability stable * @category guards * @since 2.0.0 */ export declare function isString(input: unknown): input is string; /** * Checks whether a value is a `number`. * * **When to use** * * Use when you need a `Predicate` guard to narrow an `unknown` value to a * number. * * **Details** * * Uses `typeof input === "number"` and does not exclude `NaN` or `Infinity`. * * **Example** (Guarding numbers) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = 42 * * if (Predicate.isNumber(data)) { * data + 1 // => 43 * } * ``` * * @see {@link isBigInt} * @see {@link isString} * @stability stable * @category guards * @since 2.0.0 */ export declare function isNumber(input: unknown): input is number; /** * Checks whether a value is a `boolean`. * * **When to use** * * Use when you need a `Predicate` guard to narrow an `unknown` value to a * boolean. * * **Details** * * Uses `typeof input === "boolean"`. * * **Example** (Guarding booleans) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = true * * if (Predicate.isBoolean(data)) { * data ? "yes" : "no" // => "yes" * } * ``` * * @see {@link isString} * @see {@link isNumber} * @stability stable * @category guards * @since 2.0.0 */ export declare function isBoolean(input: unknown): input is boolean; /** * Checks whether a value is a `bigint`. * * **When to use** * * Use when you need a `Predicate` guard to narrow an `unknown` value to a * bigint. * * **Details** * * Uses `typeof input === "bigint"`. * * **Example** (Guarding bigints) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = 1n * * if (Predicate.isBigInt(data)) { * data + 2n // => 3n * } * ``` * * @see {@link isNumber} * @stability stable * @category guards * @since 2.0.0 */ export declare function isBigInt(input: unknown): input is bigint; /** * Checks whether a value is a `symbol`. * * **When to use** * * Use when you need a `Predicate` guard to narrow an `unknown` value to a * symbol. * * **Details** * * Uses `typeof input === "symbol"`. * * **Example** (Guarding symbols) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = Symbol.for("id") * * if (Predicate.isSymbol(data)) { * data.description // => "id" * } * ``` * * @see {@link isPropertyKey} * @stability stable * @category guards * @since 2.0.0 */ export declare function isSymbol(input: unknown): input is symbol; /** * Checks whether a value is a valid `PropertyKey` (string, number, or symbol). * * **When to use** * * Use when you need a `Predicate` guard for unknown property keys before * indexing. * * **Details** * * Uses `isString`, `isNumber`, and `isSymbol`. * * **Example** (Guarding property keys) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const key: unknown = "name" * const obj: Record = { name: "Ada" } * * if (Predicate.isPropertyKey(key) && key in obj) { * obj[key] // => "Ada" * } * ``` * * @see {@link isString} * @see {@link isNumber} * @see {@link isSymbol} * @stability stable * @category guards * @since 4.0.0 */ export declare function isPropertyKey(u: unknown): u is PropertyKey; /** * Checks whether a value is a `function`. * * **When to use** * * Use when you need a `Predicate` guard to narrow an `unknown` value to a * callable function. * * **Details** * * Uses `typeof input === "function"`. * * **Example** (Guarding functions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = () => 1 * * if (Predicate.isFunction(data)) { * data() // => 1 * } * ``` * * @see {@link isObjectKeyword} * @stability stable * @category guards * @since 2.0.0 */ export declare function isFunction(input: unknown): input is Function; /** * Checks whether a value is `undefined`. * * **When to use** * * Use when you need a `Predicate` guard for values that are exactly * `undefined`. * * **Details** * * Uses `input === undefined`. * * **Example** (Guarding undefined values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = undefined * * Predicate.isUndefined(data) // => true * ``` * * @see {@link isNotUndefined} * @see {@link isNullish} * @stability stable * @category guards * @since 2.0.0 */ export declare function isUndefined(input: unknown): input is undefined; /** * Checks whether a value is not `undefined`. * * **When to use** * * Use when you need a `Predicate` refinement that filters out `undefined` * while preserving other falsy values. * * **Details** * * Returns a refinement that excludes `undefined`. * * **Example** (Filtering undefined values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const values = [1, undefined, 2] * const defined = values.filter(Predicate.isNotUndefined) // => [1, 2] * ``` * * @see {@link isUndefined} * @see {@link isNotNullish} * @stability stable * @category guards * @since 2.0.0 */ export declare function isNotUndefined(input: A): input is Exclude; /** * Checks whether a value is `null`. * * **When to use** * * Use when you need a `Predicate` guard for nullable values. * * **Details** * * Uses `input === null`. * * **Example** (Guarding null values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = null * * Predicate.isNull(data) // => true * ``` * * @see {@link isNotNull} * @see {@link isNullish} * @stability stable * @category guards * @since 2.0.0 */ export declare function isNull(input: unknown): input is null; /** * Checks whether a value is not `null`. * * **When to use** * * Use when you need a `Predicate` refinement that filters out `null` while * preserving other falsy values. * * **Details** * * Returns a refinement that excludes `null`. * * **Example** (Filtering null values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const values = [1, null, 2] * const nonNull = values.filter(Predicate.isNotNull) // => [1, 2] * ``` * * @see {@link isNull} * @see {@link isNotNullish} * @stability stable * @category guards * @since 2.0.0 */ export declare function isNotNull(input: A): input is Exclude; /** * Checks whether a value is `null` or `undefined`. * * **When to use** * * Use when you need a `Predicate` guard for nullish values. * * **Details** * * Uses `input === null || input === undefined`. * * **Example** (Guarding nullish values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const values = [0, null, "", undefined] * const nullish = values.filter(Predicate.isNullish) // => [null, undefined] * ``` * * @see {@link isNotNullish} * @see {@link isUndefined} * @see {@link isNull} * @stability stable * @category guards * @since 4.0.0 */ export declare function isNullish(input: A): input is A & (null | undefined); /** * Checks whether a value is not `null` and not `undefined`. * * **When to use** * * Use when you need a `Predicate` refinement that filters out nullish values * but keeps other falsy ones. * * **Details** * * Uses `input != null`. * * **Example** (Filtering non-nullish values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const values = [0, null, "", undefined] * const present = values.filter(Predicate.isNotNullish) // => [0, ""] * ``` * * @see {@link isNullish} * @see {@link isNotNull} * @see {@link isNotUndefined} * @stability stable * @category guards * @since 4.0.0 */ export declare function isNotNullish(input: A): input is NonNullable; /** * Type guard that always returns `false`. * * **When to use** * * Use when you need a `Predicate` that never accepts, e.g. in default branches. * * **Example** (Matching no values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * Predicate.isNever("anything") // => false * ``` * * @see {@link isUnknown} * @stability stable * @category guards * @since 2.0.0 */ export declare function isNever(_: unknown): _ is never; /** * Type guard that always returns `true`. * * **When to use** * * Use when you need a `Predicate` that always accepts, e.g. as a placeholder. * * **Example** (Matching every value) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * Predicate.isUnknown(123) // => true * ``` * * @see {@link isNever} * @stability stable * @category guards * @since 2.0.0 */ export declare function isUnknown(_: unknown): _ is unknown; /** * Checks whether a value is an object or an array (non-null object). * * **When to use** * * Use when you need a `Predicate` guard that accepts plain objects and arrays, * but not `null`. * * **Details** * * Uses `typeof input === "object" && input !== null` and includes arrays. * * **Example** (Checking objects or arrays) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * Predicate.isObjectOrArray([]) // => true * ``` * * @see {@link isObject} * @see {@link isObjectKeyword} * @stability stable * @category guards * @since 4.0.0 */ export declare function isObjectOrArray(input: unknown): input is { [x: PropertyKey]: unknown; } | Array; /** * Checks whether a value is a non-null object value that is not an array. * * **When to use** * * Use to narrow unknown input to a non-null, non-array object with a * `Predicate` guard. * * **Details** * * This is a structural runtime check using `typeof input === "object"`, so it * also accepts object instances such as `Date`, `Map`, class instances, and * typed arrays. It excludes `null` and arrays. * * **Example** (Guarding objects) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * Predicate.isObject({ a: 1 }) // => true * Predicate.isObject([1, 2]) // => false * ``` * * @see {@link isObjectOrArray} * @see {@link isReadonlyObject} * @stability stable * @category guards * @since 2.0.0 */ export declare function isObject(input: unknown): input is { [x: PropertyKey]: unknown; }; /** * Checks whether a value is a non-null, non-array object and narrows it to a * readonly indexable object type. * * **When to use** * * Use to narrow unknown input to a readonly view of a non-null, non-array * object with a `Predicate` guard. * * **Details** * * Readonly-ness is a TypeScript type-level view; it is not observable at * runtime. This delegates to `isObject`, so class instances and built-in object * instances are accepted. * * **Example** (Checking readonly objects) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = { a: 1 } * * Predicate.isReadonlyObject(data) // => true * ``` * * @see {@link isObject} * @stability stable * @category guards * @since 4.0.0 */ export declare function isReadonlyObject(input: unknown): input is { readonly [x: PropertyKey]: unknown; }; /** * Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions). * * **When to use** * * Use when you need a `Predicate` guard that accepts arrays and functions as * well as objects. * * **Details** * * Returns `true` for arrays and functions, and `false` for `null`. * * **Example** (Checking object keywords) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * Predicate.isObjectKeyword(() => 1) // => true * Predicate.isObjectKeyword(null) // => false * ``` * * @see {@link isObject} * @see {@link isObjectOrArray} * @stability stable * @category guards * @since 4.0.0 */ export declare function isObjectKeyword(input: unknown): input is object; /** * Checks whether a value has a given property key. * * **When to use** * * Use when you need a `Predicate` guard for property access on `unknown` * values with a simple structural object check. * * **Details** * * Uses the `in` operator and `isObjectKeyword`. This does not check property * value types. * * **Example** (Guarding object properties) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasName = Predicate.hasProperty("name") * const data: unknown = { name: "Ada" } * * if (hasName(data)) { * data.name // => "Ada" * } * ``` * * @see {@link isTagged} * @see {@link isObjectKeyword} * @stability stable * @category guards * @since 2.0.0 */ export declare const hasProperty: { /** * Checks whether a value has a given property key. * * **When to use** * * Use when you need a `Predicate` guard for property access on `unknown` * values with a simple structural object check. * * **Details** * * Uses the `in` operator and `isObjectKeyword`. This does not check property * value types. * * **Example** (Guarding object properties) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasName = Predicate.hasProperty("name") * const data: unknown = { name: "Ada" } * * if (hasName(data)) { * data.name // => "Ada" * } * ``` * * @see {@link isTagged} * @see {@link isObjectKeyword} * @stability stable * @category guards * @since 2.0.0 */

(property: P): (self: unknown) => self is { [K in P]: unknown; }; /** * Checks whether a value has a given property key. * * **When to use** * * Use when you need a `Predicate` guard for property access on `unknown` * values with a simple structural object check. * * **Details** * * Uses the `in` operator and `isObjectKeyword`. This does not check property * value types. * * **Example** (Guarding object properties) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasName = Predicate.hasProperty("name") * const data: unknown = { name: "Ada" } * * if (hasName(data)) { * data.name // => "Ada" * } * ``` * * @see {@link isTagged} * @see {@link isObjectKeyword} * @stability stable * @category guards * @since 2.0.0 */

(self: unknown, property: P): self is { [K in P]: unknown; }; }; /** * Checks whether a value has a `_tag` property equal to the given tag. * * **When to use** * * Use when you model tagged unions with a `_tag` field and want a quick * `Predicate` guard for tagged values. * * **Details** * * Uses `hasProperty` and strict equality on `_tag`. * * **Example** (Guarding tagged values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isOk = Predicate.isTagged("Ok") * * isOk({ _tag: "Ok", value: 1 }) // => true * ``` * * @see {@link hasProperty} * @stability stable * @category guards * @since 2.0.0 */ export declare const isTagged: { /** * Checks whether a value has a `_tag` property equal to the given tag. * * **When to use** * * Use when you model tagged unions with a `_tag` field and want a quick * `Predicate` guard for tagged values. * * **Details** * * Uses `hasProperty` and strict equality on `_tag`. * * **Example** (Guarding tagged values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isOk = Predicate.isTagged("Ok") * * isOk({ _tag: "Ok", value: 1 }) // => true * ``` * * @see {@link hasProperty} * @stability stable * @category guards * @since 2.0.0 */ (tag: K): (self: unknown) => self is { _tag: K; }; /** * Checks whether a value has a `_tag` property equal to the given tag. * * **When to use** * * Use when you model tagged unions with a `_tag` field and want a quick * `Predicate` guard for tagged values. * * **Details** * * Uses `hasProperty` and strict equality on `_tag`. * * **Example** (Guarding tagged values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isOk = Predicate.isTagged("Ok") * * isOk({ _tag: "Ok", value: 1 }) // => true * ``` * * @see {@link hasProperty} * @stability stable * @category guards * @since 2.0.0 */ (self: unknown, tag: K): self is { _tag: K; }; }; /** * Checks whether a value is an `Error`. * * **When to use** * * Use when you need a `Predicate` guard for errors caught from unknown sources. * * **Details** * * Uses `instanceof Error`. * * **Example** (Guarding errors) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = new Error("boom") * * Predicate.isError(data) // => true * ``` * * @see {@link isUnknown} * @stability stable * @category guards * @since 2.0.0 */ export declare function isError(input: unknown): input is Error; /** * Checks whether a value is a `Uint8Array`. * * **When to use** * * Use when you need a `Predicate` runtime guard for binary data. * * **Details** * * Uses `instanceof Uint8Array`. * * **Example** (Guarding Uint8Array values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = new Uint8Array([1, 2]) * * Predicate.isUint8Array(data) // => true * ``` * * @see {@link isIterable} * @see {@link isSet} * @stability stable * @category guards * @since 2.0.0 */ export declare function isUint8Array(input: unknown): input is Uint8Array; /** * Checks whether a value is a `Date`. * * **When to use** * * Use when you need a `Predicate` runtime guard for dates. * * **Details** * * Uses `instanceof Date`. * * **Example** (Guarding Date values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = new Date() * * Predicate.isDate(data) // => true * ``` * * @see {@link isRegExp} * @stability stable * @category guards * @since 2.0.0 */ export declare function isDate(input: unknown): input is Date; /** * Checks whether a value is iterable. * * **When to use** * * Use when you need a `Predicate` guard before iterating an unknown value. * * **Details** * * Accepts strings as iterable and uses `hasProperty` for `Symbol.iterator`. * * **Example** (Guarding iterables) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = [1, 2, 3] * * Predicate.isIterable(data) // => true * ``` * * @see {@link isSet} * @see {@link isMap} * @stability stable * @category guards * @since 2.0.0 */ export declare function isIterable(input: unknown): input is Iterable; /** * Checks whether a value is a `Promise`-like object with `then` and `catch`. * * **When to use** * * Use when you need a `Predicate` guard for promise instances across realms. * * **Details** * * Performs a structural check for `then` and `catch` functions. * * **Example** (Guarding promises) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = Promise.resolve(1) * * Predicate.isPromise(data) // => true * ``` * * @see {@link isPromiseLike} * @stability stable * @category guards * @since 2.0.0 */ export declare function isPromise(input: unknown): input is Promise; /** * Checks whether a value is `PromiseLike` (has a `then` method). * * **When to use** * * Use when you need a `Predicate` guard for promise-like values with a * callable `then` method. * * **Details** * * Performs a structural check for a callable `then`. * * **Example** (Guarding promise-like values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = { then: () => {} } * * Predicate.isPromiseLike(data) // => true * ``` * * @see {@link isPromise} * @stability stable * @category guards * @since 2.0.0 */ export declare function isPromiseLike(input: unknown): input is PromiseLike; /** * Checks whether a value is a `RegExp`. * * **When to use** * * Use when you need a `Predicate` runtime guard for regular expressions. * * **Details** * * Uses `instanceof RegExp`. * * **Example** (Guarding RegExp values) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const data: unknown = /abc/ * * Predicate.isRegExp(data) // => true * ``` * * @see {@link isDate} * @stability stable * @category guards * @since 3.9.0 */ export declare function isRegExp(input: unknown): input is RegExp; /** * Composes two predicates or refinements into one. * * **When to use** * * Use when you want to compose two `Predicate` checks in sequence, especially * when chaining refinements for progressive narrowing. * * **Details** * * For refinements, the output type is narrowed by both checks. Evaluation * short-circuits on the first `false`. * * **Example** (Composing refinements) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isNumber: Predicate.Refinement = (u): u is number => typeof u === "number" * const isInteger: Predicate.Refinement = (n): n is number => Number.isInteger(n) * * const isIntegerNumber = Predicate.compose(isNumber, isInteger) * * isIntegerNumber(1) // => true * ``` * * @see {@link and} * @see {@link Refinement} * @stability stable * @category combinators * @since 2.0.0 */ export declare const compose: { /** * Composes two predicates or refinements into one. * * **When to use** * * Use when you want to compose two `Predicate` checks in sequence, especially * when chaining refinements for progressive narrowing. * * **Details** * * For refinements, the output type is narrowed by both checks. Evaluation * short-circuits on the first `false`. * * **Example** (Composing refinements) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isNumber: Predicate.Refinement = (u): u is number => typeof u === "number" * const isInteger: Predicate.Refinement = (n): n is number => Number.isInteger(n) * * const isIntegerNumber = Predicate.compose(isNumber, isInteger) * * isIntegerNumber(1) // => true * ``` * * @see {@link and} * @see {@link Refinement} * @stability stable * @category combinators * @since 2.0.0 */ (bc: Refinement): (ab: Refinement) => Refinement; /** * Composes two predicates or refinements into one. * * **When to use** * * Use when you want to compose two `Predicate` checks in sequence, especially * when chaining refinements for progressive narrowing. * * **Details** * * For refinements, the output type is narrowed by both checks. Evaluation * short-circuits on the first `false`. * * **Example** (Composing refinements) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isNumber: Predicate.Refinement = (u): u is number => typeof u === "number" * const isInteger: Predicate.Refinement = (n): n is number => Number.isInteger(n) * * const isIntegerNumber = Predicate.compose(isNumber, isInteger) * * isIntegerNumber(1) // => true * ``` * * @see {@link and} * @see {@link Refinement} * @stability stable * @category combinators * @since 2.0.0 */ (bc: Predicate>): (ab: Refinement) => Refinement; /** * Composes two predicates or refinements into one. * * **When to use** * * Use when you want to compose two `Predicate` checks in sequence, especially * when chaining refinements for progressive narrowing. * * **Details** * * For refinements, the output type is narrowed by both checks. Evaluation * short-circuits on the first `false`. * * **Example** (Composing refinements) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isNumber: Predicate.Refinement = (u): u is number => typeof u === "number" * const isInteger: Predicate.Refinement = (n): n is number => Number.isInteger(n) * * const isIntegerNumber = Predicate.compose(isNumber, isInteger) * * isIntegerNumber(1) // => true * ``` * * @see {@link and} * @see {@link Refinement} * @stability stable * @category combinators * @since 2.0.0 */ (ab: Refinement, bc: Refinement): Refinement; /** * Composes two predicates or refinements into one. * * **When to use** * * Use when you want to compose two `Predicate` checks in sequence, especially * when chaining refinements for progressive narrowing. * * **Details** * * For refinements, the output type is narrowed by both checks. Evaluation * short-circuits on the first `false`. * * **Example** (Composing refinements) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isNumber: Predicate.Refinement = (u): u is number => typeof u === "number" * const isInteger: Predicate.Refinement = (n): n is number => Number.isInteger(n) * * const isIntegerNumber = Predicate.compose(isNumber, isInteger) * * isIntegerNumber(1) // => true * ``` * * @see {@link and} * @see {@link Refinement} * @stability stable * @category combinators * @since 2.0.0 */ (ab: Refinement, bc: Predicate>): Refinement; }; /** * Creates a predicate for tuples by applying predicates to each element. * * **When to use** * * Use when you want to validate tuple positions independently by lifting * element predicates into a tuple predicate. * * **Details** * * Returns a refinement if any element predicate is a refinement. Evaluation * stops at the first failing element. * * **Example** (Checking tuples) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const tupleCheck = Predicate.Tuple([(n: number) => n > 0, Predicate.isString]) * * tupleCheck([1, "ok"]) // => true * ``` * * @see {@link Struct} * @see {@link isTupleOf} * @stability stable * @category combinators * @since 4.0.0 */ export declare function Tuple>(elements: T): [Extract] extends [never] ? Predicate<{ readonly [I in keyof T]: Predicate.In; }> : Refinement<{ readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.In : Predicate.In; }, { readonly [I in keyof T]: T[I] extends Refinement.Any ? Refinement.Out : Predicate.In; }>; /** * Creates a predicate for objects by applying predicates to named properties. * * **When to use** * * Use when you want to validate a record shape at runtime by lifting property * predicates into an object predicate. * * **Details** * * Returns a refinement if any field predicate is a refinement. Only the * specified keys are checked, and extra keys are ignored. * * **Example** (Checking structs) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const userCheck = Predicate.Struct({ * id: Predicate.isNumber, * name: Predicate.isString * }) * * userCheck({ id: 1, name: "Ada" }) // => true * ``` * * @see {@link Tuple} * @see {@link hasProperty} * @stability stable * @category combinators * @since 4.0.0 */ export declare function Struct>(fields: R): [Extract] extends [never] ? Predicate<{ readonly [K in keyof R]: Predicate.In; }> : Refinement<{ readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.In : Predicate.In; }, { readonly [K in keyof R]: R[K] extends Refinement.Any ? Refinement.Out : Predicate.In; }>; /** * Negates a predicate. * * **When to use** * * Use when you want the inverse of an existing predicate. * * **Details** * * Returns a new predicate that flips the boolean result. * * **Example** (Negating a predicate) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isNotString = Predicate.not(Predicate.isString) * * isNotString(1) // => true * ``` * * @see {@link and} * @see {@link or} * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ export declare function not(self: Predicate): Predicate; /** * Creates a predicate that returns `true` if either predicate is `true`. * * **When to use** * * Use when you want to combine `Predicate`s with OR, accepting values that * satisfy at least one condition, including refinements that narrow to a union. * * **Details** * * Evaluation short-circuits on the first `true`. For refinements, the output * type is a union. * * **Example** (Checking either condition) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber) * * isStringOrNumber("a") // => true * ``` * * @see {@link and} * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ export declare const or: { /** * Creates a predicate that returns `true` if either predicate is `true`. * * **When to use** * * Use when you want to combine `Predicate`s with OR, accepting values that * satisfy at least one condition, including refinements that narrow to a union. * * **Details** * * Evaluation short-circuits on the first `true`. For refinements, the output * type is a union. * * **Example** (Checking either condition) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber) * * isStringOrNumber("a") // => true * ``` * * @see {@link and} * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ (that: Refinement): (self: Refinement) => Refinement; /** * Creates a predicate that returns `true` if either predicate is `true`. * * **When to use** * * Use when you want to combine `Predicate`s with OR, accepting values that * satisfy at least one condition, including refinements that narrow to a union. * * **Details** * * Evaluation short-circuits on the first `true`. For refinements, the output * type is a union. * * **Example** (Checking either condition) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber) * * isStringOrNumber("a") // => true * ``` * * @see {@link and} * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ (self: Refinement, that: Refinement): Refinement; /** * Creates a predicate that returns `true` if either predicate is `true`. * * **When to use** * * Use when you want to combine `Predicate`s with OR, accepting values that * satisfy at least one condition, including refinements that narrow to a union. * * **Details** * * Evaluation short-circuits on the first `true`. For refinements, the output * type is a union. * * **Example** (Checking either condition) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber) * * isStringOrNumber("a") // => true * ``` * * @see {@link and} * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ (that: Predicate): (self: Predicate) => Predicate; /** * Creates a predicate that returns `true` if either predicate is `true`. * * **When to use** * * Use when you want to combine `Predicate`s with OR, accepting values that * satisfy at least one condition, including refinements that narrow to a union. * * **Details** * * Evaluation short-circuits on the first `true`. For refinements, the output * type is a union. * * **Example** (Checking either condition) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber) * * isStringOrNumber("a") // => true * ``` * * @see {@link and} * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ (self: Predicate, that: Predicate): Predicate; }; /** * Creates a predicate that returns `true` only if both predicates are `true`. * * **When to use** * * Use when you want to combine `Predicate`s with AND, accepting values that * satisfy multiple conditions, including refinements that narrow to an * intersection. * * **Details** * * Evaluation short-circuits on the first `false`. For refinements, the output * type is an intersection. * * **Example** (Checking both conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasAAndB = Predicate.and( * Predicate.hasProperty("a"), * Predicate.hasProperty("b") * ) * * const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`) * if (hasAAndB(input)) { * // input has both properties at this point * const a = input.a * const b = input.b * * const values = [a, b] // => [1, "ok"] * } * ``` * * @see {@link or} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ export declare const and: { /** * Creates a predicate that returns `true` only if both predicates are `true`. * * **When to use** * * Use when you want to combine `Predicate`s with AND, accepting values that * satisfy multiple conditions, including refinements that narrow to an * intersection. * * **Details** * * Evaluation short-circuits on the first `false`. For refinements, the output * type is an intersection. * * **Example** (Checking both conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasAAndB = Predicate.and( * Predicate.hasProperty("a"), * Predicate.hasProperty("b") * ) * * const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`) * if (hasAAndB(input)) { * // input has both properties at this point * const a = input.a * const b = input.b * * const values = [a, b] // => [1, "ok"] * } * ``` * * @see {@link or} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (that: Refinement): (self: Refinement) => Refinement; /** * Creates a predicate that returns `true` only if both predicates are `true`. * * **When to use** * * Use when you want to combine `Predicate`s with AND, accepting values that * satisfy multiple conditions, including refinements that narrow to an * intersection. * * **Details** * * Evaluation short-circuits on the first `false`. For refinements, the output * type is an intersection. * * **Example** (Checking both conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasAAndB = Predicate.and( * Predicate.hasProperty("a"), * Predicate.hasProperty("b") * ) * * const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`) * if (hasAAndB(input)) { * // input has both properties at this point * const a = input.a * const b = input.b * * const values = [a, b] // => [1, "ok"] * } * ``` * * @see {@link or} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (self: Refinement, that: Refinement): Refinement; /** * Creates a predicate that returns `true` only if both predicates are `true`. * * **When to use** * * Use when you want to combine `Predicate`s with AND, accepting values that * satisfy multiple conditions, including refinements that narrow to an * intersection. * * **Details** * * Evaluation short-circuits on the first `false`. For refinements, the output * type is an intersection. * * **Example** (Checking both conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasAAndB = Predicate.and( * Predicate.hasProperty("a"), * Predicate.hasProperty("b") * ) * * const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`) * if (hasAAndB(input)) { * // input has both properties at this point * const a = input.a * const b = input.b * * const values = [a, b] // => [1, "ok"] * } * ``` * * @see {@link or} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (that: Predicate): (self: Predicate) => Predicate; /** * Creates a predicate that returns `true` only if both predicates are `true`. * * **When to use** * * Use when you want to combine `Predicate`s with AND, accepting values that * satisfy multiple conditions, including refinements that narrow to an * intersection. * * **Details** * * Evaluation short-circuits on the first `false`. For refinements, the output * type is an intersection. * * **Example** (Checking both conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const hasAAndB = Predicate.and( * Predicate.hasProperty("a"), * Predicate.hasProperty("b") * ) * * const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`) * if (hasAAndB(input)) { * // input has both properties at this point * const a = input.a * const b = input.b * * const values = [a, b] // => [1, "ok"] * } * ``` * * @see {@link or} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (self: Predicate, that: Predicate): Predicate; }; /** * Creates a predicate that returns `true` if exactly one predicate is `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with exclusive-or semantics. * * **Details** * * Returns `true` when results differ. * * **Example** (Checking exclusive-or conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isEven = (n: number) => n % 2 === 0 * const isPositive = (n: number) => n > 0 * const either = Predicate.xor(isEven, isPositive) * * either(-2) // => true * ``` * * @see {@link or} * @see {@link and} * @stability stable * @category combinators * @since 2.0.0 */ export declare const xor: { /** * Creates a predicate that returns `true` if exactly one predicate is `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with exclusive-or semantics. * * **Details** * * Returns `true` when results differ. * * **Example** (Checking exclusive-or conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isEven = (n: number) => n % 2 === 0 * const isPositive = (n: number) => n > 0 * const either = Predicate.xor(isEven, isPositive) * * either(-2) // => true * ``` * * @see {@link or} * @see {@link and} * @stability stable * @category combinators * @since 2.0.0 */ (that: Predicate): (self: Predicate) => Predicate; /** * Creates a predicate that returns `true` if exactly one predicate is `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with exclusive-or semantics. * * **Details** * * Returns `true` when results differ. * * **Example** (Checking exclusive-or conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isEven = (n: number) => n % 2 === 0 * const isPositive = (n: number) => n > 0 * const either = Predicate.xor(isEven, isPositive) * * either(-2) // => true * ``` * * @see {@link or} * @see {@link and} * @stability stable * @category combinators * @since 2.0.0 */ (self: Predicate, that: Predicate): Predicate; }; /** * Creates a predicate that returns `true` when both predicates agree. * * **When to use** * * Use when you want to check equivalence of two `Predicate`s. * * **Details** * * Returns `true` when both results are equal. * * **Example** (Defining equivalence) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isEven = (n: number) => n % 2 === 0 * const same = Predicate.eqv(isEven, isEven) * * same(3) // => true * ``` * * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ export declare const eqv: { /** * Creates a predicate that returns `true` when both predicates agree. * * **When to use** * * Use when you want to check equivalence of two `Predicate`s. * * **Details** * * Returns `true` when both results are equal. * * **Example** (Defining equivalence) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isEven = (n: number) => n % 2 === 0 * const same = Predicate.eqv(isEven, isEven) * * same(3) // => true * ``` * * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ (that: Predicate): (self: Predicate) => Predicate; /** * Creates a predicate that returns `true` when both predicates agree. * * **When to use** * * Use when you want to check equivalence of two `Predicate`s. * * **Details** * * Returns `true` when both results are equal. * * **Example** (Defining equivalence) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isEven = (n: number) => n % 2 === 0 * const same = Predicate.eqv(isEven, isEven) * * same(3) // => true * ``` * * @see {@link xor} * @stability stable * @category combinators * @since 2.0.0 */ (self: Predicate, that: Predicate): Predicate; }; /** * Creates a predicate representing logical implication: if `antecedent`, then `consequent`. * * **When to use** * * Use when you need to encode logical implication between `Predicate` rules, * where one rule only applies when a precondition holds. * * **Details** * * Models constraints like "if A then B" and returns `true` when the antecedent * is `false`. * * **Example** (Checking implication) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isAdult = (age: number) => age >= 18 * const canVote = (age: number) => age >= 18 * const implies = Predicate.implies(isAdult, canVote) * * implies(16) // => true * ``` * * @see {@link and} * @see {@link or} * @stability stable * @category combinators * @since 2.0.0 */ export declare const implies: { /** * Creates a predicate representing logical implication: if `antecedent`, then `consequent`. * * **When to use** * * Use when you need to encode logical implication between `Predicate` rules, * where one rule only applies when a precondition holds. * * **Details** * * Models constraints like "if A then B" and returns `true` when the antecedent * is `false`. * * **Example** (Checking implication) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isAdult = (age: number) => age >= 18 * const canVote = (age: number) => age >= 18 * const implies = Predicate.implies(isAdult, canVote) * * implies(16) // => true * ``` * * @see {@link and} * @see {@link or} * @stability stable * @category combinators * @since 2.0.0 */ (consequent: Predicate): (antecedent: Predicate) => Predicate; /** * Creates a predicate representing logical implication: if `antecedent`, then `consequent`. * * **When to use** * * Use when you need to encode logical implication between `Predicate` rules, * where one rule only applies when a precondition holds. * * **Details** * * Models constraints like "if A then B" and returns `true` when the antecedent * is `false`. * * **Example** (Checking implication) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const isAdult = (age: number) => age >= 18 * const canVote = (age: number) => age >= 18 * const implies = Predicate.implies(isAdult, canVote) * * implies(16) // => true * ``` * * @see {@link and} * @see {@link or} * @stability stable * @category combinators * @since 2.0.0 */ (antecedent: Predicate, consequent: Predicate): Predicate; }; /** * Creates a predicate that returns `true` when neither predicate is `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with logical NOR semantics. * * **Details** * * Returns the negation of `or`. * * **Example** (Checking NOR conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const neither = Predicate.nor(Predicate.isString, Predicate.isNumber) * * neither(true) // => true * ``` * * @see {@link or} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ export declare const nor: { /** * Creates a predicate that returns `true` when neither predicate is `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with logical NOR semantics. * * **Details** * * Returns the negation of `or`. * * **Example** (Checking NOR conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const neither = Predicate.nor(Predicate.isString, Predicate.isNumber) * * neither(true) // => true * ``` * * @see {@link or} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (that: Predicate): (self: Predicate) => Predicate; /** * Creates a predicate that returns `true` when neither predicate is `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with logical NOR semantics. * * **Details** * * Returns the negation of `or`. * * **Example** (Checking NOR conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const neither = Predicate.nor(Predicate.isString, Predicate.isNumber) * * neither(true) // => true * ``` * * @see {@link or} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (self: Predicate, that: Predicate): Predicate; }; /** * Creates a predicate that returns `true` unless both predicates are `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with logical NAND semantics. * * **Details** * * Returns the negation of `and`. * * **Example** (Checking NAND conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber) * * notBoth("a") // => true * ``` * * @see {@link and} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ export declare const nand: { /** * Creates a predicate that returns `true` unless both predicates are `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with logical NAND semantics. * * **Details** * * Returns the negation of `and`. * * **Example** (Checking NAND conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber) * * notBoth("a") // => true * ``` * * @see {@link and} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (that: Predicate): (self: Predicate) => Predicate; /** * Creates a predicate that returns `true` unless both predicates are `true`. * * **When to use** * * Use when you want to combine two `Predicate`s with logical NAND semantics. * * **Details** * * Returns the negation of `and`. * * **Example** (Checking NAND conditions) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber) * * notBoth("a") // => true * ``` * * @see {@link and} * @see {@link not} * @stability stable * @category combinators * @since 2.0.0 */ (self: Predicate, that: Predicate): Predicate; }; /** * Creates a predicate that returns `true` if all predicates in the collection return `true`. * * **When to use** * * Use when you have a dynamic list of predicates to apply. * * **Details** * * Evaluation short-circuits on the first `false`. The collection is iterated * each time the predicate is called. * * **Example** (Checking all predicates) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const allChecks = Predicate.every([Predicate.isNumber, (n: number) => n > 0]) * * allChecks(2) // => true * ``` * * @see {@link some} * @see {@link and} * @stability stable * @category combining * @since 2.0.0 */ export declare function every(collection: Iterable>): Predicate; /** * Creates a predicate that returns `true` if any predicate in the collection returns `true`. * * **When to use** * * Use when you have a dynamic list of predicates and only need one to pass. * * **Details** * * Evaluation short-circuits on the first `true`. The collection is iterated * each time the predicate is called. * * **Example** (Checking any predicate) * * ```ts import.meta.vitest * import { Predicate } from "effect" * * const anyCheck = Predicate.some([Predicate.isString, Predicate.isNumber]) * * anyCheck("ok") // => true * ``` * * @see {@link every} * @see {@link or} * @stability stable * @category combining * @since 2.0.0 */ export declare function some(collection: Iterable>): Predicate; //# sourceMappingURL=Predicate.d.ts.map