(a: unknown): a is booleanMatches values of type boolean.
When to use
Use to match primitive boolean values.
Details
This predicate refines unknown values to booleans, allowing pattern matching
on boolean types. It only matches the primitive boolean values true and false.
Example (Matching boolean values)
import { Match } from "effect"
const describeTruthiness = Match.type<unknown>().pipe(
Match.when(
Match.boolean,
(bool) => bool ? "Definitely true" : "Definitely false"
),
Match.when(0, () => "Falsy number"),
Match.when("", () => "Empty string"),
Match.when(Match.null, () => "Null value"),
Match.orElse(() => "Some other truthy value")
)
console.log(describeTruthiness(true)) // "Definitely true"
console.log(describeTruthiness(false)) // "Definitely false"
console.log(describeTruthiness(0)) // "Falsy number"
console.log(describeTruthiness(1)) // "Some other truthy value"export const const boolean: Predicate.Refinement<
unknown,
boolean
>
Matches values of type boolean.
When to use
Use to match primitive boolean values.
Details
This predicate refines unknown values to booleans, allowing pattern matching
on boolean types. It only matches the primitive boolean values true and false.
Example (Matching boolean values)
import { Match } from "effect"
const describeTruthiness = Match.type<unknown>().pipe(
Match.when(
Match.boolean,
(bool) => bool ? "Definitely true" : "Definitely false"
),
Match.when(0, () => "Falsy number"),
Match.when("", () => "Empty string"),
Match.when(Match.null, () => "Null value"),
Match.orElse(() => "Some other truthy value")
)
console.log(describeTruthiness(true)) // "Definitely true"
console.log(describeTruthiness(false)) // "Definitely false"
console.log(describeTruthiness(0)) // "Falsy number"
console.log(describeTruthiness(1)) // "Some other truthy value"
boolean: 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<unknown, boolean> = 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