Hyperlinkv0.8.0-beta.28

Predicate

Predicate.isTaggedconsteffect/Predicate.ts:1166
<K extends string>(tag: K): (self: unknown) => self is { _tag: K }
<K extends string>(self: unknown, tag: K): self is { _tag: K }

Checks whether a value has a _tag property equal to the given tag.

When to use

Use when you model tagged unions with a _tag field and want a quick Predicate guard for tagged values.

Details

Uses hasProperty and strict equality on _tag.

Example (Guarding tagged values)

import { Predicate } from "effect"

const isOk = Predicate.isTagged("Ok")

console.log(isOk({ _tag: "Ok", value: 1 }))
export const isTagged: {
  <K extends string>(tag: K): (self: unknown) => self is { _tag: K }
  <K extends string>(self: unknown, tag: K): self is { _tag: K }
} = dual(
  2,
  <K extends string>(self: unknown, tag: K): self is { _tag: K } => hasProperty(self, "_tag") && self["_tag"] === tag
)
Referenced by 6 symbols