(a: unknown): a is symbolMatches values of type symbol.
Details
This predicate refines unknown values to symbols, allowing pattern matching on symbol types. Symbols are unique identifiers that are often used as object keys or for creating private properties.
Example (Matching symbol values)
import { Match } from "effect"
const mySymbol = Symbol("my-symbol")
const globalSymbol = Symbol.for("global-symbol")
const handleSymbol = Match.type<unknown>().pipe(
Match.when(Match.symbol, (sym) => {
const description = sym.description
if (description) {
return `Symbol with description: ${description}`
}
return "Symbol without description"
}),
Match.orElse(() => "Not a symbol")
)
console.log(handleSymbol(mySymbol)) // "Symbol with description: my-symbol"
console.log(handleSymbol(Symbol())) // "Symbol without description"
console.log(handleSymbol("string")) // "Not a symbol"export const const symbol: Predicate.Refinement<
unknown,
symbol
>
Matches values of type symbol.
Details
This predicate refines unknown values to symbols, allowing pattern matching
on symbol types. Symbols are unique identifiers that are often used as
object keys or for creating private properties.
Example (Matching symbol values)
import { Match } from "effect"
const mySymbol = Symbol("my-symbol")
const globalSymbol = Symbol.for("global-symbol")
const handleSymbol = Match.type<unknown>().pipe(
Match.when(Match.symbol, (sym) => {
const description = sym.description
if (description) {
return `Symbol with description: ${description}`
}
return "Symbol without description"
}),
Match.orElse(() => "Not a symbol")
)
console.log(handleSymbol(mySymbol)) // "Symbol with description: my-symbol"
console.log(handleSymbol(Symbol())) // "Symbol without description"
console.log(handleSymbol("string")) // "Not a symbol"
symbol: 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, symbol> = import PredicatePredicate.function isSymbol(
input: unknown
): input is symbol
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)
import { Predicate } from "effect"
const data: unknown = Symbol.for("id")
if (Predicate.isSymbol(data)) {
console.log(data.description)
}
isSymbol