MCPcopy
hub / github.com/Effect-TS/effect / EitherFromUnion

Function EitherFromUnion

packages/effect/src/Schema.ts:7532–7564  ·  view source on GitHub ↗
({ left, right }: {
  readonly left: Left
  readonly right: Right
})

Source from the content-addressed store, hash-verified

7530 * @since 3.10.0
7531 */
7532export const EitherFromUnion = <Right extends Schema.All, Left extends Schema.All>({ left, right }: {
7533 readonly left: Left
7534 readonly right: Right
7535}): EitherFromUnion<Right, Left> => {
7536 const right_ = asSchema(right)
7537 const left_ = asSchema(left)
7538 const toright = typeSchema(right_)
7539 const toleft = typeSchema(left_)
7540 const fromRight = transform(right_, rightEncoded(toright), {
7541 strict: true,
7542 decode: (i) => makeRightEncoded(i),
7543 encode: (a) => a.right
7544 })
7545 const fromLeft = transform(left_, leftEncoded(toleft), {
7546 strict: true,
7547 decode: (i) => makeLeftEncoded(i),
7548 encode: (a) => a.left
7549 })
7550 const out = transform(
7551 Union(fromRight, fromLeft),
7552 EitherFromSelf({ left: toleft, right: toright }),
7553 {
7554 strict: true,
7555 decode: (i) => i._tag === "Left" ? either_.left(i.left) : either_.right(i.right),
7556 encode: (a) =>
7557 either_.match(a, {
7558 onLeft: makeLeftEncoded,
7559 onRight: makeRightEncoded
7560 })
7561 }
7562 )
7563 return out as any
7564}
7565
7566const mapArbitrary = <K, V>(
7567 key: LazyArbitrary<K>,

Callers

nothing calls this directly

Calls 9

asSchemaFunction · 0.85
typeSchemaFunction · 0.85
rightEncodedFunction · 0.85
makeRightEncodedFunction · 0.85
leftEncodedFunction · 0.85
makeLeftEncodedFunction · 0.85
transformInterface · 0.70
UnionFunction · 0.70
EitherFromSelfFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…