(input: unknown): Result.Result<boolean, unknown>A predefined filter that only passes through boolean values.
When to use
Use when accepting an unknown input only if it is already a boolean and you
want a Filter result rather than a plain predicate result.
Details
Implemented with fromPredicate(Predicate.isBoolean), so true and false
succeed and non-booleans fail with the original input.
export const const boolean: Filter<unknown, boolean>A predefined filter that only passes through boolean values.
When to use
Use when accepting an unknown input only if it is already a boolean and you
want a Filter result rather than a plain predicate result.
Details
Implemented with fromPredicate(Predicate.isBoolean), so true and false
succeed and non-booleans fail with the original input.
boolean: 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<unknown, boolean> = const fromPredicate: {
<A, B extends A>(
refinement: Predicate.Refinement<A, B>
): Filter<
A,
B,
EqualsWith<A, B, A, Exclude<A, B>>
>
<A>(
predicate: Predicate.Predicate<A>
): Filter<A>
}
fromPredicate(import PredicatePredicate.function isBoolean(
input: unknown
): input is boolean
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)
import { Predicate } from "effect"
const data: unknown = true
if (Predicate.isBoolean(data)) {
console.log(data ? "yes" : "no")
}
isBoolean)