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

Function Exit

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

Source from the content-addressed store, hash-verified

10829 * @since 3.10.0
10830 */
10831export function Exit<A extends Constraint, E extends Constraint, D extends Constraint>(
10832 value: A,
10833 error: E,
10834 defect: D
10835): Exit<A, E, D> {
10836 const schema = declareConstructor<
10837 Exit_.Exit<A["Type"], E["Type"]>,
10838 Exit_.Exit<A["Encoded"], E["Encoded"]>,
10839 ExitIso<A, E, D>
10840 >()(
10841 [value, error, defect],
10842 ([value, error, defect]) => {
10843 const cause = Cause(error, defect)
10844 return (input, ast, options) => {
10845 if (!Exit_.isExit(input)) {
10846 return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
10847 }
10848 switch (input._tag) {
10849 case "Success":
10850 return Effect.mapBothEager(
10851 SchemaParser.decodeUnknownEffect(value)(input.value, options),
10852 {
10853 onSuccess: Exit_.succeed,
10854 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
10855 }
10856 )
10857 case "Failure":
10858 return Effect.mapBothEager(
10859 SchemaParser.decodeUnknownEffect(cause)(input.cause, options),
10860 {
10861 onSuccess: Exit_.failCause,
10862 onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "cause", issue, input, options)
10863 }
10864 )
10865 }
10866 }
10867 },
10868 {
10869 representation: {
10870 id: "effect/schema/Exit",
10871 payload: null
10872 },
10873 toCode: ({ typeParameters }) => ({
10874 runtime: `Schema.Exit(${typeParameters[0].runtime}, ${typeParameters[1].runtime}, ${
10875 typeParameters[2].runtime
10876 })`,
10877 Type: `Exit.Exit<${typeParameters[0].Type}, ${typeParameters[1].Type}, ${typeParameters[2].Type}>`,
10878 importDeclarations: [`import * as Exit from "effect/Exit"`]
10879 }),
10880 expected: "Exit",
10881 toCodec: ([value, error, defect]) =>
10882 link<Exit_.Exit<A["Encoded"], E["Encoded"]>>()(
10883 Union([
10884 Struct({ _tag: Literal("Success"), value }),
10885 Struct({ _tag: Literal("Failure"), cause: Cause(error, defect) })
10886 ]),
10887 SchemaTransformation.transform({
10888 decode: (e): Exit_.Exit<A["Encoded"], E["Encoded"]> =>

Callers 1

Schema.tsFile · 0.70

Calls 15

causeToArbitraryFunction · 0.85
oneOfArbitrariesFunction · 0.85
withRecursionFunction · 0.85
causeToEquivalenceFunction · 0.85
causeFunction · 0.85
causeToFormatterFunction · 0.85
declareConstructorFunction · 0.70
CauseFunction · 0.70
linkFunction · 0.70
UnionFunction · 0.70
StructFunction · 0.70
LiteralFunction · 0.70

Tested by

no test coverage detected