<A>(u: A): u is A & {}Matches any defined (non-null and non-undefined) value.
When to use
Use to exclude only null and undefined from a match branch.
Details
This predicate matches values that are neither null nor undefined,
effectively filtering out nullish values while preserving all other types.
Example (Matching defined values)
import { Match } from "effect"
const processValue = Match.type<string | number | null | undefined>()
.pipe(
Match.when(Match.defined, (value) => `Defined value: ${value}`),
Match.orElse(() => "Value is null or undefined")
)
console.log(processValue("hello"))
// Output: "Defined value: hello"
console.log(processValue(42))
// Output: "Defined value: 42"
console.log(processValue(0))
// Output: "Defined value: 0"
console.log(processValue(""))
// Output: "Defined value: "
console.log(processValue(null))
// Output: "Value is null or undefined"
console.log(processValue(undefined))
// Output: "Value is null or undefined"predicatesany
Source effect/Match.ts:14241 lines
export const const defined: <A>(u: A) => u is A & {}Matches any defined (non-null and non-undefined) value.
When to use
Use to exclude only null and undefined from a match branch.
Details
This predicate matches values that are neither null nor undefined,
effectively filtering out nullish values while preserving all other types.
Example (Matching defined values)
import { Match } from "effect"
const processValue = Match.type<string | number | null | undefined>()
.pipe(
Match.when(Match.defined, (value) => `Defined value: ${value}`),
Match.orElse(() => "Value is null or undefined")
)
console.log(processValue("hello"))
// Output: "Defined value: hello"
console.log(processValue(42))
// Output: "Defined value: 42"
console.log(processValue(0))
// Output: "Defined value: 0"
console.log(processValue(""))
// Output: "Defined value: "
console.log(processValue(null))
// Output: "Value is null or undefined"
console.log(processValue(undefined))
// Output: "Value is null or undefined"
defined: <function (type parameter) A in <A>(u: A): u is A & {}A>(u: Au: function (type parameter) A in <A>(u: A): u is A & {}A) => u: Au is function (type parameter) A in <A>(u: A): u is A & {}A & {} = import internalinternal.const defined: <A>(u: A) => u is A & {}defined