Hyperlinkv0.8.0-beta.28

Match

Match.definedconsteffect/Match.ts:1424
<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 defined: <A>(u: A) => u is A & {} = internal.defined