MCPcopy Create free account
hub / github.com/Effect-TS/effect / TaggedUnion

Function TaggedUnion

packages/effect/src/Schema.ts:6637–6650  ·  view source on GitHub ↗
(
  casesByTag: CasesByTag
)

Source from the content-addressed store, hash-verified

6635 * @since 4.0.0
6636 */
6637export function TaggedUnion<const CasesByTag extends Record<string, Struct.Fields>>(
6638 casesByTag: CasesByTag
6639): TaggedUnion<{ readonly [K in keyof CasesByTag & string]: TaggedStruct<K, CasesByTag[K]> }> {
6640 const cases: any = {}
6641 const members: any = []
6642 for (const key of Object.keys(casesByTag)) {
6643 const member = TaggedStruct(key, casesByTag[key])
6644 InternalRecord.assignProperty(cases, key, member)
6645 members.push(member)
6646 }
6647 const union = Union(members)
6648 const { tag, guards, isAnyOf, match, matchOrElse } = toTaggedUnion("_tag")(union)
6649 return make(union.ast, { tag, cases, isAnyOf, guards, match, matchOrElse })
6650}
6651/**
6652 * Type-level representation returned by {@link Opaque}.
6653 *

Callers

nothing calls this directly

Calls 6

TaggedStructFunction · 0.85
toTaggedUnionFunction · 0.85
keysMethod · 0.80
UnionFunction · 0.70
makeFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected