( value: A, error: E, defect: D )
| 10829 | * @since 3.10.0 |
| 10830 | */ |
| 10831 | export 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"]> => |
no test coverage detected