<A, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>Converts a Filter into a predicate function.
When to use
Use to reuse a Filter with APIs that accept only boolean predicates when
the pass and fail payloads are not needed.
export const const toPredicate: <A, Pass, Fail>(
self: Filter<A, Pass, Fail>
) => Predicate.Predicate<A>
Converts a Filter into a predicate function.
When to use
Use to reuse a Filter with APIs that accept only boolean predicates when
the pass and fail payloads are not needed.
toPredicate = <function (type parameter) A in <A, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>A, function (type parameter) Pass in <A, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>Pass, function (type parameter) Fail in <A, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>Fail>(
self: Filter<A, Pass, Fail>self: interface Filter<in Input, out Pass = Input, out Fail = Input>Represents a filter function that can transform inputs to outputs or filter them out.
Details
A filter takes an input value and either returns a boxed pass value or the
special fail type to indicate the value should be filtered out.
Example (Defining a positive number filter)
import { Filter, Result } from "effect"
// A filter that only passes positive numbers
const positiveFilter: Filter.Filter<number> = (n) => n > 0 ? Result.succeed(n) : Result.fail(n)
console.log(positiveFilter(5)) // Result.succeed(5)
console.log(positiveFilter(-3)) // Result.fail(-3)
Filter<function (type parameter) A in <A, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>A, function (type parameter) Pass in <A, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>Pass, function (type parameter) Fail in <A, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>Fail>
): 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, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>A> =>
(input: Ainput: function (type parameter) A in <A, Pass, Fail>(self: Filter<A, Pass, Fail>): Predicate.Predicate<A>A) => !import ResultResult.const isFailure: <A, E>(
self: Result<A, E>
) => self is Failure<A, E>
Checks whether a Result is a Failure.
When to use
Use to narrow a known Result to the Failure variant.
Details
- Acts as a TypeScript type guard, narrowing to
Failure<A, E>
- After narrowing, you can access
.failure to read the error value
Example (Narrowing to failure)
import { Result } from "effect"
const result = Result.fail("oops")
if (Result.isFailure(result)) {
console.log(result.failure)
// Output: "oops"
}
isFailure(self: Filter<A, Pass, Fail>self(input: Ainput))