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

Function Cause

packages/effect/src/Schema.ts:10493–10533  ·  view source on GitHub ↗
(error: E, defect: D)

Source from the content-addressed store, hash-verified

10491 * @since 3.10.0
10492 */
10493export function Cause<E extends Constraint, D extends Constraint>(error: E, defect: D): Cause<E, D> {
10494 const schema = declareConstructor<Cause_.Cause<E["Type"]>, Cause_.Cause<E["Encoded"]>, CauseIso<E, D>>()(
10495 [error, defect],
10496 ([error, defect]) => {
10497 const failures = ArraySchema(CauseReason(error, defect))
10498 return (input, ast, options) => {
10499 if (!Cause_.isCause(input)) {
10500 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
10501 }
10502 return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
10503 onSuccess: Cause_.fromReasons,
10504 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "failures", issue, input, options)
10505 })
10506 }
10507 },
10508 {
10509 representation: {
10510 id: "effect/schema/Cause",
10511 payload: null
10512 },
10513 toCode: ({ typeParameters }) => ({
10514 runtime: `Schema.Cause(${typeParameters[0].runtime}, ${typeParameters[1].runtime})`,
10515 Type: `Cause.Cause<${typeParameters[0].Type}, ${typeParameters[1].Type}>`,
10516 importDeclarations: [`import * as Cause from "effect/Cause"`]
10517 }),
10518 expected: "Cause",
10519 toCodec: ([error, defect]) =>
10520 link<Cause_.Cause<E["Encoded"]>>()(
10521 ArraySchema(CauseReason(error, defect)),
10522 SchemaTransformation.transform({
10523 decode: Cause_.fromReasons,
10524 encode: ({ reasons: failures }) => failures
10525 })
10526 ),
10527 toArbitrary: ([error, defect]) => causeToArbitrary(error, defect),
10528 toEquivalence: ([error, defect]) => causeToEquivalence(error, defect),
10529 toFormatter: ([error, defect]) => causeToFormatter(error, defect)
10530 }
10531 )
10532 return make(schema.ast, { error, defect })
10533}
10534
10535/**
10536 * Reviver for persisted `Cause` declarations.

Callers 2

Schema.tsFile · 0.70
ExitFunction · 0.70

Calls 9

causeToArbitraryFunction · 0.85
causeToEquivalenceFunction · 0.85
causeToFormatterFunction · 0.85
declareConstructorFunction · 0.70
CauseReasonFunction · 0.70
linkFunction · 0.70
makeFunction · 0.70
transformMethod · 0.65
failMethod · 0.45

Tested by

no test coverage detected