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

Function Exit

packages/effect/src/Schema.ts:15472–15540  ·  view source on GitHub ↗
(
  value: A,
  error: E,
  defect: D
)

Source from the content-addressed store, hash-verified

15470 * @since 3.10.0
15471 */
15472export function Exit<
15473 A extends Constraint,
15474 E extends Constraint,
15475 D extends Constraint
15476>(
15477 value: A,
15478 error: E,
15479 defect: D
15480): Exit<A, E, D> {
15481 const schema = declareConstructor<
15482 Exit_.Exit<A["Type"], E["Type"]>,
15483 Exit_.Exit<A["Encoded"], E["Encoded"]>,
15484 ExitIso<A, E, D>
15485 >()(
15486 [value, error, defect],
15487 ([value, error, defect]) => {
15488 const cause = Cause(error, defect)
15489 return (input, ast, options) => {
15490 if (!Exit_.isExit(input)) {
15491 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
15492 }
15493 switch (input._tag) {
15494 case "Success":
15495 return Effect.mapBothEager(
15496 SchemaParser.decodeUnknownEffect(value)(input.value, options),
15497 {
15498 onSuccess: Exit_.succeed,
15499 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
15500 }
15501 )
15502 case "Failure":
15503 return Effect.mapBothEager(
15504 SchemaParser.decodeUnknownEffect(cause)(input.cause, options),
15505 {
15506 onSuccess: Exit_.failCause,
15507 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "cause", issue, input, options)
15508 }
15509 )
15510 }
15511 }
15512 },
15513 {
15514 representation: {
15515 id: "effect/schema/Exit",
15516 payload: null
15517 },
15518 expected: "Exit",
15519 toCodec: ([value, error, defect]) =>
15520 link<Exit_.Exit<A["Encoded"], E["Encoded"]>>()(
15521 Union([
15522 Struct({ _tag: Literal("Success"), value }),
15523 Struct({
15524 _tag: Literal("Failure"),
15525 cause: Cause(error, defect)
15526 })
15527 ]),
15528 SchemaTransformation.transform({
15529 decode: (e): Exit_.Exit<A["Encoded"], E["Encoded"]> =>

Callers

nothing calls this directly

Calls 10

declareConstructorFunction · 0.70
CauseFunction · 0.70
linkFunction · 0.70
UnionFunction · 0.70
StructFunction · 0.70
LiteralFunction · 0.70
makeFunction · 0.70
failMethod · 0.65
transformMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected