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

Function TaggedUnion

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

Source from the content-addressed store, hash-verified

6393 * @since 4.0.0
6394 */
6395export function TaggedUnion<const CasesByTag extends Record<string, Struct.Fields>>(
6396 casesByTag: CasesByTag
6397): TaggedUnion<{ readonly [K in keyof CasesByTag & string]: TaggedStruct<K, CasesByTag[K]> }> {
6398 const cases: any = {}
6399 const members: any = []
6400 for (const key of Object.keys(casesByTag)) {
6401 const member = TaggedStruct(key, casesByTag[key])
6402 InternalRecord.assignProperty(cases, key, member)
6403 members.push(member)
6404 }
6405 const union = Union(members)
6406 const { guards, isAnyOf, match } = toTaggedUnion("_tag")(union)
6407 return make(union.ast, { cases, isAnyOf, guards, match })
6408}
6409
6410/**
6411 * Type-level representation returned by {@link Opaque}.

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected