effect 4.0.0-beta.3 → 4.0.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Array.d.ts +126 -299
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +102 -62
- package/dist/Array.js.map +1 -1
- package/dist/Brand.d.ts +1 -1
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/Cache.d.ts +2 -2
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +6 -5
- package/dist/Cache.js.map +1 -1
- package/dist/Cause.d.ts +2 -2
- package/dist/Cause.d.ts.map +1 -1
- package/dist/Channel.d.ts +116 -30
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +82 -37
- package/dist/Channel.js.map +1 -1
- package/dist/Chunk.d.ts +54 -247
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +36 -67
- package/dist/Chunk.js.map +1 -1
- package/dist/Combiner.d.ts +280 -13
- package/dist/Combiner.d.ts.map +1 -1
- package/dist/Combiner.js +198 -7
- package/dist/Combiner.js.map +1 -1
- package/dist/Config.d.ts +165 -9
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +65 -10
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +1 -1
- package/dist/Cron.d.ts +1 -1
- package/dist/Data.d.ts +535 -366
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js +132 -79
- package/dist/Data.js.map +1 -1
- package/dist/DateTime.d.ts +23 -161
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +6 -51
- package/dist/DateTime.js.map +1 -1
- package/dist/Duration.d.ts +11 -11
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +11 -11
- package/dist/Duration.js.map +1 -1
- package/dist/Effect.d.ts +1206 -924
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +390 -329
- package/dist/Effect.js.map +1 -1
- package/dist/Encoding.d.ts +194 -0
- package/dist/Encoding.d.ts.map +1 -0
- package/dist/Encoding.js +352 -0
- package/dist/Encoding.js.map +1 -0
- package/dist/Equal.d.ts +276 -109
- package/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +124 -48
- package/dist/Equal.js.map +1 -1
- package/dist/ErrorReporter.d.ts +374 -0
- package/dist/ErrorReporter.d.ts.map +1 -0
- package/dist/ErrorReporter.js +244 -0
- package/dist/ErrorReporter.js.map +1 -0
- package/dist/Exit.d.ts +24 -12
- package/dist/Exit.d.ts.map +1 -1
- package/dist/Exit.js +8 -4
- package/dist/Exit.js.map +1 -1
- package/dist/Fiber.d.ts +3 -2
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/FileSystem.d.ts +1 -1
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +5 -5
- package/dist/FileSystem.js.map +1 -1
- package/dist/Filter.d.ts +34 -38
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js +15 -13
- package/dist/Filter.js.map +1 -1
- package/dist/Formatter.d.ts +131 -47
- package/dist/Formatter.d.ts.map +1 -1
- package/dist/Formatter.js +229 -51
- package/dist/Formatter.js.map +1 -1
- package/dist/Function.d.ts +1 -9
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +2 -10
- package/dist/Function.js.map +1 -1
- package/dist/Graph.d.ts +1 -1
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +5 -8
- package/dist/Graph.js.map +1 -1
- package/dist/HashMap.d.ts +15 -14
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js +4 -4
- package/dist/HashMap.js.map +1 -1
- package/dist/Iterable.d.ts +39 -39
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +94 -22
- package/dist/Iterable.js.map +1 -1
- package/dist/JsonSchema.d.ts +299 -10
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +323 -4
- package/dist/JsonSchema.js.map +1 -1
- package/dist/Latch.d.ts +109 -0
- package/dist/Latch.d.ts.map +1 -0
- package/dist/Latch.js +72 -0
- package/dist/Latch.js.map +1 -0
- package/dist/Layer.d.ts +121 -126
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +43 -44
- package/dist/Layer.js.map +1 -1
- package/dist/LayerMap.d.ts +8 -8
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LayerMap.js +3 -3
- package/dist/LogLevel.d.ts +32 -0
- package/dist/LogLevel.d.ts.map +1 -1
- package/dist/LogLevel.js +28 -100
- package/dist/LogLevel.js.map +1 -1
- package/dist/Logger.d.ts +29 -95
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +2 -3
- package/dist/Logger.js.map +1 -1
- package/dist/ManagedRuntime.d.ts +2 -2
- package/dist/ManagedRuntime.js +2 -2
- package/dist/Metric.d.ts +4 -6
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +3 -5
- package/dist/Metric.js.map +1 -1
- package/dist/Newtype.d.ts +291 -0
- package/dist/Newtype.d.ts.map +1 -0
- package/dist/Newtype.js +161 -0
- package/dist/Newtype.js.map +1 -0
- package/dist/Optic.d.ts +947 -18
- package/dist/Optic.d.ts.map +1 -1
- package/dist/Optic.js +454 -5
- package/dist/Optic.js.map +1 -1
- package/dist/Option.d.ts +23 -16
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +15 -9
- package/dist/Option.js.map +1 -1
- package/dist/Pipeable.d.ts +17 -0
- package/dist/Pipeable.d.ts.map +1 -1
- package/dist/Pipeable.js +19 -1
- package/dist/Pipeable.js.map +1 -1
- package/dist/PlatformError.d.ts +10 -9
- package/dist/PlatformError.d.ts.map +1 -1
- package/dist/PlatformError.js +2 -2
- package/dist/PlatformError.js.map +1 -1
- package/dist/Pool.d.ts +6 -4
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +7 -5
- package/dist/Pool.js.map +1 -1
- package/dist/PubSub.d.ts +3 -2
- package/dist/PubSub.d.ts.map +1 -1
- package/dist/PubSub.js +3 -2
- package/dist/PubSub.js.map +1 -1
- package/dist/Pull.d.ts.map +1 -1
- package/dist/Pull.js +1 -1
- package/dist/Pull.js.map +1 -1
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +0 -1
- package/dist/Queue.js.map +1 -1
- package/dist/Random.d.ts +35 -1
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +46 -12
- package/dist/Random.js.map +1 -1
- package/dist/RcMap.d.ts +2 -2
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +1 -1
- package/dist/RcMap.js.map +1 -1
- package/dist/RcRef.d.ts +1 -1
- package/dist/RcRef.d.ts.map +1 -1
- package/dist/Record.d.ts +23 -120
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +21 -41
- package/dist/Record.js.map +1 -1
- package/dist/Reducer.d.ts +166 -7
- package/dist/Reducer.d.ts.map +1 -1
- package/dist/Reducer.js +135 -1
- package/dist/Reducer.js.map +1 -1
- package/dist/References.d.ts +9 -4
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +6 -1
- package/dist/References.js.map +1 -1
- package/dist/Request.d.ts +1 -1
- package/dist/Request.d.ts.map +1 -1
- package/dist/Request.js +2 -1
- package/dist/Request.js.map +1 -1
- package/dist/RequestResolver.d.ts +25 -45
- package/dist/RequestResolver.d.ts.map +1 -1
- package/dist/RequestResolver.js +10 -30
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Result.d.ts +1 -1
- package/dist/Result.d.ts.map +1 -1
- package/dist/Result.js +1 -2
- package/dist/Result.js.map +1 -1
- package/dist/Runtime.d.ts +66 -0
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +79 -6
- package/dist/Runtime.js.map +1 -1
- package/dist/Schedule.d.ts +191 -102
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +152 -66
- package/dist/Schedule.js.map +1 -1
- package/dist/Scheduler.d.ts +9 -0
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +11 -0
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +309 -88
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +499 -109
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +129 -23
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +5 -5
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +12 -14
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaParser.d.ts +5 -0
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +10 -0
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +44 -43
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +49 -24
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +107 -3
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +159 -4
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/ScopedCache.d.ts +2 -2
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +1 -1
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Semaphore.d.ts +211 -0
- package/dist/Semaphore.d.ts.map +1 -0
- package/dist/{PartitionedSemaphore.js → Semaphore.js} +97 -13
- package/dist/Semaphore.js.map +1 -0
- package/dist/ServiceMap.d.ts +41 -31
- package/dist/ServiceMap.d.ts.map +1 -1
- package/dist/ServiceMap.js +3 -3
- package/dist/ServiceMap.js.map +1 -1
- package/dist/Sink.d.ts +13 -13
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js +53 -6
- package/dist/Sink.js.map +1 -1
- package/dist/Stdio.d.ts +16 -4
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +18 -0
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +250 -428
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +137 -82
- package/dist/Stream.js.map +1 -1
- package/dist/Struct.d.ts +16 -0
- package/dist/Struct.d.ts.map +1 -1
- package/dist/Struct.js +22 -0
- package/dist/Struct.js.map +1 -1
- package/dist/SubscriptionRef.d.ts +2 -1
- package/dist/SubscriptionRef.d.ts.map +1 -1
- package/dist/SubscriptionRef.js +2 -1
- package/dist/SubscriptionRef.js.map +1 -1
- package/dist/SynchronizedRef.d.ts +2 -1
- package/dist/SynchronizedRef.d.ts.map +1 -1
- package/dist/SynchronizedRef.js +2 -1
- package/dist/SynchronizedRef.js.map +1 -1
- package/dist/Trie.d.ts +18 -17
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js +5 -5
- package/dist/Trie.js.map +1 -1
- package/dist/TxChunk.d.ts +37 -37
- package/dist/TxChunk.d.ts.map +1 -1
- package/dist/TxChunk.js +3 -3
- package/dist/TxChunk.js.map +1 -1
- package/dist/TxDeferred.d.ts +328 -0
- package/dist/TxDeferred.d.ts.map +1 -0
- package/dist/TxDeferred.js +196 -0
- package/dist/TxDeferred.js.map +1 -0
- package/dist/TxHashMap.d.ts +84 -83
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +24 -24
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxHashSet.d.ts +35 -35
- package/dist/TxHashSet.d.ts.map +1 -1
- package/dist/TxHashSet.js +14 -14
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +609 -0
- package/dist/TxPriorityQueue.d.ts.map +1 -0
- package/dist/TxPriorityQueue.js +415 -0
- package/dist/TxPriorityQueue.js.map +1 -0
- package/dist/TxPubSub.d.ts +585 -0
- package/dist/TxPubSub.d.ts.map +1 -0
- package/dist/TxPubSub.js +521 -0
- package/dist/TxPubSub.js.map +1 -0
- package/dist/TxQueue.d.ts +32 -32
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +26 -26
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +523 -0
- package/dist/TxReentrantLock.d.ts.map +1 -0
- package/dist/TxReentrantLock.js +504 -0
- package/dist/TxReentrantLock.js.map +1 -0
- package/dist/TxRef.d.ts +34 -34
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +21 -14
- package/dist/TxRef.js.map +1 -1
- package/dist/TxSemaphore.d.ts +8 -8
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +7 -7
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/TxSubscriptionRef.d.ts +508 -0
- package/dist/TxSubscriptionRef.d.ts.map +1 -0
- package/dist/TxSubscriptionRef.js +293 -0
- package/dist/TxSubscriptionRef.js.map +1 -0
- package/dist/Types.d.ts +80 -23
- package/dist/Types.d.ts.map +1 -1
- package/dist/Utils.d.ts +137 -65
- package/dist/Utils.d.ts.map +1 -1
- package/dist/Utils.js +38 -66
- package/dist/Utils.js.map +1 -1
- package/dist/index.d.ts +718 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +718 -23
- package/dist/index.js.map +1 -1
- package/dist/internal/core.js +11 -3
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/dateTime.js +3 -11
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +264 -126
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js +5 -4
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/random.d.ts +2 -0
- package/dist/internal/random.d.ts.map +1 -0
- package/dist/internal/random.js +13 -0
- package/dist/internal/random.js.map +1 -0
- package/dist/internal/rcRef.js +3 -2
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/internal/request.js +2 -2
- package/dist/internal/request.js.map +1 -1
- package/dist/internal/schema/annotations.js +2 -0
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/representation.js +47 -106
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.js +1 -0
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/internal/schema/to-codec.js +7 -10
- package/dist/internal/schema/to-codec.js.map +1 -1
- package/dist/internal/trie.js +5 -4
- package/dist/internal/trie.js.map +1 -1
- package/dist/testing/TestClock.d.ts +8 -7
- package/dist/testing/TestClock.d.ts.map +1 -1
- package/dist/testing/TestClock.js +6 -4
- package/dist/testing/TestClock.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +266 -32
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +296 -23
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/testing/index.d.ts +64 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +64 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/unstable/ai/AiError.d.ts +134 -51
- package/dist/unstable/ai/AiError.d.ts.map +1 -1
- package/dist/unstable/ai/AiError.js +19 -16
- package/dist/unstable/ai/AiError.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +5 -5
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js +38 -44
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +16 -30
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +97 -37
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +183 -88
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +57 -12
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +66 -13
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +193 -51
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Model.d.ts +25 -7
- package/dist/unstable/ai/Model.d.ts.map +1 -1
- package/dist/unstable/ai/Model.js +22 -6
- package/dist/unstable/ai/Model.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +20 -20
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Response.d.ts +26 -26
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js +1 -1
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +20 -4
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +14 -9
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +1 -1
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +4 -11
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/ai/index.d.ts +1 -1
- package/dist/unstable/ai/index.js +1 -1
- package/dist/unstable/ai/internal/codec-transformer.js +0 -5
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/cli/CliError.d.ts +27 -60
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +25 -57
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/CliOutput.js +59 -6
- package/dist/unstable/cli/CliOutput.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +368 -56
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +325 -64
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +125 -0
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -0
- package/dist/unstable/cli/GlobalFlag.js +118 -0
- package/dist/unstable/cli/GlobalFlag.js.map +1 -0
- package/dist/unstable/cli/HelpDoc.d.ts +70 -2
- package/dist/unstable/cli/HelpDoc.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts +1 -1
- package/dist/unstable/cli/Primitive.js +1 -1
- package/dist/unstable/cli/Prompt.js +35 -8
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/command.d.ts +40 -14
- package/dist/unstable/cli/internal/command.d.ts.map +1 -1
- package/dist/unstable/cli/internal/command.js +72 -46
- package/dist/unstable/cli/internal/command.js.map +1 -1
- package/dist/unstable/cli/internal/completions/CommandDescriptor.js +7 -2
- package/dist/unstable/cli/internal/completions/CommandDescriptor.js.map +1 -1
- package/dist/unstable/cli/internal/config.js +42 -0
- package/dist/unstable/cli/internal/config.js.map +1 -1
- package/dist/unstable/cli/internal/help.d.ts +33 -0
- package/dist/unstable/cli/internal/help.d.ts.map +1 -0
- package/dist/unstable/cli/internal/help.js +125 -0
- package/dist/unstable/cli/internal/help.js.map +1 -0
- package/dist/unstable/cli/internal/parser.js +55 -42
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts +1 -1
- package/dist/unstable/cluster/ClusterCron.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterCron.js +1 -1
- package/dist/unstable/cluster/ClusterCron.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +4 -3
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +7 -6
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/EntityResource.d.ts +2 -2
- package/dist/unstable/cluster/EntityResource.d.ts.map +1 -1
- package/dist/unstable/cluster/Envelope.d.ts +1 -1
- package/dist/unstable/cluster/K8sHttpClient.d.ts +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js +4 -4
- package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +10 -10
- package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/MessageStorage.js +2 -1
- package/dist/unstable/cluster/MessageStorage.js.map +1 -1
- package/dist/unstable/cluster/Reply.d.ts +6 -6
- package/dist/unstable/cluster/Runner.d.ts +1 -1
- package/dist/unstable/cluster/Runners.d.ts.map +1 -1
- package/dist/unstable/cluster/Runners.js +4 -3
- package/dist/unstable/cluster/Runners.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +2 -2
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +9 -7
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.d.ts +21 -21
- package/dist/unstable/cluster/ShardingConfig.d.ts.map +1 -1
- package/dist/unstable/cluster/ShardingConfig.js +20 -20
- package/dist/unstable/cluster/ShardingConfig.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +5 -4
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/cluster/internal/entityReaper.js +2 -1
- package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
- package/dist/unstable/cluster/internal/resourceRef.js +2 -1
- package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.d.ts +36 -36
- package/dist/unstable/encoding/Msgpack.d.ts +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +1 -1
- package/dist/unstable/encoding/Sse.d.ts +4 -4
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +2 -2
- package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLog.js +2 -1
- package/dist/unstable/eventlog/EventLog.js.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +6 -6
- package/dist/unstable/http/Cookies.d.ts +47 -3
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +24 -2
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/Headers.d.ts +16 -0
- package/dist/unstable/http/Headers.d.ts.map +1 -1
- package/dist/unstable/http/Headers.js +38 -10
- package/dist/unstable/http/Headers.js.map +1 -1
- package/dist/unstable/http/HttpBody.d.ts +3 -3
- package/dist/unstable/http/HttpBody.d.ts.map +1 -1
- package/dist/unstable/http/HttpBody.js +6 -6
- package/dist/unstable/http/HttpBody.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +117 -15
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +189 -12
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientError.d.ts +7 -7
- package/dist/unstable/http/HttpClientRequest.d.ts +16 -11
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +31 -20
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpClientResponse.d.ts +2 -1
- package/dist/unstable/http/HttpClientResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientResponse.js +4 -0
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +7 -5
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +46 -54
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpMethod.d.ts +4 -4
- package/dist/unstable/http/HttpMethod.d.ts.map +1 -1
- package/dist/unstable/http/HttpMethod.js +3 -3
- package/dist/unstable/http/HttpMethod.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts +1 -6
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +8 -17
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +20 -33
- package/dist/unstable/http/HttpServerError.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerError.js +37 -44
- package/dist/unstable/http/HttpServerError.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts +12 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +291 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerRespondable.d.ts +2 -2
- package/dist/unstable/http/HttpServerRespondable.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRespondable.js +5 -5
- package/dist/unstable/http/HttpServerRespondable.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +50 -3
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +234 -1
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
- package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
- package/dist/unstable/http/HttpStaticServer.js +353 -0
- package/dist/unstable/http/HttpStaticServer.js.map +1 -0
- package/dist/unstable/http/Multipart.d.ts +3 -3
- package/dist/unstable/http/UrlParams.d.ts +14 -6
- package/dist/unstable/http/UrlParams.d.ts.map +1 -1
- package/dist/unstable/http/UrlParams.js +1 -1
- package/dist/unstable/http/UrlParams.js.map +1 -1
- package/dist/unstable/http/index.d.ts +4 -0
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +4 -0
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/http/internal/preResponseHandler.d.ts +2 -0
- package/dist/unstable/http/internal/preResponseHandler.d.ts.map +1 -0
- package/dist/unstable/http/internal/preResponseHandler.js +10 -0
- package/dist/unstable/http/internal/preResponseHandler.js.map +1 -0
- package/dist/unstable/httpapi/HttpApi.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +11 -5
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +28 -18
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +66 -6
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +40 -3
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +41 -54
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +17 -26
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +16 -14
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +44 -29
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +4 -3
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +6 -0
- package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSecurity.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiSecurity.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSecurity.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +32 -21
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/Otlp.d.ts +12 -12
- package/dist/unstable/observability/Otlp.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.d.ts +2 -2
- package/dist/unstable/observability/OtlpExporter.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpExporter.js +1 -1
- package/dist/unstable/observability/OtlpExporter.js.map +1 -1
- package/dist/unstable/observability/OtlpLogger.d.ts +4 -4
- package/dist/unstable/observability/OtlpLogger.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpLogger.js +7 -4
- package/dist/unstable/observability/OtlpLogger.js.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.d.ts +4 -4
- package/dist/unstable/observability/OtlpMetrics.d.ts.map +1 -1
- package/dist/unstable/observability/OtlpTracer.d.ts +4 -4
- package/dist/unstable/observability/OtlpTracer.d.ts.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
- package/dist/unstable/persistence/KeyValueStore.js +6 -6
- package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts +2 -2
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedCache.d.ts +6 -5
- package/dist/unstable/persistence/PersistedCache.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedCache.js +2 -1
- package/dist/unstable/persistence/PersistedCache.js.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts +12 -12
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +12 -11
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts +1 -1
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistence.js +2 -2
- package/dist/unstable/persistence/Persistence.js.map +1 -1
- package/dist/unstable/persistence/RateLimiter.d.ts +3 -3
- package/dist/unstable/persistence/RateLimiter.d.ts.map +1 -1
- package/dist/unstable/persistence/RateLimiter.js +1 -1
- package/dist/unstable/persistence/RateLimiter.js.map +1 -1
- package/dist/unstable/process/ChildProcess.d.ts +5 -128
- package/dist/unstable/process/ChildProcess.d.ts.map +1 -1
- package/dist/unstable/process/ChildProcess.js +1 -65
- package/dist/unstable/process/ChildProcess.js.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.d.ts +45 -7
- package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
- package/dist/unstable/process/ChildProcessSpawner.js +21 -1
- package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +73 -12
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +107 -20
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +10 -12
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +42 -12
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.d.ts +6 -0
- package/dist/unstable/reactivity/AtomRegistry.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +50 -9
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +9 -9
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +47 -21
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/reactivity/Hydration.d.ts +39 -0
- package/dist/unstable/reactivity/Hydration.d.ts.map +1 -0
- package/dist/unstable/reactivity/Hydration.js +76 -0
- package/dist/unstable/reactivity/Hydration.js.map +1 -0
- package/dist/unstable/reactivity/index.d.ts +4 -0
- package/dist/unstable/reactivity/index.d.ts.map +1 -1
- package/dist/unstable/reactivity/index.js +4 -0
- package/dist/unstable/reactivity/index.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +5 -5
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts +5 -26
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +6 -13
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts +2 -2
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcGroup.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +8 -8
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/rpc/RpcSchema.d.ts +13 -0
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.js +14 -0
- package/dist/unstable/rpc/RpcSchema.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +34 -9
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +5 -9
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +17 -17
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/Utils.d.ts.map +1 -1
- package/dist/unstable/rpc/Utils.js +3 -2
- package/dist/unstable/rpc/Utils.js.map +1 -1
- package/dist/unstable/schema/Model.d.ts +22 -1
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/Model.js +15 -0
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +5 -5
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +6 -6
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts +4 -4
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +6 -5
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/dist/unstable/socket/SocketServer.d.ts +3 -3
- package/dist/unstable/sql/Migrator.d.ts +1 -1
- package/dist/unstable/sql/SqlClient.d.ts +1 -1
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlError.d.ts +14 -14
- package/dist/unstable/sql/SqlError.d.ts.map +1 -1
- package/dist/unstable/sql/SqlError.js +9 -3
- package/dist/unstable/sql/SqlError.js.map +1 -1
- package/dist/unstable/sql/SqlModel.d.ts +2 -2
- package/dist/unstable/sql/SqlModel.d.ts.map +1 -1
- package/dist/unstable/sql/SqlModel.js +3 -3
- package/dist/unstable/sql/SqlModel.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +17 -8
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +17 -6
- package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
- package/dist/unstable/sql/SqlSchema.js +17 -7
- package/dist/unstable/sql/SqlSchema.js.map +1 -1
- package/dist/unstable/sql/Statement.js +0 -1
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workers/Worker.d.ts.map +1 -1
- package/dist/unstable/workers/Worker.js +2 -1
- package/dist/unstable/workers/Worker.js.map +1 -1
- package/dist/unstable/workflow/DurableClock.d.ts +3 -3
- package/dist/unstable/workflow/DurableClock.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableClock.js +3 -3
- package/dist/unstable/workflow/DurableClock.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +2 -2
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +3 -3
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +1 -1
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +12 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +137 -1
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +2 -2
- package/src/Array.ts +192 -342
- package/src/Brand.ts +1 -1
- package/src/Cache.ts +9 -8
- package/src/Cause.ts +2 -2
- package/src/Channel.ts +554 -138
- package/src/Chunk.ts +81 -268
- package/src/Combiner.ts +280 -13
- package/src/Config.ts +186 -24
- package/src/Data.ts +539 -376
- package/src/DateTime.ts +24 -164
- package/src/Duration.ts +13 -13
- package/src/Effect.ts +1477 -1126
- package/src/Encoding.ts +879 -0
- package/src/Equal.ts +278 -111
- package/src/ErrorReporter.ts +457 -0
- package/src/Exit.ts +24 -12
- package/src/Fiber.ts +10 -2
- package/src/FileSystem.ts +7 -8
- package/src/Filter.ts +52 -63
- package/src/Formatter.ts +253 -51
- package/src/Function.ts +2 -10
- package/src/Graph.ts +24 -11
- package/src/HashMap.ts +15 -14
- package/src/Iterable.ts +104 -50
- package/src/JsonSchema.ts +383 -10
- package/src/Latch.ts +112 -0
- package/src/Layer.ts +123 -132
- package/src/LayerMap.ts +9 -9
- package/src/LogLevel.ts +37 -0
- package/src/Logger.ts +33 -100
- package/src/ManagedRuntime.ts +2 -2
- package/src/Metric.ts +6 -8
- package/src/Newtype.ts +308 -0
- package/src/Optic.ts +948 -19
- package/src/Option.ts +32 -24
- package/src/Pipeable.ts +32 -1
- package/src/PlatformError.ts +5 -5
- package/src/Pool.ts +13 -11
- package/src/PubSub.ts +10 -9
- package/src/Pull.ts +1 -1
- package/src/Queue.ts +0 -1
- package/src/Random.ts +51 -14
- package/src/RcMap.ts +5 -5
- package/src/RcRef.ts +1 -1
- package/src/Record.ts +42 -152
- package/src/Reducer.ts +166 -7
- package/src/References.ts +10 -5
- package/src/Request.ts +3 -2
- package/src/RequestResolver.ts +29 -49
- package/src/Result.ts +2 -4
- package/src/Runtime.ts +102 -6
- package/src/Schedule.ts +462 -242
- package/src/Scheduler.ts +12 -0
- package/src/Schema.ts +796 -194
- package/src/SchemaAST.ts +164 -31
- package/src/SchemaGetter.ts +15 -17
- package/src/SchemaParser.ts +11 -0
- package/src/SchemaRepresentation.ts +49 -24
- package/src/SchemaTransformation.ts +189 -4
- package/src/ScopedCache.ts +3 -3
- package/src/Semaphore.ts +356 -0
- package/src/ServiceMap.ts +50 -40
- package/src/Sink.ts +78 -26
- package/src/Stdio.ts +27 -4
- package/src/Stream.ts +586 -608
- package/src/Struct.ts +26 -0
- package/src/SubscriptionRef.ts +3 -2
- package/src/SynchronizedRef.ts +3 -2
- package/src/Trie.ts +18 -17
- package/src/TxChunk.ts +72 -53
- package/src/TxDeferred.ts +394 -0
- package/src/TxHashMap.ts +332 -285
- package/src/TxHashSet.ts +111 -116
- package/src/TxPriorityQueue.ts +767 -0
- package/src/TxPubSub.ts +789 -0
- package/src/TxQueue.ts +241 -251
- package/src/TxReentrantLock.ts +753 -0
- package/src/TxRef.ts +50 -38
- package/src/TxSemaphore.ts +29 -32
- package/src/TxSubscriptionRef.ts +639 -0
- package/src/Types.ts +73 -19
- package/src/Utils.ts +137 -111
- package/src/index.ts +728 -24
- package/src/internal/core.ts +12 -5
- package/src/internal/dateTime.ts +9 -30
- package/src/internal/effect.ts +774 -301
- package/src/internal/hashMap.ts +8 -7
- package/src/internal/random.ts +20 -0
- package/src/internal/rcRef.ts +4 -3
- package/src/internal/request.ts +2 -2
- package/src/internal/schema/annotations.ts +2 -0
- package/src/internal/schema/representation.ts +45 -94
- package/src/internal/schema/schema.ts +1 -0
- package/src/internal/schema/to-codec.ts +7 -17
- package/src/internal/trie.ts +15 -9
- package/src/testing/TestClock.ts +13 -11
- package/src/testing/TestSchema.ts +332 -35
- package/src/testing/index.ts +64 -1
- package/src/unstable/ai/AiError.ts +105 -48
- package/src/unstable/ai/Chat.ts +47 -61
- package/src/unstable/ai/LanguageModel.ts +153 -68
- package/src/unstable/ai/McpSchema.ts +73 -13
- package/src/unstable/ai/McpServer.ts +271 -61
- package/src/unstable/ai/Model.ts +40 -9
- package/src/unstable/ai/Prompt.ts +37 -37
- package/src/unstable/ai/Response.ts +25 -25
- package/src/unstable/ai/Tool.ts +20 -14
- package/src/unstable/ai/Toolkit.ts +5 -14
- package/src/unstable/ai/index.ts +1 -1
- package/src/unstable/ai/internal/codec-transformer.ts +0 -7
- package/src/unstable/cli/CliError.ts +47 -59
- package/src/unstable/cli/CliOutput.ts +75 -6
- package/src/unstable/cli/Command.ts +796 -187
- package/src/unstable/cli/GlobalFlag.ts +243 -0
- package/src/unstable/cli/HelpDoc.ts +80 -2
- package/src/unstable/cli/Primitive.ts +1 -1
- package/src/unstable/cli/Prompt.ts +31 -9
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cli/internal/command.ts +109 -63
- package/src/unstable/cli/internal/completions/CommandDescriptor.ts +7 -2
- package/src/unstable/cli/internal/config.ts +49 -0
- package/src/unstable/cli/internal/help.ts +171 -0
- package/src/unstable/cli/internal/parser.ts +66 -61
- package/src/unstable/cluster/ClusterCron.ts +2 -2
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +5 -4
- package/src/unstable/cluster/Entity.ts +11 -10
- package/src/unstable/cluster/EntityResource.ts +4 -4
- package/src/unstable/cluster/Envelope.ts +1 -1
- package/src/unstable/cluster/K8sHttpClient.ts +5 -5
- package/src/unstable/cluster/MessageStorage.ts +3 -5
- package/src/unstable/cluster/Runners.ts +6 -5
- package/src/unstable/cluster/Sharding.ts +12 -10
- package/src/unstable/cluster/ShardingConfig.ts +30 -31
- package/src/unstable/cluster/SqlRunnerStorage.ts +1 -1
- package/src/unstable/cluster/internal/entityManager.ts +9 -8
- package/src/unstable/cluster/internal/entityReaper.ts +2 -1
- package/src/unstable/cluster/internal/resourceRef.ts +2 -1
- package/src/unstable/encoding/Sse.ts +3 -5
- package/src/unstable/eventlog/EventLog.ts +2 -1
- package/src/unstable/http/Cookies.ts +87 -3
- package/src/unstable/http/Headers.ts +62 -13
- package/src/unstable/http/HttpBody.ts +6 -6
- package/src/unstable/http/HttpClient.ts +374 -33
- package/src/unstable/http/HttpClientRequest.ts +38 -30
- package/src/unstable/http/HttpClientResponse.ts +7 -2
- package/src/unstable/http/HttpEffect.ts +54 -68
- package/src/unstable/http/HttpMethod.ts +16 -4
- package/src/unstable/http/HttpMiddleware.ts +9 -24
- package/src/unstable/http/HttpServerError.ts +42 -45
- package/src/unstable/http/HttpServerRequest.ts +389 -2
- package/src/unstable/http/HttpServerRespondable.ts +6 -6
- package/src/unstable/http/HttpServerResponse.ts +337 -4
- package/src/unstable/http/HttpStaticServer.ts +456 -0
- package/src/unstable/http/Multipart.ts +2 -2
- package/src/unstable/http/UrlParams.ts +20 -5
- package/src/unstable/http/index.ts +5 -0
- package/src/unstable/http/internal/preResponseHandler.ts +15 -0
- package/src/unstable/httpapi/HttpApi.ts +6 -6
- package/src/unstable/httpapi/HttpApiBuilder.ts +81 -28
- package/src/unstable/httpapi/HttpApiClient.ts +100 -11
- package/src/unstable/httpapi/HttpApiEndpoint.ts +71 -87
- package/src/unstable/httpapi/HttpApiError.ts +51 -28
- package/src/unstable/httpapi/HttpApiGroup.ts +7 -6
- package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -4
- package/src/unstable/httpapi/HttpApiScalar.ts +6 -0
- package/src/unstable/httpapi/HttpApiSecurity.ts +3 -3
- package/src/unstable/httpapi/OpenApi.ts +41 -23
- package/src/unstable/observability/Otlp.ts +12 -12
- package/src/unstable/observability/OtlpExporter.ts +3 -3
- package/src/unstable/observability/OtlpLogger.ts +13 -9
- package/src/unstable/observability/OtlpMetrics.ts +4 -4
- package/src/unstable/observability/OtlpTracer.ts +4 -4
- package/src/unstable/persistence/KeyValueStore.ts +6 -6
- package/src/unstable/persistence/Persistable.ts +2 -2
- package/src/unstable/persistence/PersistedCache.ts +20 -9
- package/src/unstable/persistence/PersistedQueue.ts +25 -24
- package/src/unstable/persistence/Persistence.ts +3 -3
- package/src/unstable/persistence/RateLimiter.ts +4 -4
- package/src/unstable/process/ChildProcess.ts +6 -208
- package/src/unstable/process/ChildProcessSpawner.ts +75 -14
- package/src/unstable/reactivity/Atom.ts +211 -50
- package/src/unstable/reactivity/AtomHttpApi.ts +66 -31
- package/src/unstable/reactivity/AtomRegistry.ts +61 -9
- package/src/unstable/reactivity/AtomRpc.ts +51 -20
- package/src/unstable/reactivity/Hydration.ts +112 -0
- package/src/unstable/reactivity/index.ts +5 -0
- package/src/unstable/rpc/Rpc.ts +7 -9
- package/src/unstable/rpc/RpcClient.ts +12 -54
- package/src/unstable/rpc/RpcGroup.ts +4 -4
- package/src/unstable/rpc/RpcMiddleware.ts +15 -9
- package/src/unstable/rpc/RpcSchema.ts +17 -0
- package/src/unstable/rpc/RpcSerialization.ts +44 -9
- package/src/unstable/rpc/RpcServer.ts +28 -32
- package/src/unstable/rpc/Utils.ts +3 -2
- package/src/unstable/schema/Model.ts +31 -0
- package/src/unstable/schema/VariantSchema.ts +9 -9
- package/src/unstable/socket/Socket.ts +16 -17
- package/src/unstable/sql/SqlClient.ts +1 -1
- package/src/unstable/sql/SqlError.ts +11 -9
- package/src/unstable/sql/SqlModel.ts +5 -5
- package/src/unstable/sql/SqlResolver.ts +17 -7
- package/src/unstable/sql/SqlSchema.ts +42 -26
- package/src/unstable/sql/Statement.ts +0 -1
- package/src/unstable/workers/Worker.ts +2 -1
- package/src/unstable/workflow/DurableClock.ts +8 -8
- package/src/unstable/workflow/DurableDeferred.ts +2 -2
- package/src/unstable/workflow/Workflow.ts +6 -2
- package/src/unstable/workflow/WorkflowEngine.ts +185 -2
- package/dist/PartitionedSemaphore.d.ts +0 -52
- package/dist/PartitionedSemaphore.d.ts.map +0 -1
- package/dist/PartitionedSemaphore.js.map +0 -1
- package/dist/encoding/Base64.d.ts +0 -67
- package/dist/encoding/Base64.d.ts.map +0 -1
- package/dist/encoding/Base64.js +0 -146
- package/dist/encoding/Base64.js.map +0 -1
- package/dist/encoding/Base64Url.d.ts +0 -60
- package/dist/encoding/Base64Url.d.ts.map +0 -1
- package/dist/encoding/Base64Url.js +0 -89
- package/dist/encoding/Base64Url.js.map +0 -1
- package/dist/encoding/EncodingError.d.ts +0 -31
- package/dist/encoding/EncodingError.d.ts.map +0 -1
- package/dist/encoding/EncodingError.js +0 -22
- package/dist/encoding/EncodingError.js.map +0 -1
- package/dist/encoding/Hex.d.ts +0 -61
- package/dist/encoding/Hex.d.ts.map +0 -1
- package/dist/encoding/Hex.js +0 -115
- package/dist/encoding/Hex.js.map +0 -1
- package/dist/encoding/index.d.ts +0 -26
- package/dist/encoding/index.d.ts.map +0 -1
- package/dist/encoding/index.js +0 -27
- package/dist/encoding/index.js.map +0 -1
- package/dist/unstable/cli/internal/builtInFlags.d.ts +0 -7
- package/dist/unstable/cli/internal/builtInFlags.d.ts.map +0 -1
- package/dist/unstable/cli/internal/builtInFlags.js +0 -44
- package/dist/unstable/cli/internal/builtInFlags.js.map +0 -1
- package/src/PartitionedSemaphore.ts +0 -182
- package/src/encoding/Base64.ts +0 -366
- package/src/encoding/Base64Url.ts +0 -104
- package/src/encoding/EncodingError.ts +0 -35
- package/src/encoding/Hex.ts +0 -390
- package/src/encoding/index.ts +0 -31
- package/src/unstable/cli/internal/builtInFlags.ts +0 -78
package/src/Effect.ts
CHANGED
|
@@ -40,12 +40,14 @@
|
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
42
|
* ```ts
|
|
43
|
-
* import { Effect } from "effect"
|
|
43
|
+
* import { Data, Effect } from "effect"
|
|
44
|
+
*
|
|
45
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
44
46
|
*
|
|
45
47
|
* // Effect that may fail
|
|
46
48
|
* const divide = (a: number, b: number) =>
|
|
47
49
|
* b === 0
|
|
48
|
-
* ? Effect.fail(new
|
|
50
|
+
* ? Effect.fail(new DiscountRateError())
|
|
49
51
|
* : Effect.succeed(a / b)
|
|
50
52
|
*
|
|
51
53
|
* // Error handling
|
|
@@ -84,7 +86,7 @@ import * as internalRequest from "./internal/request.ts"
|
|
|
84
86
|
import * as internalSchedule from "./internal/schedule.ts"
|
|
85
87
|
import type * as Layer from "./Layer.ts"
|
|
86
88
|
import type { Logger } from "./Logger.ts"
|
|
87
|
-
import type {
|
|
89
|
+
import type { Severity } from "./LogLevel.ts"
|
|
88
90
|
import * as Metric from "./Metric.ts"
|
|
89
91
|
import type { Option } from "./Option.ts"
|
|
90
92
|
import type { Pipeable } from "./Pipeable.ts"
|
|
@@ -116,9 +118,12 @@ import type {
|
|
|
116
118
|
ExcludeTag,
|
|
117
119
|
ExtractReason,
|
|
118
120
|
ExtractTag,
|
|
121
|
+
NarrowReason,
|
|
119
122
|
NoInfer,
|
|
123
|
+
OmitReason,
|
|
120
124
|
ReasonOf,
|
|
121
125
|
ReasonTags,
|
|
126
|
+
Simplify,
|
|
122
127
|
Tags,
|
|
123
128
|
unassigned
|
|
124
129
|
} from "./Types.ts"
|
|
@@ -143,13 +148,15 @@ const TypeId = core.EffectTypeId
|
|
|
143
148
|
*
|
|
144
149
|
* @example
|
|
145
150
|
* ```ts
|
|
146
|
-
* import { Effect } from "effect"
|
|
151
|
+
* import { Data, Effect } from "effect"
|
|
152
|
+
*
|
|
153
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
147
154
|
*
|
|
148
155
|
* // A simple effect that succeeds with a value
|
|
149
156
|
* const success = Effect.succeed(42)
|
|
150
157
|
*
|
|
151
|
-
* // An effect that
|
|
152
|
-
* const risky = Effect.fail(new
|
|
158
|
+
* // An effect that will always fail
|
|
159
|
+
* const risky = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
153
160
|
*
|
|
154
161
|
* // Effects can be composed using generator functions
|
|
155
162
|
* const program = Effect.gen(function*() {
|
|
@@ -430,13 +437,15 @@ export declare namespace All {
|
|
|
430
437
|
* @category Models
|
|
431
438
|
* @example
|
|
432
439
|
* ```ts
|
|
433
|
-
* import { Effect } from "effect"
|
|
440
|
+
* import { Data, Effect } from "effect"
|
|
441
|
+
*
|
|
442
|
+
* class OopsError extends Data.TaggedError("OopsError")<{}> {}
|
|
434
443
|
*
|
|
435
444
|
* // EffectAny represents an Effect with any type parameters
|
|
436
445
|
* const effects: Array<Effect.All.EffectAny> = [
|
|
437
446
|
* Effect.succeed(42),
|
|
438
447
|
* Effect.succeed("hello"),
|
|
439
|
-
* Effect.fail(new
|
|
448
|
+
* Effect.fail(new OopsError())
|
|
440
449
|
* ]
|
|
441
450
|
* ```
|
|
442
451
|
*/
|
|
@@ -740,7 +749,6 @@ export declare namespace All {
|
|
|
740
749
|
* ```
|
|
741
750
|
*
|
|
742
751
|
* @see {@link forEach} for iterating over elements and applying an effect.
|
|
743
|
-
* @see {@link allWith} for a data-last version of this function.
|
|
744
752
|
*
|
|
745
753
|
* @since 2.0.0
|
|
746
754
|
* @category Collecting
|
|
@@ -852,6 +860,316 @@ export const partition: {
|
|
|
852
860
|
): Effect<[excluded: Array<E>, satisfying: Array<B>], never, R>
|
|
853
861
|
} = internal.partition
|
|
854
862
|
|
|
863
|
+
/**
|
|
864
|
+
* Applies an effectful function to each element and accumulates all failures.
|
|
865
|
+
*
|
|
866
|
+
* This function always evaluates every element. If at least one effect fails,
|
|
867
|
+
* all failures are returned as a non-empty array and successes are discarded.
|
|
868
|
+
* If all effects succeed, it returns all collected successes.
|
|
869
|
+
*
|
|
870
|
+
* Use `discard: true` to ignore successful values while still validating all
|
|
871
|
+
* elements.
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* ```ts
|
|
875
|
+
* import { Effect } from "effect"
|
|
876
|
+
*
|
|
877
|
+
* const program = Effect.validate([0, 1, 2, 3], (n) =>
|
|
878
|
+
* n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
|
|
879
|
+
* )
|
|
880
|
+
*
|
|
881
|
+
* Effect.runPromiseExit(program).then(console.log)
|
|
882
|
+
* // {
|
|
883
|
+
* // _id: 'Exit',
|
|
884
|
+
* // _tag: 'Failure',
|
|
885
|
+
* // cause: {
|
|
886
|
+
* // _id: 'Cause',
|
|
887
|
+
* // reasons: [
|
|
888
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
|
|
889
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
|
|
890
|
+
* // ]
|
|
891
|
+
* // }
|
|
892
|
+
* // }
|
|
893
|
+
* ```
|
|
894
|
+
*
|
|
895
|
+
* @since 4.0.0
|
|
896
|
+
* @category Error Accumulation
|
|
897
|
+
*/
|
|
898
|
+
export const validate: {
|
|
899
|
+
/**
|
|
900
|
+
* Applies an effectful function to each element and accumulates all failures.
|
|
901
|
+
*
|
|
902
|
+
* This function always evaluates every element. If at least one effect fails,
|
|
903
|
+
* all failures are returned as a non-empty array and successes are discarded.
|
|
904
|
+
* If all effects succeed, it returns all collected successes.
|
|
905
|
+
*
|
|
906
|
+
* Use `discard: true` to ignore successful values while still validating all
|
|
907
|
+
* elements.
|
|
908
|
+
*
|
|
909
|
+
* @example
|
|
910
|
+
* ```ts
|
|
911
|
+
* import { Effect } from "effect"
|
|
912
|
+
*
|
|
913
|
+
* const program = Effect.validate([0, 1, 2, 3], (n) =>
|
|
914
|
+
* n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
|
|
915
|
+
* )
|
|
916
|
+
*
|
|
917
|
+
* Effect.runPromiseExit(program).then(console.log)
|
|
918
|
+
* // {
|
|
919
|
+
* // _id: 'Exit',
|
|
920
|
+
* // _tag: 'Failure',
|
|
921
|
+
* // cause: {
|
|
922
|
+
* // _id: 'Cause',
|
|
923
|
+
* // reasons: [
|
|
924
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
|
|
925
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
|
|
926
|
+
* // ]
|
|
927
|
+
* // }
|
|
928
|
+
* // }
|
|
929
|
+
* ```
|
|
930
|
+
*
|
|
931
|
+
* @since 4.0.0
|
|
932
|
+
* @category Error Accumulation
|
|
933
|
+
*/
|
|
934
|
+
<A, B, E, R>(
|
|
935
|
+
f: (a: A, i: number) => Effect<B, E, R>,
|
|
936
|
+
options?: {
|
|
937
|
+
readonly concurrency?: Concurrency | undefined
|
|
938
|
+
readonly discard?: false | undefined
|
|
939
|
+
} | undefined
|
|
940
|
+
): (elements: Iterable<A>) => Effect<Array<B>, Arr.NonEmptyArray<E>, R>
|
|
941
|
+
/**
|
|
942
|
+
* Applies an effectful function to each element and accumulates all failures.
|
|
943
|
+
*
|
|
944
|
+
* This function always evaluates every element. If at least one effect fails,
|
|
945
|
+
* all failures are returned as a non-empty array and successes are discarded.
|
|
946
|
+
* If all effects succeed, it returns all collected successes.
|
|
947
|
+
*
|
|
948
|
+
* Use `discard: true` to ignore successful values while still validating all
|
|
949
|
+
* elements.
|
|
950
|
+
*
|
|
951
|
+
* @example
|
|
952
|
+
* ```ts
|
|
953
|
+
* import { Effect } from "effect"
|
|
954
|
+
*
|
|
955
|
+
* const program = Effect.validate([0, 1, 2, 3], (n) =>
|
|
956
|
+
* n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
|
|
957
|
+
* )
|
|
958
|
+
*
|
|
959
|
+
* Effect.runPromiseExit(program).then(console.log)
|
|
960
|
+
* // {
|
|
961
|
+
* // _id: 'Exit',
|
|
962
|
+
* // _tag: 'Failure',
|
|
963
|
+
* // cause: {
|
|
964
|
+
* // _id: 'Cause',
|
|
965
|
+
* // reasons: [
|
|
966
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
|
|
967
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
|
|
968
|
+
* // ]
|
|
969
|
+
* // }
|
|
970
|
+
* // }
|
|
971
|
+
* ```
|
|
972
|
+
*
|
|
973
|
+
* @since 4.0.0
|
|
974
|
+
* @category Error Accumulation
|
|
975
|
+
*/
|
|
976
|
+
<A, B, E, R>(
|
|
977
|
+
f: (a: A, i: number) => Effect<B, E, R>,
|
|
978
|
+
options: {
|
|
979
|
+
readonly concurrency?: Concurrency | undefined
|
|
980
|
+
readonly discard: true
|
|
981
|
+
}
|
|
982
|
+
): (elements: Iterable<A>) => Effect<void, Arr.NonEmptyArray<E>, R>
|
|
983
|
+
/**
|
|
984
|
+
* Applies an effectful function to each element and accumulates all failures.
|
|
985
|
+
*
|
|
986
|
+
* This function always evaluates every element. If at least one effect fails,
|
|
987
|
+
* all failures are returned as a non-empty array and successes are discarded.
|
|
988
|
+
* If all effects succeed, it returns all collected successes.
|
|
989
|
+
*
|
|
990
|
+
* Use `discard: true` to ignore successful values while still validating all
|
|
991
|
+
* elements.
|
|
992
|
+
*
|
|
993
|
+
* @example
|
|
994
|
+
* ```ts
|
|
995
|
+
* import { Effect } from "effect"
|
|
996
|
+
*
|
|
997
|
+
* const program = Effect.validate([0, 1, 2, 3], (n) =>
|
|
998
|
+
* n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
|
|
999
|
+
* )
|
|
1000
|
+
*
|
|
1001
|
+
* Effect.runPromiseExit(program).then(console.log)
|
|
1002
|
+
* // {
|
|
1003
|
+
* // _id: 'Exit',
|
|
1004
|
+
* // _tag: 'Failure',
|
|
1005
|
+
* // cause: {
|
|
1006
|
+
* // _id: 'Cause',
|
|
1007
|
+
* // reasons: [
|
|
1008
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
|
|
1009
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
|
|
1010
|
+
* // ]
|
|
1011
|
+
* // }
|
|
1012
|
+
* // }
|
|
1013
|
+
* ```
|
|
1014
|
+
*
|
|
1015
|
+
* @since 4.0.0
|
|
1016
|
+
* @category Error Accumulation
|
|
1017
|
+
*/
|
|
1018
|
+
<A, B, E, R>(
|
|
1019
|
+
elements: Iterable<A>,
|
|
1020
|
+
f: (a: A, i: number) => Effect<B, E, R>,
|
|
1021
|
+
options?: {
|
|
1022
|
+
readonly concurrency?: Concurrency | undefined
|
|
1023
|
+
readonly discard?: false | undefined
|
|
1024
|
+
} | undefined
|
|
1025
|
+
): Effect<Array<B>, Arr.NonEmptyArray<E>, R>
|
|
1026
|
+
/**
|
|
1027
|
+
* Applies an effectful function to each element and accumulates all failures.
|
|
1028
|
+
*
|
|
1029
|
+
* This function always evaluates every element. If at least one effect fails,
|
|
1030
|
+
* all failures are returned as a non-empty array and successes are discarded.
|
|
1031
|
+
* If all effects succeed, it returns all collected successes.
|
|
1032
|
+
*
|
|
1033
|
+
* Use `discard: true` to ignore successful values while still validating all
|
|
1034
|
+
* elements.
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
* ```ts
|
|
1038
|
+
* import { Effect } from "effect"
|
|
1039
|
+
*
|
|
1040
|
+
* const program = Effect.validate([0, 1, 2, 3], (n) =>
|
|
1041
|
+
* n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
|
|
1042
|
+
* )
|
|
1043
|
+
*
|
|
1044
|
+
* Effect.runPromiseExit(program).then(console.log)
|
|
1045
|
+
* // {
|
|
1046
|
+
* // _id: 'Exit',
|
|
1047
|
+
* // _tag: 'Failure',
|
|
1048
|
+
* // cause: {
|
|
1049
|
+
* // _id: 'Cause',
|
|
1050
|
+
* // reasons: [
|
|
1051
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '0 is even' },
|
|
1052
|
+
* // { _id: 'Reason', _tag: 'Fail', error: '2 is even' }
|
|
1053
|
+
* // ]
|
|
1054
|
+
* // }
|
|
1055
|
+
* // }
|
|
1056
|
+
* ```
|
|
1057
|
+
*
|
|
1058
|
+
* @since 4.0.0
|
|
1059
|
+
* @category Error Accumulation
|
|
1060
|
+
*/
|
|
1061
|
+
<A, B, E, R>(
|
|
1062
|
+
elements: Iterable<A>,
|
|
1063
|
+
f: (a: A, i: number) => Effect<B, E, R>,
|
|
1064
|
+
options: {
|
|
1065
|
+
readonly concurrency?: Concurrency | undefined
|
|
1066
|
+
readonly discard: true
|
|
1067
|
+
}
|
|
1068
|
+
): Effect<void, Arr.NonEmptyArray<E>, R>
|
|
1069
|
+
} = internal.validate
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* Returns the first element that satisfies an effectful predicate.
|
|
1073
|
+
*
|
|
1074
|
+
* The predicate receives the element and its index. Evaluation short-circuits
|
|
1075
|
+
* as soon as an element matches.
|
|
1076
|
+
*
|
|
1077
|
+
* @example
|
|
1078
|
+
* ```ts
|
|
1079
|
+
* import { Effect } from "effect"
|
|
1080
|
+
*
|
|
1081
|
+
* const program = Effect.findFirst([1, 2, 3, 4], (n) => Effect.succeed(n > 2))
|
|
1082
|
+
*
|
|
1083
|
+
* Effect.runPromise(program).then(console.log)
|
|
1084
|
+
* // { _id: 'Option', _tag: 'Some', value: 3 }
|
|
1085
|
+
* ```
|
|
1086
|
+
*
|
|
1087
|
+
* @since 2.0.0
|
|
1088
|
+
* @category Collecting
|
|
1089
|
+
*/
|
|
1090
|
+
export const findFirst: {
|
|
1091
|
+
/**
|
|
1092
|
+
* Returns the first element that satisfies an effectful predicate.
|
|
1093
|
+
*
|
|
1094
|
+
* The predicate receives the element and its index. Evaluation short-circuits
|
|
1095
|
+
* as soon as an element matches.
|
|
1096
|
+
*
|
|
1097
|
+
* @example
|
|
1098
|
+
* ```ts
|
|
1099
|
+
* import { Effect } from "effect"
|
|
1100
|
+
*
|
|
1101
|
+
* const program = Effect.findFirst([1, 2, 3, 4], (n) => Effect.succeed(n > 2))
|
|
1102
|
+
*
|
|
1103
|
+
* Effect.runPromise(program).then(console.log)
|
|
1104
|
+
* // { _id: 'Option', _tag: 'Some', value: 3 }
|
|
1105
|
+
* ```
|
|
1106
|
+
*
|
|
1107
|
+
* @since 2.0.0
|
|
1108
|
+
* @category Collecting
|
|
1109
|
+
*/
|
|
1110
|
+
<A, E, R>(predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>): (elements: Iterable<A>) => Effect<Option<A>, E, R>
|
|
1111
|
+
/**
|
|
1112
|
+
* Returns the first element that satisfies an effectful predicate.
|
|
1113
|
+
*
|
|
1114
|
+
* The predicate receives the element and its index. Evaluation short-circuits
|
|
1115
|
+
* as soon as an element matches.
|
|
1116
|
+
*
|
|
1117
|
+
* @example
|
|
1118
|
+
* ```ts
|
|
1119
|
+
* import { Effect } from "effect"
|
|
1120
|
+
*
|
|
1121
|
+
* const program = Effect.findFirst([1, 2, 3, 4], (n) => Effect.succeed(n > 2))
|
|
1122
|
+
*
|
|
1123
|
+
* Effect.runPromise(program).then(console.log)
|
|
1124
|
+
* // { _id: 'Option', _tag: 'Some', value: 3 }
|
|
1125
|
+
* ```
|
|
1126
|
+
*
|
|
1127
|
+
* @since 2.0.0
|
|
1128
|
+
* @category Collecting
|
|
1129
|
+
*/
|
|
1130
|
+
<A, E, R>(
|
|
1131
|
+
elements: Iterable<A>,
|
|
1132
|
+
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>
|
|
1133
|
+
): Effect<Option<A>, E, R>
|
|
1134
|
+
} = internal.findFirst
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Returns the first value that passes an effectful `FilterEffect`.
|
|
1138
|
+
*
|
|
1139
|
+
* The filter receives the element and index. Evaluation short-circuits on the
|
|
1140
|
+
* first `Result.succeed` and returns the transformed value in `Option.some`.
|
|
1141
|
+
*
|
|
1142
|
+
* @since 4.0.0
|
|
1143
|
+
* @category Collecting
|
|
1144
|
+
*/
|
|
1145
|
+
export const findFirstFilter: {
|
|
1146
|
+
/**
|
|
1147
|
+
* Returns the first value that passes an effectful `FilterEffect`.
|
|
1148
|
+
*
|
|
1149
|
+
* The filter receives the element and index. Evaluation short-circuits on the
|
|
1150
|
+
* first `Result.succeed` and returns the transformed value in `Option.some`.
|
|
1151
|
+
*
|
|
1152
|
+
* @since 4.0.0
|
|
1153
|
+
* @category Collecting
|
|
1154
|
+
*/
|
|
1155
|
+
<A, B, X, E, R>(
|
|
1156
|
+
filter: (input: NoInfer<A>, i: number) => Effect<Result.Result<B, X>, E, R>
|
|
1157
|
+
): (elements: Iterable<A>) => Effect<Option<B>, E, R>
|
|
1158
|
+
/**
|
|
1159
|
+
* Returns the first value that passes an effectful `FilterEffect`.
|
|
1160
|
+
*
|
|
1161
|
+
* The filter receives the element and index. Evaluation short-circuits on the
|
|
1162
|
+
* first `Result.succeed` and returns the transformed value in `Option.some`.
|
|
1163
|
+
*
|
|
1164
|
+
* @since 4.0.0
|
|
1165
|
+
* @category Collecting
|
|
1166
|
+
*/
|
|
1167
|
+
<A, B, X, E, R>(
|
|
1168
|
+
elements: Iterable<A>,
|
|
1169
|
+
filter: (input: NoInfer<A>, i: number) => Effect<Result.Result<B, X>, E, R>
|
|
1170
|
+
): Effect<Option<B>, E, R>
|
|
1171
|
+
} = internal.findFirstFilter
|
|
1172
|
+
|
|
855
1173
|
/**
|
|
856
1174
|
* Executes an effectful operation for each element in an `Iterable`.
|
|
857
1175
|
*
|
|
@@ -1206,16 +1524,18 @@ export const promise: <A>(
|
|
|
1206
1524
|
*
|
|
1207
1525
|
* @example Custom Error Handling
|
|
1208
1526
|
* ```ts
|
|
1209
|
-
* import { Effect } from "effect"
|
|
1527
|
+
* import { Data, Effect } from "effect"
|
|
1528
|
+
*
|
|
1529
|
+
* class TodoFetchError extends Data.TaggedError("TodoFetchError")<{ readonly cause: unknown }> {}
|
|
1210
1530
|
*
|
|
1211
1531
|
* const getTodo = (id: number) =>
|
|
1212
1532
|
* Effect.tryPromise({
|
|
1213
1533
|
* try: () => fetch(`https://jsonplaceholder.typicode.com/todos/${id}`),
|
|
1214
1534
|
* // remap the error
|
|
1215
|
-
* catch: (
|
|
1535
|
+
* catch: (cause) => new TodoFetchError({ cause })
|
|
1216
1536
|
* })
|
|
1217
1537
|
*
|
|
1218
|
-
* // ┌─── Effect<Response,
|
|
1538
|
+
* // ┌─── Effect<Response, TodoFetchError, never>
|
|
1219
1539
|
* // ▼
|
|
1220
1540
|
* const program = getTodo(1)
|
|
1221
1541
|
* ```
|
|
@@ -1458,8 +1778,13 @@ export {
|
|
|
1458
1778
|
*
|
|
1459
1779
|
* **When to Use**
|
|
1460
1780
|
*
|
|
1461
|
-
* Use `Effect.
|
|
1781
|
+
* Use `Effect.callback` when dealing with APIs that use callback-style instead of
|
|
1462
1782
|
* `async/await` or `Promise`.
|
|
1783
|
+
* * **Previously Known As**
|
|
1784
|
+
*
|
|
1785
|
+
* This API replaces the following from Effect 3.x:
|
|
1786
|
+
*
|
|
1787
|
+
* - `Effect.async`
|
|
1463
1788
|
*
|
|
1464
1789
|
* @example
|
|
1465
1790
|
* ```ts
|
|
@@ -1512,48 +1837,147 @@ export const callback: <A, E = never, R = never>(
|
|
|
1512
1837
|
export const never: Effect<never> = internal.never
|
|
1513
1838
|
|
|
1514
1839
|
/**
|
|
1515
|
-
*
|
|
1516
|
-
*
|
|
1517
|
-
*
|
|
1518
|
-
* **When to Use**
|
|
1519
|
-
*
|
|
1520
|
-
* `gen` allows you to write code that looks and behaves like synchronous
|
|
1521
|
-
* code, but it can handle asynchronous tasks, errors, and complex control flow
|
|
1522
|
-
* (like loops and conditions). It helps make asynchronous code more readable
|
|
1523
|
-
* and easier to manage.
|
|
1524
|
-
*
|
|
1525
|
-
* The generator functions work similarly to `async/await` but with more
|
|
1526
|
-
* explicit control over the execution of effects. You can `yield*` values from
|
|
1527
|
-
* effects and return the final result at the end.
|
|
1840
|
+
* An `Effect` containing an empty record `{}`, used as the starting point for
|
|
1841
|
+
* do notation chains.
|
|
1528
1842
|
*
|
|
1529
1843
|
* @example
|
|
1530
1844
|
* ```ts
|
|
1531
1845
|
* import { Effect } from "effect"
|
|
1846
|
+
* import { pipe } from "effect/Function"
|
|
1532
1847
|
*
|
|
1533
|
-
* const
|
|
1534
|
-
*
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
1538
|
-
* )
|
|
1539
|
-
*
|
|
1540
|
-
*
|
|
1541
|
-
*
|
|
1542
|
-
*
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
*
|
|
1548
|
-
*
|
|
1549
|
-
*
|
|
1550
|
-
*
|
|
1551
|
-
*
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1848
|
+
* const program = pipe(
|
|
1849
|
+
* Effect.Do,
|
|
1850
|
+
* Effect.bind("x", () => Effect.succeed(2)),
|
|
1851
|
+
* Effect.bind("y", ({ x }) => Effect.succeed(x + 1)),
|
|
1852
|
+
* Effect.let("sum", ({ x, y }) => x + y)
|
|
1853
|
+
* )
|
|
1854
|
+
* ```
|
|
1855
|
+
*
|
|
1856
|
+
* @since 4.0.0
|
|
1857
|
+
* @category Do notation
|
|
1858
|
+
*/
|
|
1859
|
+
export const Do: Effect<{}> = internal.Do
|
|
1860
|
+
|
|
1861
|
+
/**
|
|
1862
|
+
* Gives a name to the success value of an `Effect`, creating a single-key
|
|
1863
|
+
* record used in do notation pipelines.
|
|
1864
|
+
*
|
|
1865
|
+
* @since 4.0.0
|
|
1866
|
+
* @category Do notation
|
|
1867
|
+
*/
|
|
1868
|
+
export const bindTo: {
|
|
1869
|
+
/**
|
|
1870
|
+
* Gives a name to the success value of an `Effect`, creating a single-key
|
|
1871
|
+
* record used in do notation pipelines.
|
|
1872
|
+
*
|
|
1873
|
+
* @since 4.0.0
|
|
1874
|
+
* @category Do notation
|
|
1875
|
+
*/
|
|
1876
|
+
<N extends string>(name: N): <A, E, R>(self: Effect<A, E, R>) => Effect<{ [K in N]: A }, E, R>
|
|
1877
|
+
/**
|
|
1878
|
+
* Gives a name to the success value of an `Effect`, creating a single-key
|
|
1879
|
+
* record used in do notation pipelines.
|
|
1880
|
+
*
|
|
1881
|
+
* @since 4.0.0
|
|
1882
|
+
* @category Do notation
|
|
1883
|
+
*/
|
|
1884
|
+
<A, E, R, N extends string>(self: Effect<A, E, R>, name: N): Effect<{ [K in N]: A }, E, R>
|
|
1885
|
+
} = internal.bindTo
|
|
1886
|
+
|
|
1887
|
+
const let_: {
|
|
1888
|
+
<N extends string, A extends Record<string, any>, B>(
|
|
1889
|
+
name: N,
|
|
1890
|
+
f: (a: NoInfer<A>) => B
|
|
1891
|
+
): <E, R>(
|
|
1892
|
+
self: Effect<A, E, R>
|
|
1893
|
+
) => Effect<Simplify<Omit<A, N> & Record<N, B>>, E, R>
|
|
1894
|
+
<A extends Record<string, any>, E, R, B, N extends string>(
|
|
1895
|
+
self: Effect<A, E, R>,
|
|
1896
|
+
name: N,
|
|
1897
|
+
f: (a: NoInfer<A>) => B
|
|
1898
|
+
): Effect<Simplify<Omit<A, N> & Record<N, B>>, E, R>
|
|
1899
|
+
} = internal.let
|
|
1900
|
+
|
|
1901
|
+
export {
|
|
1902
|
+
/**
|
|
1903
|
+
* Adds a computed plain value to the do notation record.
|
|
1904
|
+
*
|
|
1905
|
+
* @since 4.0.0
|
|
1906
|
+
* @category Do notation
|
|
1907
|
+
*/
|
|
1908
|
+
let_ as let
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
/**
|
|
1912
|
+
* Adds an `Effect` value to the do notation record under a given name.
|
|
1913
|
+
*
|
|
1914
|
+
* @since 4.0.0
|
|
1915
|
+
* @category Do notation
|
|
1916
|
+
*/
|
|
1917
|
+
export const bind: {
|
|
1918
|
+
/**
|
|
1919
|
+
* Adds an `Effect` value to the do notation record under a given name.
|
|
1920
|
+
*
|
|
1921
|
+
* @since 4.0.0
|
|
1922
|
+
* @category Do notation
|
|
1923
|
+
*/
|
|
1924
|
+
<N extends string, A extends Record<string, any>, B, E2, R2>(name: N, f: (a: NoInfer<A>) => Effect<B, E2, R2>): <E, R>(
|
|
1925
|
+
self: Effect<A, E, R>
|
|
1926
|
+
) => Effect<Simplify<Omit<A, N> & Record<N, B>>, E | E2, R | R2>
|
|
1927
|
+
/**
|
|
1928
|
+
* Adds an `Effect` value to the do notation record under a given name.
|
|
1929
|
+
*
|
|
1930
|
+
* @since 4.0.0
|
|
1931
|
+
* @category Do notation
|
|
1932
|
+
*/
|
|
1933
|
+
<A extends Record<string, any>, E, R, B, E2, R2, N extends string>(self: Effect<A, E, R>, name: N, f: (a: NoInfer<A>) => Effect<B, E2, R2>): Effect<Simplify<Omit<A, N> & Record<N, B>>, E | E2, R | R2>
|
|
1934
|
+
} = internal.bind
|
|
1935
|
+
|
|
1936
|
+
/**
|
|
1937
|
+
* Provides a way to write effectful code using generator functions, simplifying
|
|
1938
|
+
* control flow and error handling.
|
|
1939
|
+
*
|
|
1940
|
+
* **When to Use**
|
|
1941
|
+
*
|
|
1942
|
+
* `gen` allows you to write code that looks and behaves like synchronous
|
|
1943
|
+
* code, but it can handle asynchronous tasks, errors, and complex control flow
|
|
1944
|
+
* (like loops and conditions). It helps make asynchronous code more readable
|
|
1945
|
+
* and easier to manage.
|
|
1946
|
+
*
|
|
1947
|
+
* The generator functions work similarly to `async/await` but with more
|
|
1948
|
+
* explicit control over the execution of effects. You can `yield*` values from
|
|
1949
|
+
* effects and return the final result at the end.
|
|
1950
|
+
*
|
|
1951
|
+
* @example
|
|
1952
|
+
* ```ts
|
|
1953
|
+
* import { Data, Effect } from "effect"
|
|
1954
|
+
*
|
|
1955
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
1956
|
+
*
|
|
1957
|
+
* const addServiceCharge = (amount: number) => amount + 1
|
|
1958
|
+
*
|
|
1959
|
+
* const applyDiscount = (
|
|
1960
|
+
* total: number,
|
|
1961
|
+
* discountRate: number
|
|
1962
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
1963
|
+
* discountRate === 0
|
|
1964
|
+
* ? Effect.fail(new DiscountRateError())
|
|
1965
|
+
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
1966
|
+
*
|
|
1967
|
+
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
1968
|
+
*
|
|
1969
|
+
* const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
|
|
1970
|
+
*
|
|
1971
|
+
* export const program = Effect.gen(function*() {
|
|
1972
|
+
* const transactionAmount = yield* fetchTransactionAmount
|
|
1973
|
+
* const discountRate = yield* fetchDiscountRate
|
|
1974
|
+
* const discountedAmount = yield* applyDiscount(
|
|
1975
|
+
* transactionAmount,
|
|
1976
|
+
* discountRate
|
|
1977
|
+
* )
|
|
1978
|
+
* const finalAmount = addServiceCharge(discountedAmount)
|
|
1979
|
+
* return `Final amount to charge: ${finalAmount}`
|
|
1980
|
+
* })
|
|
1557
1981
|
* ```
|
|
1558
1982
|
*
|
|
1559
1983
|
* @since 2.0.0
|
|
@@ -1577,16 +2001,18 @@ export const gen: {
|
|
|
1577
2001
|
*
|
|
1578
2002
|
* @example
|
|
1579
2003
|
* ```ts
|
|
1580
|
-
* import { Effect } from "effect"
|
|
2004
|
+
* import { Data, Effect } from "effect"
|
|
2005
|
+
*
|
|
2006
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
1581
2007
|
*
|
|
1582
2008
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
1583
2009
|
*
|
|
1584
2010
|
* const applyDiscount = (
|
|
1585
2011
|
* total: number,
|
|
1586
2012
|
* discountRate: number
|
|
1587
|
-
* ): Effect.Effect<number,
|
|
2013
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
1588
2014
|
* discountRate === 0
|
|
1589
|
-
* ? Effect.fail(new
|
|
2015
|
+
* ? Effect.fail(new DiscountRateError())
|
|
1590
2016
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
1591
2017
|
*
|
|
1592
2018
|
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
@@ -1634,16 +2060,18 @@ export const gen: {
|
|
|
1634
2060
|
*
|
|
1635
2061
|
* @example
|
|
1636
2062
|
* ```ts
|
|
1637
|
-
* import { Effect } from "effect"
|
|
2063
|
+
* import { Data, Effect } from "effect"
|
|
2064
|
+
*
|
|
2065
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
1638
2066
|
*
|
|
1639
2067
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
1640
2068
|
*
|
|
1641
2069
|
* const applyDiscount = (
|
|
1642
2070
|
* total: number,
|
|
1643
2071
|
* discountRate: number
|
|
1644
|
-
* ): Effect.Effect<number,
|
|
2072
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
1645
2073
|
* discountRate === 0
|
|
1646
|
-
* ? Effect.fail(new
|
|
2074
|
+
* ? Effect.fail(new DiscountRateError())
|
|
1647
2075
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
1648
2076
|
*
|
|
1649
2077
|
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
@@ -1707,12 +2135,14 @@ export namespace gen {
|
|
|
1707
2135
|
* @example
|
|
1708
2136
|
* ```ts
|
|
1709
2137
|
* // Title: Creating a Failed Effect
|
|
1710
|
-
* import { Effect } from "effect"
|
|
2138
|
+
* import { Data, Effect } from "effect"
|
|
1711
2139
|
*
|
|
1712
|
-
*
|
|
2140
|
+
* class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
|
|
2141
|
+
*
|
|
2142
|
+
* // ┌─── Effect<never, OperationFailedError, never>
|
|
1713
2143
|
* // ▼
|
|
1714
2144
|
* const failure = Effect.fail(
|
|
1715
|
-
* new
|
|
2145
|
+
* new OperationFailedError()
|
|
1716
2146
|
* )
|
|
1717
2147
|
* ```
|
|
1718
2148
|
*
|
|
@@ -1729,9 +2159,11 @@ export const fail: <E>(error: E) => Effect<never, E> = internal.fail
|
|
|
1729
2159
|
*
|
|
1730
2160
|
* @example
|
|
1731
2161
|
* ```ts
|
|
1732
|
-
* import { Effect } from "effect"
|
|
2162
|
+
* import { Data, Effect } from "effect"
|
|
2163
|
+
*
|
|
2164
|
+
* class ProgramError extends Data.TaggedError("ProgramError")<{ readonly failedAt: Date }> {}
|
|
1733
2165
|
*
|
|
1734
|
-
* const program = Effect.failSync(() => new
|
|
2166
|
+
* const program = Effect.failSync(() => new ProgramError({ failedAt: new Date() }))
|
|
1735
2167
|
*
|
|
1736
2168
|
* Effect.runPromiseExit(program).then(console.log)
|
|
1737
2169
|
* // Output: { _id: 'Exit', _tag: 'Failure', cause: ... }
|
|
@@ -1885,12 +2317,14 @@ export {
|
|
|
1885
2317
|
*
|
|
1886
2318
|
* @example Custom Error Handling
|
|
1887
2319
|
* ```ts
|
|
1888
|
-
* import { Effect } from "effect"
|
|
2320
|
+
* import { Data, Effect } from "effect"
|
|
2321
|
+
*
|
|
2322
|
+
* class JsonParsingError extends Data.TaggedError("JsonParsingError")<{ readonly cause: unknown }> {}
|
|
1889
2323
|
*
|
|
1890
2324
|
* const parseJSON = (input: string) =>
|
|
1891
2325
|
* Effect.try({
|
|
1892
2326
|
* try: () => JSON.parse(input),
|
|
1893
|
-
* catch: (
|
|
2327
|
+
* catch: (cause) => new JsonParsingError({ cause })
|
|
1894
2328
|
* })
|
|
1895
2329
|
*
|
|
1896
2330
|
* Effect.runPromiseExit(parseJSON("invalid json")).then(console.log)
|
|
@@ -2027,17 +2461,17 @@ export const fromOption: <A>(
|
|
|
2027
2461
|
* ```ts
|
|
2028
2462
|
* import { Console, Effect } from "effect"
|
|
2029
2463
|
*
|
|
2030
|
-
* const input: string | null
|
|
2031
|
-
*
|
|
2032
|
-
* const program = Effect.gen(function*() {
|
|
2464
|
+
* const program = Effect.fn(function*(input: string | null) {
|
|
2033
2465
|
* const value = yield* Effect.fromNullishOr(input)
|
|
2034
2466
|
* yield* Console.log(value)
|
|
2035
|
-
* }
|
|
2467
|
+
* },
|
|
2036
2468
|
* Effect.catch(() => Console.log("missing"))
|
|
2037
2469
|
* )
|
|
2038
2470
|
*
|
|
2039
|
-
* Effect.runPromise(program)
|
|
2471
|
+
* Effect.runPromise(program(null))
|
|
2040
2472
|
* // Output: missing
|
|
2473
|
+
* Effect.runPromise(program("hello"))
|
|
2474
|
+
* // Output: hello
|
|
2041
2475
|
* ```
|
|
2042
2476
|
*
|
|
2043
2477
|
* @since 4.0.0
|
|
@@ -2106,15 +2540,17 @@ export const fromYieldable: <Self extends Yieldable.Any, A, E, R>(
|
|
|
2106
2540
|
*
|
|
2107
2541
|
* @example
|
|
2108
2542
|
* ```ts
|
|
2109
|
-
* import { Effect, pipe } from "effect"
|
|
2543
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2544
|
+
*
|
|
2545
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2110
2546
|
*
|
|
2111
2547
|
* // Function to apply a discount safely to a transaction amount
|
|
2112
2548
|
* const applyDiscount = (
|
|
2113
2549
|
* total: number,
|
|
2114
2550
|
* discountRate: number
|
|
2115
|
-
* ): Effect.Effect<number,
|
|
2551
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2116
2552
|
* discountRate === 0
|
|
2117
|
-
* ? Effect.fail(new
|
|
2553
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2118
2554
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2119
2555
|
*
|
|
2120
2556
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2172,15 +2608,17 @@ export const flatMap: {
|
|
|
2172
2608
|
*
|
|
2173
2609
|
* @example
|
|
2174
2610
|
* ```ts
|
|
2175
|
-
* import { Effect, pipe } from "effect"
|
|
2611
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2612
|
+
*
|
|
2613
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2176
2614
|
*
|
|
2177
2615
|
* // Function to apply a discount safely to a transaction amount
|
|
2178
2616
|
* const applyDiscount = (
|
|
2179
2617
|
* total: number,
|
|
2180
2618
|
* discountRate: number
|
|
2181
|
-
* ): Effect.Effect<number,
|
|
2619
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2182
2620
|
* discountRate === 0
|
|
2183
|
-
* ? Effect.fail(new
|
|
2621
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2184
2622
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2185
2623
|
*
|
|
2186
2624
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2238,15 +2676,17 @@ export const flatMap: {
|
|
|
2238
2676
|
*
|
|
2239
2677
|
* @example
|
|
2240
2678
|
* ```ts
|
|
2241
|
-
* import { Effect, pipe } from "effect"
|
|
2679
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2680
|
+
*
|
|
2681
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2242
2682
|
*
|
|
2243
2683
|
* // Function to apply a discount safely to a transaction amount
|
|
2244
2684
|
* const applyDiscount = (
|
|
2245
2685
|
* total: number,
|
|
2246
2686
|
* discountRate: number
|
|
2247
|
-
* ): Effect.Effect<number,
|
|
2687
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2248
2688
|
* discountRate === 0
|
|
2249
|
-
* ? Effect.fail(new
|
|
2689
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2250
2690
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2251
2691
|
*
|
|
2252
2692
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2334,15 +2774,17 @@ export const flatten: <A, E, R, E2, R2>(self: Effect<Effect<A, E, R>, E2, R2>) =
|
|
|
2334
2774
|
*
|
|
2335
2775
|
* @example Applying a Discount Based on Fetched Amount
|
|
2336
2776
|
* ```ts
|
|
2337
|
-
* import { Effect, pipe } from "effect"
|
|
2777
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2778
|
+
*
|
|
2779
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2338
2780
|
*
|
|
2339
2781
|
* // Function to apply a discount safely to a transaction amount
|
|
2340
2782
|
* const applyDiscount = (
|
|
2341
2783
|
* total: number,
|
|
2342
2784
|
* discountRate: number
|
|
2343
|
-
* ): Effect.Effect<number,
|
|
2785
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2344
2786
|
* discountRate === 0
|
|
2345
|
-
* ? Effect.fail(new
|
|
2787
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2346
2788
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2347
2789
|
*
|
|
2348
2790
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2415,15 +2857,17 @@ export const andThen: {
|
|
|
2415
2857
|
*
|
|
2416
2858
|
* @example Applying a Discount Based on Fetched Amount
|
|
2417
2859
|
* ```ts
|
|
2418
|
-
* import { Effect, pipe } from "effect"
|
|
2860
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2861
|
+
*
|
|
2862
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2419
2863
|
*
|
|
2420
2864
|
* // Function to apply a discount safely to a transaction amount
|
|
2421
2865
|
* const applyDiscount = (
|
|
2422
2866
|
* total: number,
|
|
2423
2867
|
* discountRate: number
|
|
2424
|
-
* ): Effect.Effect<number,
|
|
2868
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2425
2869
|
* discountRate === 0
|
|
2426
|
-
* ? Effect.fail(new
|
|
2870
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2427
2871
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2428
2872
|
*
|
|
2429
2873
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2496,15 +2940,17 @@ export const andThen: {
|
|
|
2496
2940
|
*
|
|
2497
2941
|
* @example Applying a Discount Based on Fetched Amount
|
|
2498
2942
|
* ```ts
|
|
2499
|
-
* import { Effect, pipe } from "effect"
|
|
2943
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2944
|
+
*
|
|
2945
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2500
2946
|
*
|
|
2501
2947
|
* // Function to apply a discount safely to a transaction amount
|
|
2502
2948
|
* const applyDiscount = (
|
|
2503
2949
|
* total: number,
|
|
2504
2950
|
* discountRate: number
|
|
2505
|
-
* ): Effect.Effect<number,
|
|
2951
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2506
2952
|
* discountRate === 0
|
|
2507
|
-
* ? Effect.fail(new
|
|
2953
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2508
2954
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2509
2955
|
*
|
|
2510
2956
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2577,15 +3023,17 @@ export const andThen: {
|
|
|
2577
3023
|
*
|
|
2578
3024
|
* @example Applying a Discount Based on Fetched Amount
|
|
2579
3025
|
* ```ts
|
|
2580
|
-
* import { Effect, pipe } from "effect"
|
|
3026
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3027
|
+
*
|
|
3028
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2581
3029
|
*
|
|
2582
3030
|
* // Function to apply a discount safely to a transaction amount
|
|
2583
3031
|
* const applyDiscount = (
|
|
2584
3032
|
* total: number,
|
|
2585
3033
|
* discountRate: number
|
|
2586
|
-
* ): Effect.Effect<number,
|
|
3034
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2587
3035
|
* discountRate === 0
|
|
2588
|
-
* ? Effect.fail(new
|
|
3036
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2589
3037
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2590
3038
|
*
|
|
2591
3039
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2658,15 +3106,17 @@ export const andThen: {
|
|
|
2658
3106
|
*
|
|
2659
3107
|
* @example Applying a Discount Based on Fetched Amount
|
|
2660
3108
|
* ```ts
|
|
2661
|
-
* import { Effect, pipe } from "effect"
|
|
3109
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3110
|
+
*
|
|
3111
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2662
3112
|
*
|
|
2663
3113
|
* // Function to apply a discount safely to a transaction amount
|
|
2664
3114
|
* const applyDiscount = (
|
|
2665
3115
|
* total: number,
|
|
2666
3116
|
* discountRate: number
|
|
2667
|
-
* ): Effect.Effect<number,
|
|
3117
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2668
3118
|
* discountRate === 0
|
|
2669
|
-
* ? Effect.fail(new
|
|
3119
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2670
3120
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2671
3121
|
*
|
|
2672
3122
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2725,16 +3175,18 @@ export const andThen: {
|
|
|
2725
3175
|
* @example
|
|
2726
3176
|
* ```ts
|
|
2727
3177
|
* // Title: Logging a step in a pipeline
|
|
2728
|
-
* import { Effect, pipe } from "effect"
|
|
3178
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2729
3179
|
* import { Console } from "effect"
|
|
2730
3180
|
*
|
|
3181
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3182
|
+
*
|
|
2731
3183
|
* // Function to apply a discount safely to a transaction amount
|
|
2732
3184
|
* const applyDiscount = (
|
|
2733
3185
|
* total: number,
|
|
2734
3186
|
* discountRate: number
|
|
2735
|
-
* ): Effect.Effect<number,
|
|
3187
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2736
3188
|
* discountRate === 0
|
|
2737
|
-
* ? Effect.fail(new
|
|
3189
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2738
3190
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2739
3191
|
*
|
|
2740
3192
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2784,16 +3236,18 @@ export const tap: {
|
|
|
2784
3236
|
* @example
|
|
2785
3237
|
* ```ts
|
|
2786
3238
|
* // Title: Logging a step in a pipeline
|
|
2787
|
-
* import { Effect, pipe } from "effect"
|
|
3239
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2788
3240
|
* import { Console } from "effect"
|
|
2789
3241
|
*
|
|
3242
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3243
|
+
*
|
|
2790
3244
|
* // Function to apply a discount safely to a transaction amount
|
|
2791
3245
|
* const applyDiscount = (
|
|
2792
3246
|
* total: number,
|
|
2793
3247
|
* discountRate: number
|
|
2794
|
-
* ): Effect.Effect<number,
|
|
3248
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2795
3249
|
* discountRate === 0
|
|
2796
|
-
* ? Effect.fail(new
|
|
3250
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2797
3251
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2798
3252
|
*
|
|
2799
3253
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2843,16 +3297,18 @@ export const tap: {
|
|
|
2843
3297
|
* @example
|
|
2844
3298
|
* ```ts
|
|
2845
3299
|
* // Title: Logging a step in a pipeline
|
|
2846
|
-
* import { Effect, pipe } from "effect"
|
|
3300
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2847
3301
|
* import { Console } from "effect"
|
|
2848
3302
|
*
|
|
3303
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3304
|
+
*
|
|
2849
3305
|
* // Function to apply a discount safely to a transaction amount
|
|
2850
3306
|
* const applyDiscount = (
|
|
2851
3307
|
* total: number,
|
|
2852
3308
|
* discountRate: number
|
|
2853
|
-
* ): Effect.Effect<number,
|
|
3309
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2854
3310
|
* discountRate === 0
|
|
2855
|
-
* ? Effect.fail(new
|
|
3311
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2856
3312
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2857
3313
|
*
|
|
2858
3314
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2902,16 +3358,18 @@ export const tap: {
|
|
|
2902
3358
|
* @example
|
|
2903
3359
|
* ```ts
|
|
2904
3360
|
* // Title: Logging a step in a pipeline
|
|
2905
|
-
* import { Effect, pipe } from "effect"
|
|
3361
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2906
3362
|
* import { Console } from "effect"
|
|
2907
3363
|
*
|
|
3364
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3365
|
+
*
|
|
2908
3366
|
* // Function to apply a discount safely to a transaction amount
|
|
2909
3367
|
* const applyDiscount = (
|
|
2910
3368
|
* total: number,
|
|
2911
3369
|
* discountRate: number
|
|
2912
|
-
* ): Effect.Effect<number,
|
|
3370
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2913
3371
|
* discountRate === 0
|
|
2914
|
-
* ? Effect.fail(new
|
|
3372
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2915
3373
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2916
3374
|
*
|
|
2917
3375
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2961,16 +3419,18 @@ export const tap: {
|
|
|
2961
3419
|
* @example
|
|
2962
3420
|
* ```ts
|
|
2963
3421
|
* // Title: Logging a step in a pipeline
|
|
2964
|
-
* import { Effect, pipe } from "effect"
|
|
3422
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2965
3423
|
* import { Console } from "effect"
|
|
2966
3424
|
*
|
|
3425
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3426
|
+
*
|
|
2967
3427
|
* // Function to apply a discount safely to a transaction amount
|
|
2968
3428
|
* const applyDiscount = (
|
|
2969
3429
|
* total: number,
|
|
2970
3430
|
* discountRate: number
|
|
2971
|
-
* ): Effect.Effect<number,
|
|
3431
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2972
3432
|
* discountRate === 0
|
|
2973
|
-
* ? Effect.fail(new
|
|
3433
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2974
3434
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2975
3435
|
*
|
|
2976
3436
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3985,7 +4445,8 @@ export const catchTag: {
|
|
|
3985
4445
|
* once. Instead of using {@link catchTag} multiple times, you can pass an
|
|
3986
4446
|
* object where each key is an error type's `_tag`, and the value is the handler
|
|
3987
4447
|
* for that specific error. This allows you to catch and recover from multiple
|
|
3988
|
-
* error types in a single call.
|
|
4448
|
+
* error types in a single call. You can also provide a fallback handler for
|
|
4449
|
+
* unhandled errors.
|
|
3989
4450
|
*
|
|
3990
4451
|
* The error type must have a readonly `_tag` field to use `catchTag`. This
|
|
3991
4452
|
* field is used to identify and match errors.
|
|
@@ -4027,7 +4488,8 @@ export const catchTags: {
|
|
|
4027
4488
|
* once. Instead of using {@link catchTag} multiple times, you can pass an
|
|
4028
4489
|
* object where each key is an error type's `_tag`, and the value is the handler
|
|
4029
4490
|
* for that specific error. This allows you to catch and recover from multiple
|
|
4030
|
-
* error types in a single call.
|
|
4491
|
+
* error types in a single call. You can also provide a fallback handler for
|
|
4492
|
+
* unhandled errors.
|
|
4031
4493
|
*
|
|
4032
4494
|
* The error type must have a readonly `_tag` field to use `catchTag`. This
|
|
4033
4495
|
* field is used to identify and match errors.
|
|
@@ -4063,19 +4525,27 @@ export const catchTags: {
|
|
|
4063
4525
|
E,
|
|
4064
4526
|
Cases extends
|
|
4065
4527
|
& { [K in Extract<E, { _tag: string }>["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Effect<any, any, any>) }
|
|
4066
|
-
& (unknown extends E ? {} : { [K in Exclude<keyof Cases, Extract<E, { _tag: string }>["_tag"]>]: never })
|
|
4067
|
-
|
|
4528
|
+
& (unknown extends E ? {} : { [K in Exclude<keyof Cases, Extract<E, { _tag: string }>["_tag"]>]: never }),
|
|
4529
|
+
A2 = never,
|
|
4530
|
+
E2 = Exclude<E, { _tag: keyof Cases }>,
|
|
4531
|
+
R2 = never
|
|
4532
|
+
>(
|
|
4533
|
+
cases: Cases,
|
|
4534
|
+
orElse?: ((e: Exclude<E, { _tag: keyof Cases }>) => Effect<A2, E2, R2>) | undefined
|
|
4535
|
+
): <A, R>(
|
|
4068
4536
|
self: Effect<A, E, R>
|
|
4069
4537
|
) => Effect<
|
|
4070
4538
|
| A
|
|
4539
|
+
| A2
|
|
4071
4540
|
| {
|
|
4072
4541
|
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect<infer A, any, any> ? A : never
|
|
4073
4542
|
}[keyof Cases],
|
|
4074
|
-
|
|
|
4543
|
+
| E2
|
|
4075
4544
|
| {
|
|
4076
4545
|
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect<any, infer E, any> ? E : never
|
|
4077
4546
|
}[keyof Cases],
|
|
4078
4547
|
| R
|
|
4548
|
+
| R2
|
|
4079
4549
|
| {
|
|
4080
4550
|
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect<any, any, infer R> ? R : never
|
|
4081
4551
|
}[keyof Cases]
|
|
@@ -4089,7 +4559,8 @@ export const catchTags: {
|
|
|
4089
4559
|
* once. Instead of using {@link catchTag} multiple times, you can pass an
|
|
4090
4560
|
* object where each key is an error type's `_tag`, and the value is the handler
|
|
4091
4561
|
* for that specific error. This allows you to catch and recover from multiple
|
|
4092
|
-
* error types in a single call.
|
|
4562
|
+
* error types in a single call. You can also provide a fallback handler for
|
|
4563
|
+
* unhandled errors.
|
|
4093
4564
|
*
|
|
4094
4565
|
* The error type must have a readonly `_tag` field to use `catchTag`. This
|
|
4095
4566
|
* field is used to identify and match errors.
|
|
@@ -4127,17 +4598,26 @@ export const catchTags: {
|
|
|
4127
4598
|
A,
|
|
4128
4599
|
Cases extends
|
|
4129
4600
|
& { [K in Extract<E, { _tag: string }>["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Effect<any, any, any>) }
|
|
4130
|
-
& (unknown extends E ? {} : { [K in Exclude<keyof Cases, Extract<E, { _tag: string }>["_tag"]>]: never })
|
|
4131
|
-
|
|
4601
|
+
& (unknown extends E ? {} : { [K in Exclude<keyof Cases, Extract<E, { _tag: string }>["_tag"]>]: never }),
|
|
4602
|
+
A2 = never,
|
|
4603
|
+
E2 = Exclude<E, { _tag: keyof Cases }>,
|
|
4604
|
+
R2 = never
|
|
4605
|
+
>(
|
|
4606
|
+
self: Effect<A, E, R>,
|
|
4607
|
+
cases: Cases,
|
|
4608
|
+
orElse?: ((e: Exclude<E, { _tag: keyof Cases }>) => Effect<A2, E2, R2>) | undefined
|
|
4609
|
+
): Effect<
|
|
4132
4610
|
| A
|
|
4611
|
+
| A2
|
|
4133
4612
|
| {
|
|
4134
4613
|
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect<infer A, any, any> ? A : never
|
|
4135
4614
|
}[keyof Cases],
|
|
4136
|
-
|
|
|
4615
|
+
| E2
|
|
4137
4616
|
| {
|
|
4138
4617
|
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect<any, infer E, any> ? E : never
|
|
4139
4618
|
}[keyof Cases],
|
|
4140
4619
|
| R
|
|
4620
|
+
| R2
|
|
4141
4621
|
| {
|
|
4142
4622
|
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect<any, any, infer R> ? R : never
|
|
4143
4623
|
}[keyof Cases]
|
|
@@ -4228,8 +4708,16 @@ export const catchReason: {
|
|
|
4228
4708
|
>(
|
|
4229
4709
|
errorTag: K,
|
|
4230
4710
|
reasonTag: RK,
|
|
4231
|
-
f: (
|
|
4232
|
-
|
|
4711
|
+
f: (
|
|
4712
|
+
reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>,
|
|
4713
|
+
error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
|
|
4714
|
+
) => Effect<A2, E2, R2>,
|
|
4715
|
+
orElse?:
|
|
4716
|
+
| ((
|
|
4717
|
+
reasons: ExcludeReason<ExtractTag<NoInfer<E>, K>, RK>,
|
|
4718
|
+
error: OmitReason<ExtractTag<NoInfer<E>, K>, RK>
|
|
4719
|
+
) => Effect<A3, E3, R3>)
|
|
4720
|
+
| undefined
|
|
4233
4721
|
): <A, R>(
|
|
4234
4722
|
self: Effect<A, E, R>
|
|
4235
4723
|
) => Effect<A | A2 | Exclude<A3, unassigned>, (A3 extends unassigned ? E : ExcludeTag<E, K>) | E2 | E3, R | R2 | R3>
|
|
@@ -4284,8 +4772,10 @@ export const catchReason: {
|
|
|
4284
4772
|
self: Effect<A, E, R>,
|
|
4285
4773
|
errorTag: K,
|
|
4286
4774
|
reasonTag: RK,
|
|
4287
|
-
f: (reason: ExtractReason<ExtractTag<E, K>, RK>) => Effect<A2, E2, R2>,
|
|
4288
|
-
orElse?:
|
|
4775
|
+
f: (reason: ExtractReason<ExtractTag<E, K>, RK>, error: NarrowReason<ExtractTag<E, K>, RK>) => Effect<A2, E2, R2>,
|
|
4776
|
+
orElse?:
|
|
4777
|
+
| ((reasons: ExcludeReason<ExtractTag<E, K>, RK>, error: OmitReason<ExtractTag<E, K>, RK>) => Effect<A3, E3, R3>)
|
|
4778
|
+
| undefined
|
|
4289
4779
|
): Effect<A | A2 | Exclude<A3, unassigned>, (A3 extends unassigned ? E : ExcludeTag<E, K>) | E2 | E3, R | R2 | R3>
|
|
4290
4780
|
} = internal.catchReason
|
|
4291
4781
|
|
|
@@ -4363,7 +4853,8 @@ export const catchReasons: {
|
|
|
4363
4853
|
E,
|
|
4364
4854
|
Cases extends {
|
|
4365
4855
|
[RK in ReasonTags<ExtractTag<NoInfer<E>, K>>]+?: (
|
|
4366
|
-
reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK
|
|
4856
|
+
reason: ExtractReason<ExtractTag<NoInfer<E>, K>, RK>,
|
|
4857
|
+
error: NarrowReason<ExtractTag<NoInfer<E>, K>, RK>
|
|
4367
4858
|
) => Effect<any, any, any>
|
|
4368
4859
|
},
|
|
4369
4860
|
A2 = unassigned,
|
|
@@ -4373,7 +4864,10 @@ export const catchReasons: {
|
|
|
4373
4864
|
errorTag: K,
|
|
4374
4865
|
cases: Cases,
|
|
4375
4866
|
orElse?:
|
|
4376
|
-
| ((
|
|
4867
|
+
| ((
|
|
4868
|
+
reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>,
|
|
4869
|
+
error: OmitReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
|
|
4870
|
+
) => Effect<A2, E2, R2>)
|
|
4377
4871
|
| undefined
|
|
4378
4872
|
): <A, R>(
|
|
4379
4873
|
self: Effect<A, E, R>
|
|
@@ -4434,7 +4928,10 @@ export const catchReasons: {
|
|
|
4434
4928
|
R,
|
|
4435
4929
|
K extends Tags<E>,
|
|
4436
4930
|
Cases extends {
|
|
4437
|
-
[RK in ReasonTags<ExtractTag<E, K>>]+?: (
|
|
4931
|
+
[RK in ReasonTags<ExtractTag<E, K>>]+?: (
|
|
4932
|
+
reason: ExtractReason<ExtractTag<E, K>, RK>,
|
|
4933
|
+
error: NarrowReason<ExtractTag<E, K>, RK>
|
|
4934
|
+
) => Effect<any, any, any>
|
|
4438
4935
|
},
|
|
4439
4936
|
A2 = unassigned,
|
|
4440
4937
|
E2 = never,
|
|
@@ -4444,7 +4941,10 @@ export const catchReasons: {
|
|
|
4444
4941
|
errorTag: K,
|
|
4445
4942
|
cases: Cases,
|
|
4446
4943
|
orElse?:
|
|
4447
|
-
| ((
|
|
4944
|
+
| ((
|
|
4945
|
+
reason: ExcludeReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>,
|
|
4946
|
+
error: OmitReason<ExtractTag<NoInfer<E>, K>, Extract<keyof Cases, string>>
|
|
4947
|
+
) => Effect<A2, E2, R2>)
|
|
4448
4948
|
| undefined
|
|
4449
4949
|
): Effect<
|
|
4450
4950
|
| A
|
|
@@ -4870,15 +5370,14 @@ export const catchDefect: {
|
|
|
4870
5370
|
} = internal.catchDefect
|
|
4871
5371
|
|
|
4872
5372
|
/**
|
|
4873
|
-
* Recovers from specific errors using a `
|
|
4874
|
-
* `Refinement`.
|
|
5373
|
+
* Recovers from specific errors using a `Predicate` or `Refinement`.
|
|
4875
5374
|
*
|
|
4876
5375
|
* **When to Use**
|
|
4877
5376
|
*
|
|
4878
|
-
* `catchIf` lets you recover from errors that match a condition.
|
|
4879
|
-
* `
|
|
4880
|
-
*
|
|
4881
|
-
*
|
|
5377
|
+
* `catchIf` lets you recover from errors that match a condition. Use a
|
|
5378
|
+
* `Refinement` for type narrowing or a `Predicate` for simple boolean
|
|
5379
|
+
* matching. Non-matching errors re-fail with the original cause. Defects and
|
|
5380
|
+
* interrupts are not caught.
|
|
4882
5381
|
*
|
|
4883
5382
|
* **Previously Known As**
|
|
4884
5383
|
*
|
|
@@ -4905,7 +5404,7 @@ export const catchDefect: {
|
|
|
4905
5404
|
*
|
|
4906
5405
|
* // With a Filter
|
|
4907
5406
|
* const recovered2 = program.pipe(
|
|
4908
|
-
* Effect.
|
|
5407
|
+
* Effect.catchFilter(
|
|
4909
5408
|
* Filter.tagged("NotFound"),
|
|
4910
5409
|
* (error) => Effect.succeed(`missing:${error.id}`)
|
|
4911
5410
|
* )
|
|
@@ -4917,15 +5416,14 @@ export const catchDefect: {
|
|
|
4917
5416
|
*/
|
|
4918
5417
|
export const catchIf: {
|
|
4919
5418
|
/**
|
|
4920
|
-
* Recovers from specific errors using a `
|
|
4921
|
-
* `Refinement`.
|
|
5419
|
+
* Recovers from specific errors using a `Predicate` or `Refinement`.
|
|
4922
5420
|
*
|
|
4923
5421
|
* **When to Use**
|
|
4924
5422
|
*
|
|
4925
|
-
* `catchIf` lets you recover from errors that match a condition.
|
|
4926
|
-
* `
|
|
4927
|
-
*
|
|
4928
|
-
*
|
|
5423
|
+
* `catchIf` lets you recover from errors that match a condition. Use a
|
|
5424
|
+
* `Refinement` for type narrowing or a `Predicate` for simple boolean
|
|
5425
|
+
* matching. Non-matching errors re-fail with the original cause. Defects and
|
|
5426
|
+
* interrupts are not caught.
|
|
4929
5427
|
*
|
|
4930
5428
|
* **Previously Known As**
|
|
4931
5429
|
*
|
|
@@ -4952,7 +5450,7 @@ export const catchIf: {
|
|
|
4952
5450
|
*
|
|
4953
5451
|
* // With a Filter
|
|
4954
5452
|
* const recovered2 = program.pipe(
|
|
4955
|
-
* Effect.
|
|
5453
|
+
* Effect.catchFilter(
|
|
4956
5454
|
* Filter.tagged("NotFound"),
|
|
4957
5455
|
* (error) => Effect.succeed(`missing:${error.id}`)
|
|
4958
5456
|
* )
|
|
@@ -4968,15 +5466,14 @@ export const catchIf: {
|
|
|
4968
5466
|
orElse?: ((e: Exclude<E, EB>) => Effect<A3, E3, R3>) | undefined
|
|
4969
5467
|
): <A, R>(self: Effect<A, E, R>) => Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
|
|
4970
5468
|
/**
|
|
4971
|
-
* Recovers from specific errors using a `
|
|
4972
|
-
* `Refinement`.
|
|
5469
|
+
* Recovers from specific errors using a `Predicate` or `Refinement`.
|
|
4973
5470
|
*
|
|
4974
5471
|
* **When to Use**
|
|
4975
5472
|
*
|
|
4976
|
-
* `catchIf` lets you recover from errors that match a condition.
|
|
4977
|
-
* `
|
|
4978
|
-
*
|
|
4979
|
-
*
|
|
5473
|
+
* `catchIf` lets you recover from errors that match a condition. Use a
|
|
5474
|
+
* `Refinement` for type narrowing or a `Predicate` for simple boolean
|
|
5475
|
+
* matching. Non-matching errors re-fail with the original cause. Defects and
|
|
5476
|
+
* interrupts are not caught.
|
|
4980
5477
|
*
|
|
4981
5478
|
* **Previously Known As**
|
|
4982
5479
|
*
|
|
@@ -5003,7 +5500,7 @@ export const catchIf: {
|
|
|
5003
5500
|
*
|
|
5004
5501
|
* // With a Filter
|
|
5005
5502
|
* const recovered2 = program.pipe(
|
|
5006
|
-
* Effect.
|
|
5503
|
+
* Effect.catchFilter(
|
|
5007
5504
|
* Filter.tagged("NotFound"),
|
|
5008
5505
|
* (error) => Effect.succeed(`missing:${error.id}`)
|
|
5009
5506
|
* )
|
|
@@ -5013,21 +5510,20 @@ export const catchIf: {
|
|
|
5013
5510
|
* @since 2.0.0
|
|
5014
5511
|
* @category Error Handling
|
|
5015
5512
|
*/
|
|
5016
|
-
<E,
|
|
5017
|
-
|
|
5018
|
-
f: (e:
|
|
5019
|
-
orElse?: ((e:
|
|
5513
|
+
<E, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
|
|
5514
|
+
predicate: Predicate.Predicate<NoInfer<E>>,
|
|
5515
|
+
f: (e: NoInfer<E>) => Effect<A2, E2, R2>,
|
|
5516
|
+
orElse?: ((e: NoInfer<E>) => Effect<A3, E3, R3>) | undefined
|
|
5020
5517
|
): <A, R>(self: Effect<A, E, R>) => Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
|
|
5021
5518
|
/**
|
|
5022
|
-
* Recovers from specific errors using a `
|
|
5023
|
-
* `Refinement`.
|
|
5519
|
+
* Recovers from specific errors using a `Predicate` or `Refinement`.
|
|
5024
5520
|
*
|
|
5025
5521
|
* **When to Use**
|
|
5026
5522
|
*
|
|
5027
|
-
* `catchIf` lets you recover from errors that match a condition.
|
|
5028
|
-
* `
|
|
5029
|
-
*
|
|
5030
|
-
*
|
|
5523
|
+
* `catchIf` lets you recover from errors that match a condition. Use a
|
|
5524
|
+
* `Refinement` for type narrowing or a `Predicate` for simple boolean
|
|
5525
|
+
* matching. Non-matching errors re-fail with the original cause. Defects and
|
|
5526
|
+
* interrupts are not caught.
|
|
5031
5527
|
*
|
|
5032
5528
|
* **Previously Known As**
|
|
5033
5529
|
*
|
|
@@ -5054,7 +5550,7 @@ export const catchIf: {
|
|
|
5054
5550
|
*
|
|
5055
5551
|
* // With a Filter
|
|
5056
5552
|
* const recovered2 = program.pipe(
|
|
5057
|
-
* Effect.
|
|
5553
|
+
* Effect.catchFilter(
|
|
5058
5554
|
* Filter.tagged("NotFound"),
|
|
5059
5555
|
* (error) => Effect.succeed(`missing:${error.id}`)
|
|
5060
5556
|
* )
|
|
@@ -5071,15 +5567,14 @@ export const catchIf: {
|
|
|
5071
5567
|
orElse?: ((e: Exclude<E, EB>) => Effect<A3, E3, R3>) | undefined
|
|
5072
5568
|
): Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
|
|
5073
5569
|
/**
|
|
5074
|
-
* Recovers from specific errors using a `
|
|
5075
|
-
* `Refinement`.
|
|
5570
|
+
* Recovers from specific errors using a `Predicate` or `Refinement`.
|
|
5076
5571
|
*
|
|
5077
5572
|
* **When to Use**
|
|
5078
5573
|
*
|
|
5079
|
-
* `catchIf` lets you recover from errors that match a condition.
|
|
5080
|
-
* `
|
|
5081
|
-
*
|
|
5082
|
-
*
|
|
5574
|
+
* `catchIf` lets you recover from errors that match a condition. Use a
|
|
5575
|
+
* `Refinement` for type narrowing or a `Predicate` for simple boolean
|
|
5576
|
+
* matching. Non-matching errors re-fail with the original cause. Defects and
|
|
5577
|
+
* interrupts are not caught.
|
|
5083
5578
|
*
|
|
5084
5579
|
* **Previously Known As**
|
|
5085
5580
|
*
|
|
@@ -5106,7 +5601,7 @@ export const catchIf: {
|
|
|
5106
5601
|
*
|
|
5107
5602
|
* // With a Filter
|
|
5108
5603
|
* const recovered2 = program.pipe(
|
|
5109
|
-
* Effect.
|
|
5604
|
+
* Effect.catchFilter(
|
|
5110
5605
|
* Filter.tagged("NotFound"),
|
|
5111
5606
|
* (error) => Effect.succeed(`missing:${error.id}`)
|
|
5112
5607
|
* )
|
|
@@ -5116,14 +5611,46 @@ export const catchIf: {
|
|
|
5116
5611
|
* @since 2.0.0
|
|
5117
5612
|
* @category Error Handling
|
|
5118
5613
|
*/
|
|
5119
|
-
<A, E, R,
|
|
5614
|
+
<A, E, R, A2, E2, R2, A3 = never, E3 = E, R3 = never>(
|
|
5120
5615
|
self: Effect<A, E, R>,
|
|
5121
|
-
|
|
5122
|
-
f: (e:
|
|
5123
|
-
orElse?: ((e:
|
|
5616
|
+
predicate: Predicate.Predicate<E>,
|
|
5617
|
+
f: (e: E) => Effect<A2, E2, R2>,
|
|
5618
|
+
orElse?: ((e: E) => Effect<A3, E3, R3>) | undefined
|
|
5124
5619
|
): Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
|
|
5125
5620
|
} = internal.catchIf
|
|
5126
5621
|
|
|
5622
|
+
/**
|
|
5623
|
+
* Recovers from specific errors using a `Filter`.
|
|
5624
|
+
*
|
|
5625
|
+
* @since 4.0.0
|
|
5626
|
+
* @category Error Handling
|
|
5627
|
+
*/
|
|
5628
|
+
export const catchFilter: {
|
|
5629
|
+
/**
|
|
5630
|
+
* Recovers from specific errors using a `Filter`.
|
|
5631
|
+
*
|
|
5632
|
+
* @since 4.0.0
|
|
5633
|
+
* @category Error Handling
|
|
5634
|
+
*/
|
|
5635
|
+
<E, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
|
|
5636
|
+
filter: Filter.Filter<NoInfer<E>, EB, X>,
|
|
5637
|
+
f: (e: EB) => Effect<A2, E2, R2>,
|
|
5638
|
+
orElse?: ((e: X) => Effect<A3, E3, R3>) | undefined
|
|
5639
|
+
): <A, R>(self: Effect<A, E, R>) => Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
|
|
5640
|
+
/**
|
|
5641
|
+
* Recovers from specific errors using a `Filter`.
|
|
5642
|
+
*
|
|
5643
|
+
* @since 4.0.0
|
|
5644
|
+
* @category Error Handling
|
|
5645
|
+
*/
|
|
5646
|
+
<A, E, R, EB, A2, E2, R2, X, A3 = never, E3 = X, R3 = never>(
|
|
5647
|
+
self: Effect<A, E, R>,
|
|
5648
|
+
filter: Filter.Filter<NoInfer<E>, EB, X>,
|
|
5649
|
+
f: (e: EB) => Effect<A2, E2, R2>,
|
|
5650
|
+
orElse?: ((e: X) => Effect<A3, E3, R3>) | undefined
|
|
5651
|
+
): Effect<A | A2 | A3, E2 | E3, R | R2 | R3>
|
|
5652
|
+
} = internal.catchFilter
|
|
5653
|
+
|
|
5127
5654
|
/**
|
|
5128
5655
|
* Catches `NoSuchElementError` failures and converts them to `Option.none`.
|
|
5129
5656
|
*
|
|
@@ -5231,10 +5758,10 @@ export const catchCauseIf: {
|
|
|
5231
5758
|
* @since 4.0.0
|
|
5232
5759
|
* @category Error Handling
|
|
5233
5760
|
*/
|
|
5234
|
-
<E,
|
|
5235
|
-
|
|
5236
|
-
f: (
|
|
5237
|
-
): <A, R>(self: Effect<A, E, R>) => Effect<A | B,
|
|
5761
|
+
<E, B, E2, R2>(
|
|
5762
|
+
predicate: Predicate.Predicate<Cause.Cause<E>>,
|
|
5763
|
+
f: (cause: Cause.Cause<E>) => Effect<B, E2, R2>
|
|
5764
|
+
): <A, R>(self: Effect<A, E, R>) => Effect<A | B, E | E2, R | R2>
|
|
5238
5765
|
/**
|
|
5239
5766
|
* Recovers from specific failures based on a predicate.
|
|
5240
5767
|
*
|
|
@@ -5273,13 +5800,43 @@ export const catchCauseIf: {
|
|
|
5273
5800
|
* @since 4.0.0
|
|
5274
5801
|
* @category Error Handling
|
|
5275
5802
|
*/
|
|
5276
|
-
<A, E, R, B, E2, R2
|
|
5803
|
+
<A, E, R, B, E2, R2>(
|
|
5277
5804
|
self: Effect<A, E, R>,
|
|
5278
|
-
|
|
5279
|
-
f: (
|
|
5280
|
-
): Effect<A | B,
|
|
5805
|
+
predicate: Predicate.Predicate<Cause.Cause<E>>,
|
|
5806
|
+
f: (cause: Cause.Cause<E>) => Effect<B, E2, R2>
|
|
5807
|
+
): Effect<A | B, E | E2, R | R2>
|
|
5281
5808
|
} = internal.catchCauseIf
|
|
5282
5809
|
|
|
5810
|
+
/**
|
|
5811
|
+
* Recovers from specific failures based on a `Filter`.
|
|
5812
|
+
*
|
|
5813
|
+
* @since 4.0.0
|
|
5814
|
+
* @category Error Handling
|
|
5815
|
+
*/
|
|
5816
|
+
export const catchCauseFilter: {
|
|
5817
|
+
/**
|
|
5818
|
+
* Recovers from specific failures based on a `Filter`.
|
|
5819
|
+
*
|
|
5820
|
+
* @since 4.0.0
|
|
5821
|
+
* @category Error Handling
|
|
5822
|
+
*/
|
|
5823
|
+
<E, B, E2, R2, EB, X extends Cause.Cause<any>>(
|
|
5824
|
+
filter: Filter.Filter<Cause.Cause<E>, EB, X>,
|
|
5825
|
+
f: (failure: EB, cause: Cause.Cause<E>) => Effect<B, E2, R2>
|
|
5826
|
+
): <A, R>(self: Effect<A, E, R>) => Effect<A | B, Cause.Cause.Error<X> | E2, R | R2>
|
|
5827
|
+
/**
|
|
5828
|
+
* Recovers from specific failures based on a `Filter`.
|
|
5829
|
+
*
|
|
5830
|
+
* @since 4.0.0
|
|
5831
|
+
* @category Error Handling
|
|
5832
|
+
*/
|
|
5833
|
+
<A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
|
|
5834
|
+
self: Effect<A, E, R>,
|
|
5835
|
+
filter: Filter.Filter<Cause.Cause<E>, EB, X>,
|
|
5836
|
+
f: (failure: EB, cause: Cause.Cause<E>) => Effect<B, E2, R2>
|
|
5837
|
+
): Effect<A | B, Cause.Cause.Error<X> | E2, R | R2>
|
|
5838
|
+
} = internal.catchCauseFilter
|
|
5839
|
+
|
|
5283
5840
|
/**
|
|
5284
5841
|
* The `mapError` function is used to transform or modify the error
|
|
5285
5842
|
* produced by an effect, without affecting its success value.
|
|
@@ -5295,17 +5852,19 @@ export const catchCauseIf: {
|
|
|
5295
5852
|
*
|
|
5296
5853
|
* @example
|
|
5297
5854
|
* ```ts
|
|
5298
|
-
* import { Effect } from "effect"
|
|
5855
|
+
* import { Data, Effect } from "effect"
|
|
5856
|
+
*
|
|
5857
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5299
5858
|
*
|
|
5300
5859
|
* // ┌─── Effect<number, string, never>
|
|
5301
5860
|
* // ▼
|
|
5302
5861
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5303
5862
|
*
|
|
5304
|
-
* // ┌─── Effect<number,
|
|
5863
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5305
5864
|
* // ▼
|
|
5306
5865
|
* const mapped = Effect.mapError(
|
|
5307
5866
|
* simulatedTask,
|
|
5308
|
-
* (message) => new
|
|
5867
|
+
* (message) => new TaskError({ message })
|
|
5309
5868
|
* )
|
|
5310
5869
|
* ```
|
|
5311
5870
|
*
|
|
@@ -5328,17 +5887,19 @@ export const mapError: {
|
|
|
5328
5887
|
*
|
|
5329
5888
|
* @example
|
|
5330
5889
|
* ```ts
|
|
5331
|
-
* import { Effect } from "effect"
|
|
5890
|
+
* import { Data, Effect } from "effect"
|
|
5891
|
+
*
|
|
5892
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5332
5893
|
*
|
|
5333
5894
|
* // ┌─── Effect<number, string, never>
|
|
5334
5895
|
* // ▼
|
|
5335
5896
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5336
5897
|
*
|
|
5337
|
-
* // ┌─── Effect<number,
|
|
5898
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5338
5899
|
* // ▼
|
|
5339
5900
|
* const mapped = Effect.mapError(
|
|
5340
5901
|
* simulatedTask,
|
|
5341
|
-
* (message) => new
|
|
5902
|
+
* (message) => new TaskError({ message })
|
|
5342
5903
|
* )
|
|
5343
5904
|
* ```
|
|
5344
5905
|
*
|
|
@@ -5361,17 +5922,19 @@ export const mapError: {
|
|
|
5361
5922
|
*
|
|
5362
5923
|
* @example
|
|
5363
5924
|
* ```ts
|
|
5364
|
-
* import { Effect } from "effect"
|
|
5925
|
+
* import { Data, Effect } from "effect"
|
|
5926
|
+
*
|
|
5927
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5365
5928
|
*
|
|
5366
5929
|
* // ┌─── Effect<number, string, never>
|
|
5367
5930
|
* // ▼
|
|
5368
5931
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5369
5932
|
*
|
|
5370
|
-
* // ┌─── Effect<number,
|
|
5933
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5371
5934
|
* // ▼
|
|
5372
5935
|
* const mapped = Effect.mapError(
|
|
5373
5936
|
* simulatedTask,
|
|
5374
|
-
* (message) => new
|
|
5937
|
+
* (message) => new TaskError({ message })
|
|
5375
5938
|
* )
|
|
5376
5939
|
* ```
|
|
5377
5940
|
*
|
|
@@ -5393,16 +5956,18 @@ export const mapError: {
|
|
|
5393
5956
|
*
|
|
5394
5957
|
* @example
|
|
5395
5958
|
* ```ts
|
|
5396
|
-
* import { Effect } from "effect"
|
|
5959
|
+
* import { Data, Effect } from "effect"
|
|
5960
|
+
*
|
|
5961
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5397
5962
|
*
|
|
5398
5963
|
* // ┌─── Effect<number, string, never>
|
|
5399
5964
|
* // ▼
|
|
5400
5965
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5401
5966
|
*
|
|
5402
|
-
* // ┌─── Effect<boolean,
|
|
5967
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5403
5968
|
* // ▼
|
|
5404
5969
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5405
|
-
* onFailure: (message) => new
|
|
5970
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5406
5971
|
* onSuccess: (n) => n > 0
|
|
5407
5972
|
* })
|
|
5408
5973
|
* ```
|
|
@@ -5426,16 +5991,18 @@ export const mapBoth: {
|
|
|
5426
5991
|
*
|
|
5427
5992
|
* @example
|
|
5428
5993
|
* ```ts
|
|
5429
|
-
* import { Effect } from "effect"
|
|
5994
|
+
* import { Data, Effect } from "effect"
|
|
5995
|
+
*
|
|
5996
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5430
5997
|
*
|
|
5431
5998
|
* // ┌─── Effect<number, string, never>
|
|
5432
5999
|
* // ▼
|
|
5433
6000
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5434
6001
|
*
|
|
5435
|
-
* // ┌─── Effect<boolean,
|
|
6002
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5436
6003
|
* // ▼
|
|
5437
6004
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5438
|
-
* onFailure: (message) => new
|
|
6005
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5439
6006
|
* onSuccess: (n) => n > 0
|
|
5440
6007
|
* })
|
|
5441
6008
|
* ```
|
|
@@ -5461,16 +6028,18 @@ export const mapBoth: {
|
|
|
5461
6028
|
*
|
|
5462
6029
|
* @example
|
|
5463
6030
|
* ```ts
|
|
5464
|
-
* import { Effect } from "effect"
|
|
6031
|
+
* import { Data, Effect } from "effect"
|
|
6032
|
+
*
|
|
6033
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5465
6034
|
*
|
|
5466
6035
|
* // ┌─── Effect<number, string, never>
|
|
5467
6036
|
* // ▼
|
|
5468
6037
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5469
6038
|
*
|
|
5470
|
-
* // ┌─── Effect<boolean,
|
|
6039
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5471
6040
|
* // ▼
|
|
5472
6041
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5473
|
-
* onFailure: (message) => new
|
|
6042
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5474
6043
|
* onSuccess: (n) => n > 0
|
|
5475
6044
|
* })
|
|
5476
6045
|
* ```
|
|
@@ -5505,11 +6074,13 @@ export const mapBoth: {
|
|
|
5505
6074
|
* @example
|
|
5506
6075
|
* ```ts
|
|
5507
6076
|
* // Title: Propagating an Error as a Defect
|
|
5508
|
-
* import { Effect } from "effect"
|
|
6077
|
+
* import { Data, Effect } from "effect"
|
|
6078
|
+
*
|
|
6079
|
+
* class DivideByZeroError extends Data.TaggedError("DivideByZeroError")<{}> {}
|
|
5509
6080
|
*
|
|
5510
6081
|
* const divide = (a: number, b: number) =>
|
|
5511
6082
|
* b === 0
|
|
5512
|
-
* ? Effect.fail(new
|
|
6083
|
+
* ? Effect.fail(new DivideByZeroError())
|
|
5513
6084
|
* : Effect.succeed(a / b)
|
|
5514
6085
|
*
|
|
5515
6086
|
* // ┌─── Effect<number, never, never>
|
|
@@ -5518,7 +6089,7 @@ export const mapBoth: {
|
|
|
5518
6089
|
*
|
|
5519
6090
|
* Effect.runPromise(program).catch(console.error)
|
|
5520
6091
|
* // Output:
|
|
5521
|
-
* // (FiberFailure)
|
|
6092
|
+
* // (FiberFailure) DivideByZeroError
|
|
5522
6093
|
* // ...stack trace...
|
|
5523
6094
|
* ```
|
|
5524
6095
|
*
|
|
@@ -5905,9 +6476,9 @@ export const tapCauseIf: {
|
|
|
5905
6476
|
* @since 4.0.0
|
|
5906
6477
|
* @category Sequencing
|
|
5907
6478
|
*/
|
|
5908
|
-
<E,
|
|
5909
|
-
|
|
5910
|
-
f: (
|
|
6479
|
+
<E, B, E2, R2>(
|
|
6480
|
+
predicate: Predicate.Predicate<Cause.Cause<E>>,
|
|
6481
|
+
f: (cause: Cause.Cause<E>) => Effect<B, E2, R2>
|
|
5911
6482
|
): <A, R>(self: Effect<A, E, R>) => Effect<A, E | E2, R | R2>
|
|
5912
6483
|
/**
|
|
5913
6484
|
* Conditionally executes a side effect based on the cause of a failed effect.
|
|
@@ -5937,13 +6508,43 @@ export const tapCauseIf: {
|
|
|
5937
6508
|
* @since 4.0.0
|
|
5938
6509
|
* @category Sequencing
|
|
5939
6510
|
*/
|
|
5940
|
-
<A, E, R,
|
|
6511
|
+
<A, E, R, B, E2, R2>(
|
|
5941
6512
|
self: Effect<A, E, R>,
|
|
5942
|
-
|
|
5943
|
-
f: (
|
|
6513
|
+
predicate: Predicate.Predicate<Cause.Cause<E>>,
|
|
6514
|
+
f: (cause: Cause.Cause<E>) => Effect<B, E2, R2>
|
|
5944
6515
|
): Effect<A, E | E2, R | R2>
|
|
5945
6516
|
} = internal.tapCauseIf
|
|
5946
6517
|
|
|
6518
|
+
/**
|
|
6519
|
+
* Conditionally executes a side effect based on the cause of a failed effect.
|
|
6520
|
+
*
|
|
6521
|
+
* @since 4.0.0
|
|
6522
|
+
* @category Sequencing
|
|
6523
|
+
*/
|
|
6524
|
+
export const tapCauseFilter: {
|
|
6525
|
+
/**
|
|
6526
|
+
* Conditionally executes a side effect based on the cause of a failed effect.
|
|
6527
|
+
*
|
|
6528
|
+
* @since 4.0.0
|
|
6529
|
+
* @category Sequencing
|
|
6530
|
+
*/
|
|
6531
|
+
<E, B, E2, R2, EB, X extends Cause.Cause<any>>(
|
|
6532
|
+
filter: Filter.Filter<Cause.Cause<E>, EB, X>,
|
|
6533
|
+
f: (a: EB, cause: Cause.Cause<E>) => Effect<B, E2, R2>
|
|
6534
|
+
): <A, R>(self: Effect<A, E, R>) => Effect<A, E | E2, R | R2>
|
|
6535
|
+
/**
|
|
6536
|
+
* Conditionally executes a side effect based on the cause of a failed effect.
|
|
6537
|
+
*
|
|
6538
|
+
* @since 4.0.0
|
|
6539
|
+
* @category Sequencing
|
|
6540
|
+
*/
|
|
6541
|
+
<A, E, R, B, E2, R2, EB, X extends Cause.Cause<any>>(
|
|
6542
|
+
self: Effect<A, E, R>,
|
|
6543
|
+
filter: Filter.Filter<Cause.Cause<E>, EB, X>,
|
|
6544
|
+
f: (a: EB, cause: Cause.Cause<E>) => Effect<B, E2, R2>
|
|
6545
|
+
): Effect<A, E | E2, R | R2>
|
|
6546
|
+
} = internal.tapCauseFilter
|
|
6547
|
+
|
|
5947
6548
|
/**
|
|
5948
6549
|
* Inspect severe errors or defects (non-recoverable failures) in an effect.
|
|
5949
6550
|
*
|
|
@@ -6120,7 +6721,7 @@ export const tapDefect: {
|
|
|
6120
6721
|
* attempts++
|
|
6121
6722
|
* yield* Console.log(`Attempt ${attempts}`)
|
|
6122
6723
|
* if (attempts < 3) {
|
|
6123
|
-
* yield* Effect.fail("Not ready")
|
|
6724
|
+
* return yield* Effect.fail("Not ready")
|
|
6124
6725
|
* }
|
|
6125
6726
|
* return "Ready"
|
|
6126
6727
|
* })
|
|
@@ -6247,13 +6848,15 @@ export declare namespace Retry {
|
|
|
6247
6848
|
*
|
|
6248
6849
|
* @example
|
|
6249
6850
|
* ```ts
|
|
6250
|
-
* import { Effect, Schedule } from "effect"
|
|
6851
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6852
|
+
*
|
|
6853
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6251
6854
|
*
|
|
6252
6855
|
* let attempt = 0
|
|
6253
|
-
* const task = Effect.callback<string,
|
|
6856
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6254
6857
|
* attempt++
|
|
6255
6858
|
* if (attempt <= 2) {
|
|
6256
|
-
* resume(Effect.fail(new
|
|
6859
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6257
6860
|
* } else {
|
|
6258
6861
|
* resume(Effect.succeed("Success!"))
|
|
6259
6862
|
* }
|
|
@@ -6296,13 +6899,15 @@ export const retry: {
|
|
|
6296
6899
|
*
|
|
6297
6900
|
* @example
|
|
6298
6901
|
* ```ts
|
|
6299
|
-
* import { Effect, Schedule } from "effect"
|
|
6902
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6903
|
+
*
|
|
6904
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6300
6905
|
*
|
|
6301
6906
|
* let attempt = 0
|
|
6302
|
-
* const task = Effect.callback<string,
|
|
6907
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6303
6908
|
* attempt++
|
|
6304
6909
|
* if (attempt <= 2) {
|
|
6305
|
-
* resume(Effect.fail(new
|
|
6910
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6306
6911
|
* } else {
|
|
6307
6912
|
* resume(Effect.succeed("Success!"))
|
|
6308
6913
|
* }
|
|
@@ -6345,13 +6950,15 @@ export const retry: {
|
|
|
6345
6950
|
*
|
|
6346
6951
|
* @example
|
|
6347
6952
|
* ```ts
|
|
6348
|
-
* import { Effect, Schedule } from "effect"
|
|
6953
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6954
|
+
*
|
|
6955
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6349
6956
|
*
|
|
6350
6957
|
* let attempt = 0
|
|
6351
|
-
* const task = Effect.callback<string,
|
|
6958
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6352
6959
|
* attempt++
|
|
6353
6960
|
* if (attempt <= 2) {
|
|
6354
|
-
* resume(Effect.fail(new
|
|
6961
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6355
6962
|
* } else {
|
|
6356
6963
|
* resume(Effect.succeed("Success!"))
|
|
6357
6964
|
* }
|
|
@@ -6394,13 +7001,15 @@ export const retry: {
|
|
|
6394
7001
|
*
|
|
6395
7002
|
* @example
|
|
6396
7003
|
* ```ts
|
|
6397
|
-
* import { Effect, Schedule } from "effect"
|
|
7004
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
7005
|
+
*
|
|
7006
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6398
7007
|
*
|
|
6399
7008
|
* let attempt = 0
|
|
6400
|
-
* const task = Effect.callback<string,
|
|
7009
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6401
7010
|
* attempt++
|
|
6402
7011
|
* if (attempt <= 2) {
|
|
6403
|
-
* resume(Effect.fail(new
|
|
7012
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6404
7013
|
* } else {
|
|
6405
7014
|
* resume(Effect.succeed("Success!"))
|
|
6406
7015
|
* }
|
|
@@ -6447,13 +7056,15 @@ export const retry: {
|
|
|
6447
7056
|
*
|
|
6448
7057
|
* @example
|
|
6449
7058
|
* ```ts
|
|
6450
|
-
* import { Effect, Schedule } from "effect"
|
|
7059
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
7060
|
+
*
|
|
7061
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6451
7062
|
*
|
|
6452
7063
|
* let attempt = 0
|
|
6453
|
-
* const task = Effect.callback<string,
|
|
7064
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6454
7065
|
* attempt++
|
|
6455
7066
|
* if (attempt <= 2) {
|
|
6456
|
-
* resume(Effect.fail(new
|
|
7067
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6457
7068
|
* } else {
|
|
6458
7069
|
* resume(Effect.succeed("Success!"))
|
|
6459
7070
|
* }
|
|
@@ -6496,13 +7107,15 @@ export const retry: {
|
|
|
6496
7107
|
*
|
|
6497
7108
|
* @example
|
|
6498
7109
|
* ```ts
|
|
6499
|
-
* import { Effect, Schedule } from "effect"
|
|
7110
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
7111
|
+
*
|
|
7112
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6500
7113
|
*
|
|
6501
7114
|
* let attempt = 0
|
|
6502
|
-
* const task = Effect.callback<string,
|
|
7115
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6503
7116
|
* attempt++
|
|
6504
7117
|
* if (attempt <= 2) {
|
|
6505
|
-
* resume(Effect.fail(new
|
|
7118
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6506
7119
|
* } else {
|
|
6507
7120
|
* resume(Effect.succeed("Success!"))
|
|
6508
7121
|
* }
|
|
@@ -6545,13 +7158,15 @@ export const retry: {
|
|
|
6545
7158
|
*
|
|
6546
7159
|
* @example
|
|
6547
7160
|
* ```ts
|
|
6548
|
-
* import { Effect, Schedule } from "effect"
|
|
7161
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
7162
|
+
*
|
|
7163
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6549
7164
|
*
|
|
6550
7165
|
* let attempt = 0
|
|
6551
|
-
* const task = Effect.callback<string,
|
|
7166
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6552
7167
|
* attempt++
|
|
6553
7168
|
* if (attempt <= 2) {
|
|
6554
|
-
* resume(Effect.fail(new
|
|
7169
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6555
7170
|
* } else {
|
|
6556
7171
|
* resume(Effect.succeed("Success!"))
|
|
6557
7172
|
* }
|
|
@@ -6598,14 +7213,16 @@ export const retry: {
|
|
|
6598
7213
|
*
|
|
6599
7214
|
* @example
|
|
6600
7215
|
* ```ts
|
|
6601
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
7216
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
7217
|
+
*
|
|
7218
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
6602
7219
|
*
|
|
6603
7220
|
* let attempt = 0
|
|
6604
7221
|
* const networkRequest = Effect.gen(function*() {
|
|
6605
7222
|
* attempt++
|
|
6606
7223
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
6607
7224
|
* if (attempt < 3) {
|
|
6608
|
-
* return yield* Effect.fail(new
|
|
7225
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
6609
7226
|
* }
|
|
6610
7227
|
* return "Network data"
|
|
6611
7228
|
* })
|
|
@@ -6653,14 +7270,16 @@ export const retryOrElse: {
|
|
|
6653
7270
|
*
|
|
6654
7271
|
* @example
|
|
6655
7272
|
* ```ts
|
|
6656
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
7273
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
7274
|
+
*
|
|
7275
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
6657
7276
|
*
|
|
6658
7277
|
* let attempt = 0
|
|
6659
7278
|
* const networkRequest = Effect.gen(function*() {
|
|
6660
7279
|
* attempt++
|
|
6661
7280
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
6662
7281
|
* if (attempt < 3) {
|
|
6663
|
-
* return yield* Effect.fail(new
|
|
7282
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
6664
7283
|
* }
|
|
6665
7284
|
* return "Network data"
|
|
6666
7285
|
* })
|
|
@@ -6711,14 +7330,16 @@ export const retryOrElse: {
|
|
|
6711
7330
|
*
|
|
6712
7331
|
* @example
|
|
6713
7332
|
* ```ts
|
|
6714
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
7333
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
7334
|
+
*
|
|
7335
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
6715
7336
|
*
|
|
6716
7337
|
* let attempt = 0
|
|
6717
7338
|
* const networkRequest = Effect.gen(function*() {
|
|
6718
7339
|
* attempt++
|
|
6719
7340
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
6720
7341
|
* if (attempt < 3) {
|
|
6721
|
-
* return yield* Effect.fail(new
|
|
7342
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
6722
7343
|
* }
|
|
6723
7344
|
* return "Network data"
|
|
6724
7345
|
* })
|
|
@@ -6799,7 +7420,8 @@ export const sandbox: <A, E, R>(
|
|
|
6799
7420
|
* it succeeds or fails. This is useful when you only care about the side
|
|
6800
7421
|
* effects of the effect and do not need to handle or process its outcome.
|
|
6801
7422
|
*
|
|
6802
|
-
* Use the `log` option to emit the full {@link Cause} when the effect fails
|
|
7423
|
+
* Use the `log` option to emit the full {@link Cause} when the effect fails,
|
|
7424
|
+
* and `message` to prepend a custom log message.
|
|
6803
7425
|
*
|
|
6804
7426
|
* @example
|
|
6805
7427
|
* ```ts
|
|
@@ -6823,7 +7445,7 @@ export const sandbox: <A, E, R>(
|
|
|
6823
7445
|
* const task = Effect.fail("Uh oh!")
|
|
6824
7446
|
*
|
|
6825
7447
|
* const program = task.pipe(Effect.ignore({ log: true }))
|
|
6826
|
-
* const programWarn = task.pipe(Effect.ignore({ log: "Warn" }))
|
|
7448
|
+
* const programWarn = task.pipe(Effect.ignore({ log: "Warn", message: "Ignoring task failure" }))
|
|
6827
7449
|
* ```
|
|
6828
7450
|
*
|
|
6829
7451
|
* **Previously Known As**
|
|
@@ -6837,14 +7459,17 @@ export const sandbox: <A, E, R>(
|
|
|
6837
7459
|
*/
|
|
6838
7460
|
export const ignore: <
|
|
6839
7461
|
Arg extends Effect<any, any, any> | {
|
|
6840
|
-
readonly log?: boolean |
|
|
7462
|
+
readonly log?: boolean | Severity | undefined
|
|
7463
|
+
readonly message?: string | undefined
|
|
6841
7464
|
} | undefined = {
|
|
6842
|
-
readonly log?: boolean |
|
|
7465
|
+
readonly log?: boolean | Severity | undefined
|
|
7466
|
+
readonly message?: string | undefined
|
|
6843
7467
|
}
|
|
6844
7468
|
>(
|
|
6845
7469
|
effectOrOptions?: Arg,
|
|
6846
7470
|
options?: {
|
|
6847
|
-
readonly log?: boolean |
|
|
7471
|
+
readonly log?: boolean | Severity | undefined
|
|
7472
|
+
readonly message?: string | undefined
|
|
6848
7473
|
} | undefined
|
|
6849
7474
|
) => [Arg] extends [Effect<infer _A, infer _E, infer _R>] ? Effect<void, never, _R>
|
|
6850
7475
|
: <A, E, R>(self: Effect<A, E, R>) => Effect<void, never, R> = internal.ignore
|
|
@@ -6852,7 +7477,8 @@ export const ignore: <
|
|
|
6852
7477
|
/**
|
|
6853
7478
|
* Ignores the effect's failure cause, including defects and interruptions.
|
|
6854
7479
|
*
|
|
6855
|
-
* Use the `log` option to emit the full {@link Cause} when the effect fails
|
|
7480
|
+
* Use the `log` option to emit the full {@link Cause} when the effect fails,
|
|
7481
|
+
* and `message` to prepend a custom log message.
|
|
6856
7482
|
*
|
|
6857
7483
|
* @example
|
|
6858
7484
|
* ```ts
|
|
@@ -6861,7 +7487,7 @@ export const ignore: <
|
|
|
6861
7487
|
* const task = Effect.fail("boom")
|
|
6862
7488
|
*
|
|
6863
7489
|
* const program = task.pipe(Effect.ignoreCause)
|
|
6864
|
-
* const programLog = task.pipe(Effect.ignoreCause({ log: true }))
|
|
7490
|
+
* const programLog = task.pipe(Effect.ignoreCause({ log: true, message: "Ignoring failure cause" }))
|
|
6865
7491
|
* ```
|
|
6866
7492
|
*
|
|
6867
7493
|
* @since 4.0.0
|
|
@@ -6869,14 +7495,17 @@ export const ignore: <
|
|
|
6869
7495
|
*/
|
|
6870
7496
|
export const ignoreCause: <
|
|
6871
7497
|
Arg extends Effect<any, any, any> | {
|
|
6872
|
-
readonly log?: boolean |
|
|
7498
|
+
readonly log?: boolean | Severity | undefined
|
|
7499
|
+
readonly message?: string | undefined
|
|
6873
7500
|
} | undefined = {
|
|
6874
|
-
readonly log?: boolean |
|
|
7501
|
+
readonly log?: boolean | Severity | undefined
|
|
7502
|
+
readonly message?: string | undefined
|
|
6875
7503
|
}
|
|
6876
7504
|
>(
|
|
6877
7505
|
effectOrOptions?: Arg,
|
|
6878
7506
|
options?: {
|
|
6879
|
-
readonly log?: boolean |
|
|
7507
|
+
readonly log?: boolean | Severity | undefined
|
|
7508
|
+
readonly message?: string | undefined
|
|
6880
7509
|
} | undefined
|
|
6881
7510
|
) => [Arg] extends [Effect<infer _A, infer _E, infer _R>] ? Effect<void, never, _R>
|
|
6882
7511
|
: <A, E, R>(self: Effect<A, E, R>) => Effect<void, never, R> = internal.ignoreCause
|
|
@@ -6897,7 +7526,10 @@ export const ignoreCause: <
|
|
|
6897
7526
|
*
|
|
6898
7527
|
* const fetchUrl = Effect.gen(function*() {
|
|
6899
7528
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
6900
|
-
*
|
|
7529
|
+
* if (endpoint.url === "bad") {
|
|
7530
|
+
* return yield* Effect.fail("Unavailable")
|
|
7531
|
+
* }
|
|
7532
|
+
* return endpoint.url
|
|
6901
7533
|
* })
|
|
6902
7534
|
*
|
|
6903
7535
|
* const plan = ExecutionPlan.make(
|
|
@@ -6928,7 +7560,10 @@ export const withExecutionPlan: {
|
|
|
6928
7560
|
*
|
|
6929
7561
|
* const fetchUrl = Effect.gen(function*() {
|
|
6930
7562
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
6931
|
-
*
|
|
7563
|
+
* if (endpoint.url === "bad") {
|
|
7564
|
+
* return yield* Effect.fail("Unavailable")
|
|
7565
|
+
* }
|
|
7566
|
+
* return endpoint.url
|
|
6932
7567
|
* })
|
|
6933
7568
|
*
|
|
6934
7569
|
* const plan = ExecutionPlan.make(
|
|
@@ -6963,7 +7598,10 @@ export const withExecutionPlan: {
|
|
|
6963
7598
|
*
|
|
6964
7599
|
* const fetchUrl = Effect.gen(function*() {
|
|
6965
7600
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
6966
|
-
*
|
|
7601
|
+
* if (endpoint.url === "bad") {
|
|
7602
|
+
* return yield* Effect.fail("Unavailable")
|
|
7603
|
+
* }
|
|
7604
|
+
* return endpoint.url
|
|
6967
7605
|
* })
|
|
6968
7606
|
*
|
|
6969
7607
|
* const plan = ExecutionPlan.make(
|
|
@@ -6983,9 +7621,28 @@ export const withExecutionPlan: {
|
|
|
6983
7621
|
): Effect<A, E | PlanE, Exclude<R, Provides> | PlanR>
|
|
6984
7622
|
} = internalExecutionPlan.withExecutionPlan
|
|
6985
7623
|
|
|
7624
|
+
/**
|
|
7625
|
+
* Runs an effect and reports any errors to the configured `ErrorReporter`s.
|
|
7626
|
+
*
|
|
7627
|
+
* If the `defectsOnly` option is set to `true`, only defects (unrecoverable
|
|
7628
|
+
* errors) will be reported, while regular failures will be ignored.
|
|
7629
|
+
*
|
|
7630
|
+
* @since 4.0.0
|
|
7631
|
+
* @category Error Handling
|
|
7632
|
+
*/
|
|
7633
|
+
export const withErrorReporting: <
|
|
7634
|
+
Arg extends Effect<any, any, any> | { readonly defectsOnly?: boolean | undefined } | undefined = {
|
|
7635
|
+
readonly defectsOnly?: boolean | undefined
|
|
7636
|
+
}
|
|
7637
|
+
>(
|
|
7638
|
+
effectOrOptions: Arg,
|
|
7639
|
+
options?: { readonly defectsOnly?: boolean | undefined } | undefined
|
|
7640
|
+
) => [Arg] extends [Effect<infer _A, infer _E, infer _R>] ? Arg : <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R> =
|
|
7641
|
+
internal.withErrorReporting
|
|
7642
|
+
|
|
7643
|
+
// -----------------------------------------------------------------------------
|
|
7644
|
+
// Fallback
|
|
6986
7645
|
// -----------------------------------------------------------------------------
|
|
6987
|
-
// Fallback
|
|
6988
|
-
// -----------------------------------------------------------------------------
|
|
6989
7646
|
|
|
6990
7647
|
/**
|
|
6991
7648
|
* Replaces the original failure with a success value, ensuring the effect
|
|
@@ -7224,7 +7881,7 @@ export const timeout: {
|
|
|
7224
7881
|
* @since 2.0.0
|
|
7225
7882
|
* @category Delays & Timeouts
|
|
7226
7883
|
*/
|
|
7227
|
-
(duration: Duration.
|
|
7884
|
+
(duration: Duration.Input): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E | Cause.TimeoutError, R>
|
|
7228
7885
|
// -----------------------------------------------------------------------------
|
|
7229
7886
|
// Delays & timeouts
|
|
7230
7887
|
// -----------------------------------------------------------------------------
|
|
@@ -7275,7 +7932,7 @@ export const timeout: {
|
|
|
7275
7932
|
* @since 2.0.0
|
|
7276
7933
|
* @category Delays & Timeouts
|
|
7277
7934
|
*/
|
|
7278
|
-
<A, E, R>(self: Effect<A, E, R>, duration: Duration.
|
|
7935
|
+
<A, E, R>(self: Effect<A, E, R>, duration: Duration.Input): Effect<A, E | Cause.TimeoutError, R>
|
|
7279
7936
|
} = internal.timeout
|
|
7280
7937
|
|
|
7281
7938
|
/**
|
|
@@ -7377,7 +8034,7 @@ export const timeoutOption: {
|
|
|
7377
8034
|
* @since 3.1.0
|
|
7378
8035
|
* @category Delays & Timeouts
|
|
7379
8036
|
*/
|
|
7380
|
-
(duration: Duration.
|
|
8037
|
+
(duration: Duration.Input): <A, E, R>(self: Effect<A, E, R>) => Effect<Option<A>, E, R>
|
|
7381
8038
|
/**
|
|
7382
8039
|
* Handles timeouts by returning an `Option` that represents either the result
|
|
7383
8040
|
* or a timeout.
|
|
@@ -7427,7 +8084,7 @@ export const timeoutOption: {
|
|
|
7427
8084
|
* @since 3.1.0
|
|
7428
8085
|
* @category Delays & Timeouts
|
|
7429
8086
|
*/
|
|
7430
|
-
<A, E, R>(self: Effect<A, E, R>, duration: Duration.
|
|
8087
|
+
<A, E, R>(self: Effect<A, E, R>, duration: Duration.Input): Effect<Option<A>, E, R>
|
|
7431
8088
|
} = internal.timeoutOption
|
|
7432
8089
|
|
|
7433
8090
|
/**
|
|
@@ -7505,7 +8162,7 @@ export const timeoutOrElse: {
|
|
|
7505
8162
|
*/
|
|
7506
8163
|
<A2, E2, R2>(
|
|
7507
8164
|
options: {
|
|
7508
|
-
readonly duration: Duration.
|
|
8165
|
+
readonly duration: Duration.Input
|
|
7509
8166
|
readonly onTimeout: LazyArg<Effect<A2, E2, R2>>
|
|
7510
8167
|
}
|
|
7511
8168
|
): <A, E, R>(self: Effect<A, E, R>) => Effect<A | A2, E | E2, R | R2>
|
|
@@ -7548,7 +8205,7 @@ export const timeoutOrElse: {
|
|
|
7548
8205
|
<A, E, R, A2, E2, R2>(
|
|
7549
8206
|
self: Effect<A, E, R>,
|
|
7550
8207
|
options: {
|
|
7551
|
-
readonly duration: Duration.
|
|
8208
|
+
readonly duration: Duration.Input
|
|
7552
8209
|
readonly onTimeout: LazyArg<Effect<A2, E2, R2>>
|
|
7553
8210
|
}
|
|
7554
8211
|
): Effect<A | A2, E | E2, R | R2>
|
|
@@ -7595,7 +8252,7 @@ export const delay: {
|
|
|
7595
8252
|
* @since 2.0.0
|
|
7596
8253
|
* @category Delays & Timeouts
|
|
7597
8254
|
*/
|
|
7598
|
-
(duration: Duration.
|
|
8255
|
+
(duration: Duration.Input): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
|
|
7599
8256
|
/**
|
|
7600
8257
|
* Returns an effect that is delayed from this effect by the specified
|
|
7601
8258
|
* `Duration`.
|
|
@@ -7616,7 +8273,7 @@ export const delay: {
|
|
|
7616
8273
|
* @since 2.0.0
|
|
7617
8274
|
* @category Delays & Timeouts
|
|
7618
8275
|
*/
|
|
7619
|
-
<A, E, R>(self: Effect<A, E, R>, duration: Duration.
|
|
8276
|
+
<A, E, R>(self: Effect<A, E, R>, duration: Duration.Input): Effect<A, E, R>
|
|
7620
8277
|
} = internal.delay
|
|
7621
8278
|
|
|
7622
8279
|
/**
|
|
@@ -7641,7 +8298,7 @@ export const delay: {
|
|
|
7641
8298
|
* @since 2.0.0
|
|
7642
8299
|
* @category Delays & Timeouts
|
|
7643
8300
|
*/
|
|
7644
|
-
export const sleep: (duration: Duration.
|
|
8301
|
+
export const sleep: (duration: Duration.Input) => Effect<void> = internal.sleep
|
|
7645
8302
|
|
|
7646
8303
|
/**
|
|
7647
8304
|
* Measures the runtime of an effect and returns the duration with its result.
|
|
@@ -7961,12 +8618,12 @@ export const raceFirst: {
|
|
|
7961
8618
|
// -----------------------------------------------------------------------------
|
|
7962
8619
|
|
|
7963
8620
|
/**
|
|
7964
|
-
* Filters elements of an iterable using a predicate, refinement, effectful
|
|
7965
|
-
* predicate
|
|
8621
|
+
* Filters elements of an iterable using a predicate, refinement, or effectful
|
|
8622
|
+
* predicate.
|
|
7966
8623
|
*
|
|
7967
8624
|
* @example
|
|
7968
8625
|
* ```ts
|
|
7969
|
-
* import { Effect
|
|
8626
|
+
* import { Effect } from "effect"
|
|
7970
8627
|
*
|
|
7971
8628
|
* // Sync predicate
|
|
7972
8629
|
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
@@ -7974,10 +8631,7 @@ export const raceFirst: {
|
|
|
7974
8631
|
* // Effectful predicate
|
|
7975
8632
|
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
7976
8633
|
*
|
|
7977
|
-
* //
|
|
7978
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
7979
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
7980
|
-
* )
|
|
8634
|
+
* // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
|
|
7981
8635
|
* ```
|
|
7982
8636
|
*
|
|
7983
8637
|
* @since 2.0.0
|
|
@@ -7989,12 +8643,12 @@ export const filter: {
|
|
|
7989
8643
|
// -----------------------------------------------------------------------------
|
|
7990
8644
|
|
|
7991
8645
|
/**
|
|
7992
|
-
* Filters elements of an iterable using a predicate, refinement, effectful
|
|
7993
|
-
* predicate
|
|
8646
|
+
* Filters elements of an iterable using a predicate, refinement, or effectful
|
|
8647
|
+
* predicate.
|
|
7994
8648
|
*
|
|
7995
8649
|
* @example
|
|
7996
8650
|
* ```ts
|
|
7997
|
-
* import { Effect
|
|
8651
|
+
* import { Effect } from "effect"
|
|
7998
8652
|
*
|
|
7999
8653
|
* // Sync predicate
|
|
8000
8654
|
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
@@ -8002,10 +8656,7 @@ export const filter: {
|
|
|
8002
8656
|
* // Effectful predicate
|
|
8003
8657
|
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8004
8658
|
*
|
|
8005
|
-
* //
|
|
8006
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8007
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8008
|
-
* )
|
|
8659
|
+
* // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
|
|
8009
8660
|
* ```
|
|
8010
8661
|
*
|
|
8011
8662
|
* @since 2.0.0
|
|
@@ -8017,12 +8668,12 @@ export const filter: {
|
|
|
8017
8668
|
// -----------------------------------------------------------------------------
|
|
8018
8669
|
|
|
8019
8670
|
/**
|
|
8020
|
-
* Filters elements of an iterable using a predicate, refinement, effectful
|
|
8021
|
-
* predicate
|
|
8671
|
+
* Filters elements of an iterable using a predicate, refinement, or effectful
|
|
8672
|
+
* predicate.
|
|
8022
8673
|
*
|
|
8023
8674
|
* @example
|
|
8024
8675
|
* ```ts
|
|
8025
|
-
* import { Effect
|
|
8676
|
+
* import { Effect } from "effect"
|
|
8026
8677
|
*
|
|
8027
8678
|
* // Sync predicate
|
|
8028
8679
|
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
@@ -8030,10 +8681,7 @@ export const filter: {
|
|
|
8030
8681
|
* // Effectful predicate
|
|
8031
8682
|
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8032
8683
|
*
|
|
8033
|
-
* //
|
|
8034
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8035
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8036
|
-
* )
|
|
8684
|
+
* // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
|
|
8037
8685
|
* ```
|
|
8038
8686
|
*
|
|
8039
8687
|
* @since 2.0.0
|
|
@@ -8045,12 +8693,12 @@ export const filter: {
|
|
|
8045
8693
|
// -----------------------------------------------------------------------------
|
|
8046
8694
|
|
|
8047
8695
|
/**
|
|
8048
|
-
* Filters elements of an iterable using a predicate, refinement, effectful
|
|
8049
|
-
* predicate
|
|
8696
|
+
* Filters elements of an iterable using a predicate, refinement, or effectful
|
|
8697
|
+
* predicate.
|
|
8050
8698
|
*
|
|
8051
8699
|
* @example
|
|
8052
8700
|
* ```ts
|
|
8053
|
-
* import { Effect
|
|
8701
|
+
* import { Effect } from "effect"
|
|
8054
8702
|
*
|
|
8055
8703
|
* // Sync predicate
|
|
8056
8704
|
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
@@ -8058,30 +8706,27 @@ export const filter: {
|
|
|
8058
8706
|
* // Effectful predicate
|
|
8059
8707
|
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8060
8708
|
*
|
|
8061
|
-
* //
|
|
8062
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8063
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8064
|
-
* )
|
|
8709
|
+
* // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
|
|
8065
8710
|
* ```
|
|
8066
8711
|
*
|
|
8067
8712
|
* @since 2.0.0
|
|
8068
8713
|
* @category Filtering
|
|
8069
8714
|
*/
|
|
8070
|
-
<A,
|
|
8071
|
-
|
|
8715
|
+
<A, E, R>(
|
|
8716
|
+
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
|
|
8072
8717
|
options?: { readonly concurrency?: Concurrency | undefined }
|
|
8073
|
-
): (
|
|
8718
|
+
): (iterable: Iterable<A>) => Effect<Array<A>, E, R>
|
|
8074
8719
|
// -----------------------------------------------------------------------------
|
|
8075
8720
|
// Filtering
|
|
8076
8721
|
// -----------------------------------------------------------------------------
|
|
8077
8722
|
|
|
8078
8723
|
/**
|
|
8079
|
-
* Filters elements of an iterable using a predicate, refinement, effectful
|
|
8080
|
-
* predicate
|
|
8724
|
+
* Filters elements of an iterable using a predicate, refinement, or effectful
|
|
8725
|
+
* predicate.
|
|
8081
8726
|
*
|
|
8082
8727
|
* @example
|
|
8083
8728
|
* ```ts
|
|
8084
|
-
* import { Effect
|
|
8729
|
+
* import { Effect } from "effect"
|
|
8085
8730
|
*
|
|
8086
8731
|
* // Sync predicate
|
|
8087
8732
|
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
@@ -8089,30 +8734,24 @@ export const filter: {
|
|
|
8089
8734
|
* // Effectful predicate
|
|
8090
8735
|
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8091
8736
|
*
|
|
8092
|
-
* //
|
|
8093
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8094
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8095
|
-
* )
|
|
8737
|
+
* // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
|
|
8096
8738
|
* ```
|
|
8097
8739
|
*
|
|
8098
8740
|
* @since 2.0.0
|
|
8099
8741
|
* @category Filtering
|
|
8100
8742
|
*/
|
|
8101
|
-
<A, B
|
|
8102
|
-
filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
|
|
8103
|
-
options?: { readonly concurrency?: Concurrency | undefined }
|
|
8104
|
-
): (elements: Iterable<A>) => Effect<Array<B>, E, R>
|
|
8743
|
+
<A, B extends A>(elements: Iterable<A>, refinement: Predicate.Refinement<A, B>): Effect<Array<B>>
|
|
8105
8744
|
// -----------------------------------------------------------------------------
|
|
8106
8745
|
// Filtering
|
|
8107
8746
|
// -----------------------------------------------------------------------------
|
|
8108
8747
|
|
|
8109
8748
|
/**
|
|
8110
|
-
* Filters elements of an iterable using a predicate, refinement, effectful
|
|
8111
|
-
* predicate
|
|
8749
|
+
* Filters elements of an iterable using a predicate, refinement, or effectful
|
|
8750
|
+
* predicate.
|
|
8112
8751
|
*
|
|
8113
8752
|
* @example
|
|
8114
8753
|
* ```ts
|
|
8115
|
-
* import { Effect
|
|
8754
|
+
* import { Effect } from "effect"
|
|
8116
8755
|
*
|
|
8117
8756
|
* // Sync predicate
|
|
8118
8757
|
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
@@ -8120,30 +8759,24 @@ export const filter: {
|
|
|
8120
8759
|
* // Effectful predicate
|
|
8121
8760
|
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8122
8761
|
*
|
|
8123
|
-
* //
|
|
8124
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8125
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8126
|
-
* )
|
|
8762
|
+
* // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
|
|
8127
8763
|
* ```
|
|
8128
8764
|
*
|
|
8129
8765
|
* @since 2.0.0
|
|
8130
8766
|
* @category Filtering
|
|
8131
8767
|
*/
|
|
8132
|
-
<A
|
|
8133
|
-
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
|
|
8134
|
-
options?: { readonly concurrency?: Concurrency | undefined }
|
|
8135
|
-
): (iterable: Iterable<A>) => Effect<Array<A>, E, R>
|
|
8768
|
+
<A>(elements: Iterable<A>, predicate: Predicate.Predicate<A>): Effect<Array<A>>
|
|
8136
8769
|
// -----------------------------------------------------------------------------
|
|
8137
8770
|
// Filtering
|
|
8138
8771
|
// -----------------------------------------------------------------------------
|
|
8139
8772
|
|
|
8140
8773
|
/**
|
|
8141
|
-
* Filters elements of an iterable using a predicate, refinement, effectful
|
|
8142
|
-
* predicate
|
|
8774
|
+
* Filters elements of an iterable using a predicate, refinement, or effectful
|
|
8775
|
+
* predicate.
|
|
8143
8776
|
*
|
|
8144
8777
|
* @example
|
|
8145
8778
|
* ```ts
|
|
8146
|
-
* import { Effect
|
|
8779
|
+
* import { Effect } from "effect"
|
|
8147
8780
|
*
|
|
8148
8781
|
* // Sync predicate
|
|
8149
8782
|
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
@@ -8151,137 +8784,71 @@ export const filter: {
|
|
|
8151
8784
|
* // Effectful predicate
|
|
8152
8785
|
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8153
8786
|
*
|
|
8154
|
-
* //
|
|
8155
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8156
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8157
|
-
* )
|
|
8787
|
+
* // Use Effect.filterMapEffect for effectful Filter.Filter callbacks
|
|
8158
8788
|
* ```
|
|
8159
8789
|
*
|
|
8160
8790
|
* @since 2.0.0
|
|
8161
8791
|
* @category Filtering
|
|
8162
8792
|
*/
|
|
8163
|
-
<A,
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8793
|
+
<A, E, R>(
|
|
8794
|
+
iterable: Iterable<A>,
|
|
8795
|
+
predicate: (a: NoInfer<A>, i: number) => Effect<boolean, E, R>,
|
|
8796
|
+
options?: { readonly concurrency?: Concurrency | undefined }
|
|
8797
|
+
): Effect<Array<A>, E, R>
|
|
8798
|
+
} = internal.filter
|
|
8167
8799
|
|
|
8800
|
+
/**
|
|
8801
|
+
* Filters and maps elements of an iterable with a `Filter`.
|
|
8802
|
+
*
|
|
8803
|
+
* @since 4.0.0
|
|
8804
|
+
* @category Filtering
|
|
8805
|
+
*/
|
|
8806
|
+
export const filterMap: {
|
|
8168
8807
|
/**
|
|
8169
|
-
* Filters elements of an iterable
|
|
8170
|
-
* predicate, or `Filter.FilterEffect`.
|
|
8808
|
+
* Filters and maps elements of an iterable with a `Filter`.
|
|
8171
8809
|
*
|
|
8172
|
-
* @
|
|
8173
|
-
* ```ts
|
|
8174
|
-
* import { Effect, Filter, Result } from "effect"
|
|
8175
|
-
*
|
|
8176
|
-
* // Sync predicate
|
|
8177
|
-
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
8178
|
-
*
|
|
8179
|
-
* // Effectful predicate
|
|
8180
|
-
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8181
|
-
*
|
|
8182
|
-
* // FilterEffect
|
|
8183
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8184
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8185
|
-
* )
|
|
8186
|
-
* ```
|
|
8187
|
-
*
|
|
8188
|
-
* @since 2.0.0
|
|
8810
|
+
* @since 4.0.0
|
|
8189
8811
|
* @category Filtering
|
|
8190
8812
|
*/
|
|
8191
|
-
<A>(
|
|
8192
|
-
// -----------------------------------------------------------------------------
|
|
8193
|
-
// Filtering
|
|
8194
|
-
// -----------------------------------------------------------------------------
|
|
8195
|
-
|
|
8813
|
+
<A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>): (elements: Iterable<A>) => Effect<Array<B>>
|
|
8196
8814
|
/**
|
|
8197
|
-
* Filters elements of an iterable
|
|
8198
|
-
* predicate, or `Filter.FilterEffect`.
|
|
8199
|
-
*
|
|
8200
|
-
* @example
|
|
8201
|
-
* ```ts
|
|
8202
|
-
* import { Effect, Filter, Result } from "effect"
|
|
8203
|
-
*
|
|
8204
|
-
* // Sync predicate
|
|
8205
|
-
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
8206
|
-
*
|
|
8207
|
-
* // Effectful predicate
|
|
8208
|
-
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8815
|
+
* Filters and maps elements of an iterable with a `Filter`.
|
|
8209
8816
|
*
|
|
8210
|
-
*
|
|
8211
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8212
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8213
|
-
* )
|
|
8214
|
-
* ```
|
|
8215
|
-
*
|
|
8216
|
-
* @since 2.0.0
|
|
8817
|
+
* @since 4.0.0
|
|
8217
8818
|
* @category Filtering
|
|
8218
8819
|
*/
|
|
8219
8820
|
<A, B, X>(elements: Iterable<A>, filter: Filter.Filter<NoInfer<A>, B, X>): Effect<Array<B>>
|
|
8220
|
-
|
|
8221
|
-
// Filtering
|
|
8222
|
-
// -----------------------------------------------------------------------------
|
|
8821
|
+
} = internal.filterMap
|
|
8223
8822
|
|
|
8823
|
+
/**
|
|
8824
|
+
* Effectfully filters and maps elements of an iterable with a `FilterEffect`.
|
|
8825
|
+
*
|
|
8826
|
+
* @since 4.0.0
|
|
8827
|
+
* @category Filtering
|
|
8828
|
+
*/
|
|
8829
|
+
export const filterMapEffect: {
|
|
8224
8830
|
/**
|
|
8225
|
-
*
|
|
8226
|
-
* predicate, or `Filter.FilterEffect`.
|
|
8227
|
-
*
|
|
8228
|
-
* @example
|
|
8229
|
-
* ```ts
|
|
8230
|
-
* import { Effect, Filter, Result } from "effect"
|
|
8231
|
-
*
|
|
8232
|
-
* // Sync predicate
|
|
8233
|
-
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
8234
|
-
*
|
|
8235
|
-
* // Effectful predicate
|
|
8236
|
-
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8831
|
+
* Effectfully filters and maps elements of an iterable with a `FilterEffect`.
|
|
8237
8832
|
*
|
|
8238
|
-
*
|
|
8239
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8240
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8241
|
-
* )
|
|
8242
|
-
* ```
|
|
8243
|
-
*
|
|
8244
|
-
* @since 2.0.0
|
|
8833
|
+
* @since 4.0.0
|
|
8245
8834
|
* @category Filtering
|
|
8246
8835
|
*/
|
|
8247
8836
|
<A, B, X, E, R>(
|
|
8248
|
-
elements: Iterable<A>,
|
|
8249
8837
|
filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
|
|
8250
8838
|
options?: { readonly concurrency?: Concurrency | undefined }
|
|
8251
|
-
): Effect<Array<B>, E, R>
|
|
8252
|
-
// -----------------------------------------------------------------------------
|
|
8253
|
-
// Filtering
|
|
8254
|
-
// -----------------------------------------------------------------------------
|
|
8255
|
-
|
|
8839
|
+
): (elements: Iterable<A>) => Effect<Array<B>, E, R>
|
|
8256
8840
|
/**
|
|
8257
|
-
*
|
|
8258
|
-
* predicate, or `Filter.FilterEffect`.
|
|
8259
|
-
*
|
|
8260
|
-
* @example
|
|
8261
|
-
* ```ts
|
|
8262
|
-
* import { Effect, Filter, Result } from "effect"
|
|
8263
|
-
*
|
|
8264
|
-
* // Sync predicate
|
|
8265
|
-
* const evens = Effect.filter([1, 2, 3, 4], (n) => n % 2 === 0)
|
|
8266
|
-
*
|
|
8267
|
-
* // Effectful predicate
|
|
8268
|
-
* const checked = Effect.filter([1, 2, 3], (n) => Effect.succeed(n > 1))
|
|
8269
|
-
*
|
|
8270
|
-
* // FilterEffect
|
|
8271
|
-
* const mapped = Effect.filter([1, 2, 3, 4], (n) =>
|
|
8272
|
-
* Effect.succeed(n % 2 === 0 ? Result.succeed(n * 2) : Result.fail(n))
|
|
8273
|
-
* )
|
|
8274
|
-
* ```
|
|
8841
|
+
* Effectfully filters and maps elements of an iterable with a `FilterEffect`.
|
|
8275
8842
|
*
|
|
8276
|
-
* @since
|
|
8843
|
+
* @since 4.0.0
|
|
8277
8844
|
* @category Filtering
|
|
8278
8845
|
*/
|
|
8279
|
-
<A, E, R>(
|
|
8280
|
-
|
|
8281
|
-
|
|
8846
|
+
<A, B, X, E, R>(
|
|
8847
|
+
elements: Iterable<A>,
|
|
8848
|
+
filter: Filter.FilterEffect<NoInfer<A>, B, X, E, R>,
|
|
8282
8849
|
options?: { readonly concurrency?: Concurrency | undefined }
|
|
8283
|
-
): Effect<Array<
|
|
8284
|
-
} = internal.
|
|
8850
|
+
): Effect<Array<B>, E, R>
|
|
8851
|
+
} = internal.filterMapEffect
|
|
8285
8852
|
|
|
8286
8853
|
/**
|
|
8287
8854
|
* Filters an effect, providing an alternative effect if the predicate fails.
|
|
@@ -8378,10 +8945,10 @@ export const filterOrElse: {
|
|
|
8378
8945
|
* @since 2.0.0
|
|
8379
8946
|
* @category Filtering
|
|
8380
8947
|
*/
|
|
8381
|
-
<A,
|
|
8382
|
-
|
|
8383
|
-
orElse: (a:
|
|
8384
|
-
): <E, R>(self: Effect<A, E, R>) => Effect<
|
|
8948
|
+
<A, C, E2, R2>(
|
|
8949
|
+
predicate: Predicate.Predicate<NoInfer<A>>,
|
|
8950
|
+
orElse: (a: NoInfer<A>) => Effect<C, E2, R2>
|
|
8951
|
+
): <E, R>(self: Effect<A, E, R>) => Effect<A | C, E2 | E, R2 | R>
|
|
8385
8952
|
/**
|
|
8386
8953
|
* Filters an effect, providing an alternative effect if the predicate fails.
|
|
8387
8954
|
*
|
|
@@ -8447,13 +9014,43 @@ export const filterOrElse: {
|
|
|
8447
9014
|
* @since 2.0.0
|
|
8448
9015
|
* @category Filtering
|
|
8449
9016
|
*/
|
|
8450
|
-
<A, E, R,
|
|
9017
|
+
<A, E, R, C, E2, R2>(
|
|
8451
9018
|
self: Effect<A, E, R>,
|
|
8452
|
-
|
|
8453
|
-
orElse: (a:
|
|
8454
|
-
): Effect<
|
|
9019
|
+
predicate: Predicate.Predicate<NoInfer<A>>,
|
|
9020
|
+
orElse: (a: NoInfer<A>) => Effect<C, E2, R2>
|
|
9021
|
+
): Effect<A | C, E | E2, R | R2>
|
|
8455
9022
|
} = internal.filterOrElse
|
|
8456
9023
|
|
|
9024
|
+
/**
|
|
9025
|
+
* Filters an effect with a `Filter`, providing an alternative effect on failure.
|
|
9026
|
+
*
|
|
9027
|
+
* @since 4.0.0
|
|
9028
|
+
* @category Filtering
|
|
9029
|
+
*/
|
|
9030
|
+
export const filterMapOrElse: {
|
|
9031
|
+
/**
|
|
9032
|
+
* Filters an effect with a `Filter`, providing an alternative effect on failure.
|
|
9033
|
+
*
|
|
9034
|
+
* @since 4.0.0
|
|
9035
|
+
* @category Filtering
|
|
9036
|
+
*/
|
|
9037
|
+
<A, B, X, C, E2, R2>(
|
|
9038
|
+
filter: Filter.Filter<NoInfer<A>, B, X>,
|
|
9039
|
+
orElse: (x: X) => Effect<C, E2, R2>
|
|
9040
|
+
): <E, R>(self: Effect<A, E, R>) => Effect<B | C, E2 | E, R2 | R>
|
|
9041
|
+
/**
|
|
9042
|
+
* Filters an effect with a `Filter`, providing an alternative effect on failure.
|
|
9043
|
+
*
|
|
9044
|
+
* @since 4.0.0
|
|
9045
|
+
* @category Filtering
|
|
9046
|
+
*/
|
|
9047
|
+
<A, E, R, B, X, C, E2, R2>(
|
|
9048
|
+
self: Effect<A, E, R>,
|
|
9049
|
+
filter: Filter.Filter<NoInfer<A>, B, X>,
|
|
9050
|
+
orElse: (x: X) => Effect<C, E2, R2>
|
|
9051
|
+
): Effect<B | C, E | E2, R | R2>
|
|
9052
|
+
} = internal.filterMapOrElse
|
|
9053
|
+
|
|
8457
9054
|
/**
|
|
8458
9055
|
* Filters an effect, failing with a custom error if the predicate fails.
|
|
8459
9056
|
*
|
|
@@ -8550,36 +9147,6 @@ export const filterOrFail: {
|
|
|
8550
9147
|
predicate: Predicate.Predicate<NoInfer<A>>,
|
|
8551
9148
|
orFailWith: (a: NoInfer<A>) => E2
|
|
8552
9149
|
): <E, R>(self: Effect<A, E, R>) => Effect<A, E2 | E, R>
|
|
8553
|
-
/**
|
|
8554
|
-
* Filters an effect, failing with a custom error if the predicate fails.
|
|
8555
|
-
*
|
|
8556
|
-
* **Details**
|
|
8557
|
-
*
|
|
8558
|
-
* This function applies a predicate to the result of an effect. If the
|
|
8559
|
-
* predicate evaluates to `false`, the effect fails with either a custom
|
|
8560
|
-
* error (if `orFailWith` is provided) or a `NoSuchElementError`.
|
|
8561
|
-
*
|
|
8562
|
-
* @example
|
|
8563
|
-
* ```ts
|
|
8564
|
-
* import { Effect } from "effect"
|
|
8565
|
-
*
|
|
8566
|
-
* // An effect that produces a number
|
|
8567
|
-
* const program = Effect.succeed(5)
|
|
8568
|
-
*
|
|
8569
|
-
* // Filter for even numbers, fail for odd numbers
|
|
8570
|
-
* const filtered = Effect.filterOrFail(
|
|
8571
|
-
* program,
|
|
8572
|
-
* (n) => n % 2 === 0,
|
|
8573
|
-
* (n) => `Expected even number, got ${n}`
|
|
8574
|
-
* )
|
|
8575
|
-
*
|
|
8576
|
-
* // Result: Effect.fail("Expected even number, got 5")
|
|
8577
|
-
* ```
|
|
8578
|
-
*
|
|
8579
|
-
* @since 2.0.0
|
|
8580
|
-
* @category Filtering
|
|
8581
|
-
*/
|
|
8582
|
-
<A, B, X, E2>(filter: Filter.Filter<NoInfer<A>, B, X>, orFailWith: (x: X) => E2): <E, R>(self: Effect<A, E, R>) => Effect<B, E2 | E, R>
|
|
8583
9150
|
/**
|
|
8584
9151
|
* Filters an effect, failing with a custom error if the predicate fails.
|
|
8585
9152
|
*
|
|
@@ -8640,36 +9207,6 @@ export const filterOrFail: {
|
|
|
8640
9207
|
* @category Filtering
|
|
8641
9208
|
*/
|
|
8642
9209
|
<A>(predicate: Predicate.Predicate<NoInfer<A>>): <E, R>(self: Effect<A, E, R>) => Effect<A, Cause.NoSuchElementError | E, R>
|
|
8643
|
-
/**
|
|
8644
|
-
* Filters an effect, failing with a custom error if the predicate fails.
|
|
8645
|
-
*
|
|
8646
|
-
* **Details**
|
|
8647
|
-
*
|
|
8648
|
-
* This function applies a predicate to the result of an effect. If the
|
|
8649
|
-
* predicate evaluates to `false`, the effect fails with either a custom
|
|
8650
|
-
* error (if `orFailWith` is provided) or a `NoSuchElementError`.
|
|
8651
|
-
*
|
|
8652
|
-
* @example
|
|
8653
|
-
* ```ts
|
|
8654
|
-
* import { Effect } from "effect"
|
|
8655
|
-
*
|
|
8656
|
-
* // An effect that produces a number
|
|
8657
|
-
* const program = Effect.succeed(5)
|
|
8658
|
-
*
|
|
8659
|
-
* // Filter for even numbers, fail for odd numbers
|
|
8660
|
-
* const filtered = Effect.filterOrFail(
|
|
8661
|
-
* program,
|
|
8662
|
-
* (n) => n % 2 === 0,
|
|
8663
|
-
* (n) => `Expected even number, got ${n}`
|
|
8664
|
-
* )
|
|
8665
|
-
*
|
|
8666
|
-
* // Result: Effect.fail("Expected even number, got 5")
|
|
8667
|
-
* ```
|
|
8668
|
-
*
|
|
8669
|
-
* @since 2.0.0
|
|
8670
|
-
* @category Filtering
|
|
8671
|
-
*/
|
|
8672
|
-
<A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Effect<A, E, R>) => Effect<B, Cause.NoSuchElementError | E, R>
|
|
8673
9210
|
/**
|
|
8674
9211
|
* Filters an effect, failing with a custom error if the predicate fails.
|
|
8675
9212
|
*
|
|
@@ -8738,40 +9275,6 @@ export const filterOrFail: {
|
|
|
8738
9275
|
predicate: Predicate.Predicate<NoInfer<A>>,
|
|
8739
9276
|
orFailWith: (a: NoInfer<A>) => E2
|
|
8740
9277
|
): Effect<A, E2 | E, R>
|
|
8741
|
-
/**
|
|
8742
|
-
* Filters an effect, failing with a custom error if the predicate fails.
|
|
8743
|
-
*
|
|
8744
|
-
* **Details**
|
|
8745
|
-
*
|
|
8746
|
-
* This function applies a predicate to the result of an effect. If the
|
|
8747
|
-
* predicate evaluates to `false`, the effect fails with either a custom
|
|
8748
|
-
* error (if `orFailWith` is provided) or a `NoSuchElementError`.
|
|
8749
|
-
*
|
|
8750
|
-
* @example
|
|
8751
|
-
* ```ts
|
|
8752
|
-
* import { Effect } from "effect"
|
|
8753
|
-
*
|
|
8754
|
-
* // An effect that produces a number
|
|
8755
|
-
* const program = Effect.succeed(5)
|
|
8756
|
-
*
|
|
8757
|
-
* // Filter for even numbers, fail for odd numbers
|
|
8758
|
-
* const filtered = Effect.filterOrFail(
|
|
8759
|
-
* program,
|
|
8760
|
-
* (n) => n % 2 === 0,
|
|
8761
|
-
* (n) => `Expected even number, got ${n}`
|
|
8762
|
-
* )
|
|
8763
|
-
*
|
|
8764
|
-
* // Result: Effect.fail("Expected even number, got 5")
|
|
8765
|
-
* ```
|
|
8766
|
-
*
|
|
8767
|
-
* @since 2.0.0
|
|
8768
|
-
* @category Filtering
|
|
8769
|
-
*/
|
|
8770
|
-
<A, E, R, B, X, E2>(
|
|
8771
|
-
self: Effect<A, E, R>,
|
|
8772
|
-
filter: Filter.Filter<A, B, X>,
|
|
8773
|
-
orFailWith: (x: X) => E2
|
|
8774
|
-
): Effect<B, E2 | E, R>
|
|
8775
9278
|
/**
|
|
8776
9279
|
* Filters an effect, failing with a custom error if the predicate fails.
|
|
8777
9280
|
*
|
|
@@ -8832,37 +9335,48 @@ export const filterOrFail: {
|
|
|
8832
9335
|
* @category Filtering
|
|
8833
9336
|
*/
|
|
8834
9337
|
<A, E, R>(self: Effect<A, E, R>, predicate: Predicate.Predicate<NoInfer<A>>): Effect<A, E | Cause.NoSuchElementError, R>
|
|
9338
|
+
} = internal.filterOrFail
|
|
9339
|
+
|
|
9340
|
+
/**
|
|
9341
|
+
* Filters an effect with a `Filter`, failing when the filter fails.
|
|
9342
|
+
*
|
|
9343
|
+
* @since 4.0.0
|
|
9344
|
+
* @category Filtering
|
|
9345
|
+
*/
|
|
9346
|
+
export const filterMapOrFail: {
|
|
8835
9347
|
/**
|
|
8836
|
-
* Filters an effect
|
|
8837
|
-
*
|
|
8838
|
-
* **Details**
|
|
8839
|
-
*
|
|
8840
|
-
* This function applies a predicate to the result of an effect. If the
|
|
8841
|
-
* predicate evaluates to `false`, the effect fails with either a custom
|
|
8842
|
-
* error (if `orFailWith` is provided) or a `NoSuchElementError`.
|
|
9348
|
+
* Filters an effect with a `Filter`, failing when the filter fails.
|
|
8843
9349
|
*
|
|
8844
|
-
* @
|
|
8845
|
-
*
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
*
|
|
8850
|
-
*
|
|
8851
|
-
* // Filter for even numbers, fail for odd numbers
|
|
8852
|
-
* const filtered = Effect.filterOrFail(
|
|
8853
|
-
* program,
|
|
8854
|
-
* (n) => n % 2 === 0,
|
|
8855
|
-
* (n) => `Expected even number, got ${n}`
|
|
8856
|
-
* )
|
|
9350
|
+
* @since 4.0.0
|
|
9351
|
+
* @category Filtering
|
|
9352
|
+
*/
|
|
9353
|
+
<A, B, X, E2>(filter: Filter.Filter<NoInfer<A>, B, X>, orFailWith: (x: X) => E2): <E, R>(self: Effect<A, E, R>) => Effect<B, E2 | E, R>
|
|
9354
|
+
/**
|
|
9355
|
+
* Filters an effect with a `Filter`, failing when the filter fails.
|
|
8857
9356
|
*
|
|
8858
|
-
*
|
|
8859
|
-
*
|
|
9357
|
+
* @since 4.0.0
|
|
9358
|
+
* @category Filtering
|
|
9359
|
+
*/
|
|
9360
|
+
<A, B, X>(filter: Filter.Filter<NoInfer<A>, B, X>): <E, R>(self: Effect<A, E, R>) => Effect<B, Cause.NoSuchElementError | E, R>
|
|
9361
|
+
/**
|
|
9362
|
+
* Filters an effect with a `Filter`, failing when the filter fails.
|
|
8860
9363
|
*
|
|
8861
|
-
* @since
|
|
9364
|
+
* @since 4.0.0
|
|
8862
9365
|
* @category Filtering
|
|
8863
9366
|
*/
|
|
8864
|
-
<A, E, R, B, X
|
|
8865
|
-
|
|
9367
|
+
<A, E, R, B, X, E2>(
|
|
9368
|
+
self: Effect<A, E, R>,
|
|
9369
|
+
filter: Filter.Filter<A, B, X>,
|
|
9370
|
+
orFailWith: (x: X) => E2
|
|
9371
|
+
): Effect<B, E2 | E, R>
|
|
9372
|
+
/**
|
|
9373
|
+
* Filters an effect with a `Filter`, failing when the filter fails.
|
|
9374
|
+
*
|
|
9375
|
+
* @since 4.0.0
|
|
9376
|
+
* @category Filtering
|
|
9377
|
+
*/
|
|
9378
|
+
<A, E, R, B, X>(self: Effect<A, E, R>, filter: Filter.Filter<A, B, X>): Effect<B, Cause.NoSuchElementError | E, R>
|
|
9379
|
+
} = internal.filterMapOrFail
|
|
8866
9380
|
|
|
8867
9381
|
// -----------------------------------------------------------------------------
|
|
8868
9382
|
// Conditional Operators
|
|
@@ -9020,9 +9534,11 @@ export const when: {
|
|
|
9020
9534
|
* @example
|
|
9021
9535
|
* ```ts
|
|
9022
9536
|
* // Title: Handling Both Success and Failure Cases
|
|
9023
|
-
* import { Effect } from "effect"
|
|
9537
|
+
* import { Data, Effect } from "effect"
|
|
9538
|
+
*
|
|
9539
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9024
9540
|
*
|
|
9025
|
-
* const success: Effect.Effect<number,
|
|
9541
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9026
9542
|
*
|
|
9027
9543
|
* const program1 = Effect.match(success, {
|
|
9028
9544
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9033,8 +9549,8 @@ export const when: {
|
|
|
9033
9549
|
* Effect.runPromise(program1).then(console.log)
|
|
9034
9550
|
* // Output: "success: 42"
|
|
9035
9551
|
*
|
|
9036
|
-
* const failure: Effect.Effect<number,
|
|
9037
|
-
* new
|
|
9552
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9553
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9038
9554
|
* )
|
|
9039
9555
|
*
|
|
9040
9556
|
* const program2 = Effect.match(failure, {
|
|
@@ -9076,9 +9592,11 @@ export const match: {
|
|
|
9076
9592
|
* @example
|
|
9077
9593
|
* ```ts
|
|
9078
9594
|
* // Title: Handling Both Success and Failure Cases
|
|
9079
|
-
* import { Effect } from "effect"
|
|
9595
|
+
* import { Data, Effect } from "effect"
|
|
9080
9596
|
*
|
|
9081
|
-
*
|
|
9597
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9598
|
+
*
|
|
9599
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9082
9600
|
*
|
|
9083
9601
|
* const program1 = Effect.match(success, {
|
|
9084
9602
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9089,8 +9607,8 @@ export const match: {
|
|
|
9089
9607
|
* Effect.runPromise(program1).then(console.log)
|
|
9090
9608
|
* // Output: "success: 42"
|
|
9091
9609
|
*
|
|
9092
|
-
* const failure: Effect.Effect<number,
|
|
9093
|
-
* new
|
|
9610
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9611
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9094
9612
|
* )
|
|
9095
9613
|
*
|
|
9096
9614
|
* const program2 = Effect.match(failure, {
|
|
@@ -9137,9 +9655,11 @@ export const match: {
|
|
|
9137
9655
|
* @example
|
|
9138
9656
|
* ```ts
|
|
9139
9657
|
* // Title: Handling Both Success and Failure Cases
|
|
9140
|
-
* import { Effect } from "effect"
|
|
9658
|
+
* import { Data, Effect } from "effect"
|
|
9659
|
+
*
|
|
9660
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9141
9661
|
*
|
|
9142
|
-
* const success: Effect.Effect<number,
|
|
9662
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9143
9663
|
*
|
|
9144
9664
|
* const program1 = Effect.match(success, {
|
|
9145
9665
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9150,8 +9670,8 @@ export const match: {
|
|
|
9150
9670
|
* Effect.runPromise(program1).then(console.log)
|
|
9151
9671
|
* // Output: "success: 42"
|
|
9152
9672
|
*
|
|
9153
|
-
* const failure: Effect.Effect<number,
|
|
9154
|
-
* new
|
|
9673
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9674
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9155
9675
|
* )
|
|
9156
9676
|
*
|
|
9157
9677
|
* const program2 = Effect.match(failure, {
|
|
@@ -9581,9 +10101,11 @@ export const matchCauseEffectEager: {
|
|
|
9581
10101
|
*
|
|
9582
10102
|
* @example
|
|
9583
10103
|
* ```ts
|
|
9584
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
10104
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
9585
10105
|
*
|
|
9586
|
-
*
|
|
10106
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
10107
|
+
*
|
|
10108
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
9587
10109
|
*
|
|
9588
10110
|
* const program = Effect.matchCauseEffect(task, {
|
|
9589
10111
|
* onFailure: (cause) =>
|
|
@@ -9633,9 +10155,11 @@ export const matchCauseEffect: {
|
|
|
9633
10155
|
*
|
|
9634
10156
|
* @example
|
|
9635
10157
|
* ```ts
|
|
9636
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
10158
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
10159
|
+
*
|
|
10160
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
9637
10161
|
*
|
|
9638
|
-
* const task = Effect.fail(new
|
|
10162
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
9639
10163
|
*
|
|
9640
10164
|
* const program = Effect.matchCauseEffect(task, {
|
|
9641
10165
|
* onFailure: (cause) =>
|
|
@@ -9690,9 +10214,11 @@ export const matchCauseEffect: {
|
|
|
9690
10214
|
*
|
|
9691
10215
|
* @example
|
|
9692
10216
|
* ```ts
|
|
9693
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
10217
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
9694
10218
|
*
|
|
9695
|
-
*
|
|
10219
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
10220
|
+
*
|
|
10221
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
9696
10222
|
*
|
|
9697
10223
|
* const program = Effect.matchCauseEffect(task, {
|
|
9698
10224
|
* onFailure: (cause) =>
|
|
@@ -9756,11 +10282,13 @@ export const matchCauseEffect: {
|
|
|
9756
10282
|
* @example
|
|
9757
10283
|
* ```ts
|
|
9758
10284
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
9759
|
-
* import { Effect } from "effect"
|
|
10285
|
+
* import { Data, Effect } from "effect"
|
|
10286
|
+
*
|
|
10287
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9760
10288
|
*
|
|
9761
|
-
* const success: Effect.Effect<number,
|
|
9762
|
-
* const failure: Effect.Effect<number,
|
|
9763
|
-
* new
|
|
10289
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
10290
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
10291
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9764
10292
|
* )
|
|
9765
10293
|
*
|
|
9766
10294
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -9816,11 +10344,13 @@ export const matchEffect: {
|
|
|
9816
10344
|
* @example
|
|
9817
10345
|
* ```ts
|
|
9818
10346
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
9819
|
-
* import { Effect } from "effect"
|
|
10347
|
+
* import { Data, Effect } from "effect"
|
|
9820
10348
|
*
|
|
9821
|
-
*
|
|
9822
|
-
*
|
|
9823
|
-
*
|
|
10349
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
10350
|
+
*
|
|
10351
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
10352
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
10353
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9824
10354
|
* )
|
|
9825
10355
|
*
|
|
9826
10356
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -9881,11 +10411,13 @@ export const matchEffect: {
|
|
|
9881
10411
|
* @example
|
|
9882
10412
|
* ```ts
|
|
9883
10413
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
9884
|
-
* import { Effect } from "effect"
|
|
10414
|
+
* import { Data, Effect } from "effect"
|
|
10415
|
+
*
|
|
10416
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9885
10417
|
*
|
|
9886
|
-
* const success: Effect.Effect<number,
|
|
9887
|
-
* const failure: Effect.Effect<number,
|
|
9888
|
-
* new
|
|
10418
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
10419
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
10420
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9889
10421
|
* )
|
|
9890
10422
|
*
|
|
9891
10423
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -10028,7 +10560,7 @@ export const isSuccess: <A, E, R>(self: Effect<A, E, R>) => Effect<boolean, neve
|
|
|
10028
10560
|
* @since 2.0.0
|
|
10029
10561
|
* @category Environment
|
|
10030
10562
|
*/
|
|
10031
|
-
export const services: <R>() => Effect<ServiceMap.ServiceMap<R>, never, R> = internal.services
|
|
10563
|
+
export const services: <R = never>() => Effect<ServiceMap.ServiceMap<R>, never, R> = internal.services
|
|
10032
10564
|
|
|
10033
10565
|
/**
|
|
10034
10566
|
* Transforms the current service map using the provided function.
|
|
@@ -10094,7 +10626,7 @@ export const servicesWith: <R, A, E, R2>(
|
|
|
10094
10626
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10095
10627
|
*
|
|
10096
10628
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10097
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10629
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10098
10630
|
* })
|
|
10099
10631
|
*
|
|
10100
10632
|
* const program = Effect.gen(function*() {
|
|
@@ -10128,7 +10660,7 @@ export const provide: {
|
|
|
10128
10660
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10129
10661
|
*
|
|
10130
10662
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10131
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10663
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10132
10664
|
* })
|
|
10133
10665
|
*
|
|
10134
10666
|
* const program = Effect.gen(function*() {
|
|
@@ -10173,7 +10705,7 @@ export const provide: {
|
|
|
10173
10705
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10174
10706
|
*
|
|
10175
10707
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10176
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10708
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10177
10709
|
* })
|
|
10178
10710
|
*
|
|
10179
10711
|
* const program = Effect.gen(function*() {
|
|
@@ -10214,7 +10746,7 @@ export const provide: {
|
|
|
10214
10746
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10215
10747
|
*
|
|
10216
10748
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10217
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10749
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10218
10750
|
* })
|
|
10219
10751
|
*
|
|
10220
10752
|
* const program = Effect.gen(function*() {
|
|
@@ -10248,7 +10780,7 @@ export const provide: {
|
|
|
10248
10780
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10249
10781
|
*
|
|
10250
10782
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10251
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10783
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10252
10784
|
* })
|
|
10253
10785
|
*
|
|
10254
10786
|
* const program = Effect.gen(function*() {
|
|
@@ -10292,7 +10824,7 @@ export const provide: {
|
|
|
10292
10824
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10293
10825
|
*
|
|
10294
10826
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10295
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10827
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10296
10828
|
* })
|
|
10297
10829
|
*
|
|
10298
10830
|
* const program = Effect.gen(function*() {
|
|
@@ -10332,7 +10864,7 @@ export const provide: {
|
|
|
10332
10864
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10333
10865
|
*
|
|
10334
10866
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10335
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10867
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10336
10868
|
* })
|
|
10337
10869
|
*
|
|
10338
10870
|
* const program = Effect.gen(function*() {
|
|
@@ -10496,7 +11028,7 @@ export const provideServices: {
|
|
|
10496
11028
|
* @since 4.0.0
|
|
10497
11029
|
* @category ServiceMap
|
|
10498
11030
|
*/
|
|
10499
|
-
export const service: <I, S>(service: ServiceMap.
|
|
11031
|
+
export const service: <I, S>(service: ServiceMap.Key<I, S>) => Effect<S, never, I> = internal.service
|
|
10500
11032
|
|
|
10501
11033
|
/**
|
|
10502
11034
|
* Optionally accesses a service from the environment.
|
|
@@ -10532,7 +11064,7 @@ export const service: <I, S>(service: ServiceMap.Service<I, S>) => Effect<S, nev
|
|
|
10532
11064
|
* @since 2.0.0
|
|
10533
11065
|
* @category ServiceMap
|
|
10534
11066
|
*/
|
|
10535
|
-
export const serviceOption: <I, S>(key: ServiceMap.
|
|
11067
|
+
export const serviceOption: <I, S>(key: ServiceMap.Key<I, S>) => Effect<Option<S>> = internal.serviceOption
|
|
10536
11068
|
|
|
10537
11069
|
/**
|
|
10538
11070
|
* Provides part of the required context while leaving the rest unchanged.
|
|
@@ -10721,7 +11253,7 @@ export const updateService: {
|
|
|
10721
11253
|
* @since 2.0.0
|
|
10722
11254
|
* @category ServiceMap
|
|
10723
11255
|
*/
|
|
10724
|
-
<I, A>(service: ServiceMap.
|
|
11256
|
+
<I, A>(service: ServiceMap.Key<I, A>, f: (value: A) => A): <XA, E, R>(self: Effect<XA, E, R>) => Effect<XA, E, R | I>
|
|
10725
11257
|
/**
|
|
10726
11258
|
* Updates the service with the required service entry.
|
|
10727
11259
|
*
|
|
@@ -10750,11 +11282,7 @@ export const updateService: {
|
|
|
10750
11282
|
* @since 2.0.0
|
|
10751
11283
|
* @category ServiceMap
|
|
10752
11284
|
*/
|
|
10753
|
-
<XA, E, R, I, A>(
|
|
10754
|
-
self: Effect<XA, E, R>,
|
|
10755
|
-
service: ServiceMap.Service<I, A>,
|
|
10756
|
-
f: (value: A) => A
|
|
10757
|
-
): Effect<XA, E, R | I>
|
|
11285
|
+
<XA, E, R, I, A>(self: Effect<XA, E, R>, service: ServiceMap.Key<I, A>, f: (value: A) => A): Effect<XA, E, R | I>
|
|
10758
11286
|
} = internal.updateService
|
|
10759
11287
|
|
|
10760
11288
|
/**
|
|
@@ -10848,7 +11376,7 @@ export const provideService: {
|
|
|
10848
11376
|
* @since 2.0.0
|
|
10849
11377
|
* @category ServiceMap
|
|
10850
11378
|
*/
|
|
10851
|
-
<I, S>(service: ServiceMap.
|
|
11379
|
+
<I, S>(service: ServiceMap.Key<I, S>): {
|
|
10852
11380
|
/**
|
|
10853
11381
|
* The `provideService` function is used to provide an actual
|
|
10854
11382
|
* implementation for a service in the context of an effect.
|
|
@@ -10987,7 +11515,7 @@ export const provideService: {
|
|
|
10987
11515
|
* @since 2.0.0
|
|
10988
11516
|
* @category ServiceMap
|
|
10989
11517
|
*/
|
|
10990
|
-
<I, S>(service: ServiceMap.
|
|
11518
|
+
<I, S>(service: ServiceMap.Key<I, S>, implementation: S): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, I>>
|
|
10991
11519
|
/**
|
|
10992
11520
|
* The `provideService` function is used to provide an actual
|
|
10993
11521
|
* implementation for a service in the context of an effect.
|
|
@@ -11033,11 +11561,7 @@ export const provideService: {
|
|
|
11033
11561
|
* @since 2.0.0
|
|
11034
11562
|
* @category ServiceMap
|
|
11035
11563
|
*/
|
|
11036
|
-
<A, E, R, I, S>(
|
|
11037
|
-
self: Effect<A, E, R>,
|
|
11038
|
-
service: ServiceMap.Service<I, S>,
|
|
11039
|
-
implementation: S
|
|
11040
|
-
): Effect<A, E, Exclude<R, I>>
|
|
11564
|
+
<A, E, R, I, S>(self: Effect<A, E, R>, service: ServiceMap.Key<I, S>, implementation: S): Effect<A, E, Exclude<R, I>>
|
|
11041
11565
|
} = internal.provideService
|
|
11042
11566
|
|
|
11043
11567
|
/**
|
|
@@ -11145,7 +11669,7 @@ export const provideServiceEffect: {
|
|
|
11145
11669
|
* @since 2.0.0
|
|
11146
11670
|
* @category ServiceMap
|
|
11147
11671
|
*/
|
|
11148
|
-
<I, S, E2, R2>(service: ServiceMap.
|
|
11672
|
+
<I, S, E2, R2>(service: ServiceMap.Key<I, S>, acquire: Effect<S, E2, R2>): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E | E2, Exclude<R, I> | R2>
|
|
11149
11673
|
/**
|
|
11150
11674
|
* Provides the effect with the single service it requires. If the effect
|
|
11151
11675
|
* requires more than one service use `provide` instead.
|
|
@@ -11200,7 +11724,7 @@ export const provideServiceEffect: {
|
|
|
11200
11724
|
*/
|
|
11201
11725
|
<A, E, R, I, S, E2, R2>(
|
|
11202
11726
|
self: Effect<A, E, R>,
|
|
11203
|
-
service: ServiceMap.
|
|
11727
|
+
service: ServiceMap.Key<I, S>,
|
|
11204
11728
|
acquire: Effect<S, E2, R2>
|
|
11205
11729
|
): Effect<A, E | E2, Exclude<R, I> | R2>
|
|
11206
11730
|
} = internal.provideServiceEffect
|
|
@@ -11737,9 +12261,11 @@ export const ensuring: {
|
|
|
11737
12261
|
*
|
|
11738
12262
|
* @example
|
|
11739
12263
|
* ```ts
|
|
11740
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12264
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
11741
12265
|
*
|
|
11742
|
-
*
|
|
12266
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12267
|
+
*
|
|
12268
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
11743
12269
|
*
|
|
11744
12270
|
* const program = Effect.onError(
|
|
11745
12271
|
* task,
|
|
@@ -11748,8 +12274,8 @@ export const ensuring: {
|
|
|
11748
12274
|
*
|
|
11749
12275
|
* Effect.runPromise(program).catch(console.error)
|
|
11750
12276
|
* // Output:
|
|
11751
|
-
* // Cleanup on error:
|
|
11752
|
-
* //
|
|
12277
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12278
|
+
* // TaskError: Something went wrong
|
|
11753
12279
|
* ```
|
|
11754
12280
|
*
|
|
11755
12281
|
* @since 2.0.0
|
|
@@ -11762,9 +12288,11 @@ export const onError: {
|
|
|
11762
12288
|
*
|
|
11763
12289
|
* @example
|
|
11764
12290
|
* ```ts
|
|
11765
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12291
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
11766
12292
|
*
|
|
11767
|
-
*
|
|
12293
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12294
|
+
*
|
|
12295
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
11768
12296
|
*
|
|
11769
12297
|
* const program = Effect.onError(
|
|
11770
12298
|
* task,
|
|
@@ -11773,8 +12301,8 @@ export const onError: {
|
|
|
11773
12301
|
*
|
|
11774
12302
|
* Effect.runPromise(program).catch(console.error)
|
|
11775
12303
|
* // Output:
|
|
11776
|
-
* // Cleanup on error:
|
|
11777
|
-
* //
|
|
12304
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12305
|
+
* // TaskError: Something went wrong
|
|
11778
12306
|
* ```
|
|
11779
12307
|
*
|
|
11780
12308
|
* @since 2.0.0
|
|
@@ -11787,9 +12315,11 @@ export const onError: {
|
|
|
11787
12315
|
*
|
|
11788
12316
|
* @example
|
|
11789
12317
|
* ```ts
|
|
11790
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12318
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
11791
12319
|
*
|
|
11792
|
-
*
|
|
12320
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12321
|
+
*
|
|
12322
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
11793
12323
|
*
|
|
11794
12324
|
* const program = Effect.onError(
|
|
11795
12325
|
* task,
|
|
@@ -11798,8 +12328,8 @@ export const onError: {
|
|
|
11798
12328
|
*
|
|
11799
12329
|
* Effect.runPromise(program).catch(console.error)
|
|
11800
12330
|
* // Output:
|
|
11801
|
-
* // Cleanup on error:
|
|
11802
|
-
* //
|
|
12331
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12332
|
+
* // TaskError: Something went wrong
|
|
11803
12333
|
* ```
|
|
11804
12334
|
*
|
|
11805
12335
|
* @since 2.0.0
|
|
@@ -11813,7 +12343,7 @@ export const onError: {
|
|
|
11813
12343
|
|
|
11814
12344
|
/**
|
|
11815
12345
|
* Runs the finalizer only when this effect fails and the `Cause` matches the
|
|
11816
|
-
*
|
|
12346
|
+
* provided predicate.
|
|
11817
12347
|
*
|
|
11818
12348
|
* @example
|
|
11819
12349
|
* ```ts
|
|
@@ -11837,7 +12367,7 @@ export const onError: {
|
|
|
11837
12367
|
export const onErrorIf: {
|
|
11838
12368
|
/**
|
|
11839
12369
|
* Runs the finalizer only when this effect fails and the `Cause` matches the
|
|
11840
|
-
*
|
|
12370
|
+
* provided predicate.
|
|
11841
12371
|
*
|
|
11842
12372
|
* @example
|
|
11843
12373
|
* ```ts
|
|
@@ -11858,13 +12388,13 @@ export const onErrorIf: {
|
|
|
11858
12388
|
* @since 4.0.0
|
|
11859
12389
|
* @category Resource Management & Finalization
|
|
11860
12390
|
*/
|
|
11861
|
-
<E,
|
|
11862
|
-
|
|
11863
|
-
f: (
|
|
12391
|
+
<E, XE, XR>(
|
|
12392
|
+
predicate: Predicate.Predicate<Cause.Cause<E>>,
|
|
12393
|
+
f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>
|
|
11864
12394
|
): <A, R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
|
|
11865
12395
|
/**
|
|
11866
12396
|
* Runs the finalizer only when this effect fails and the `Cause` matches the
|
|
11867
|
-
*
|
|
12397
|
+
* provided predicate.
|
|
11868
12398
|
*
|
|
11869
12399
|
* @example
|
|
11870
12400
|
* ```ts
|
|
@@ -11885,13 +12415,43 @@ export const onErrorIf: {
|
|
|
11885
12415
|
* @since 4.0.0
|
|
11886
12416
|
* @category Resource Management & Finalization
|
|
11887
12417
|
*/
|
|
11888
|
-
<A, E, R, XE, XR
|
|
12418
|
+
<A, E, R, XE, XR>(
|
|
11889
12419
|
self: Effect<A, E, R>,
|
|
11890
|
-
|
|
11891
|
-
f: (
|
|
12420
|
+
predicate: Predicate.Predicate<Cause.Cause<E>>,
|
|
12421
|
+
f: (cause: Cause.Cause<E>) => Effect<void, XE, XR>
|
|
11892
12422
|
): Effect<A, E | XE, R | XR>
|
|
11893
12423
|
} = internal.onErrorIf
|
|
11894
12424
|
|
|
12425
|
+
/**
|
|
12426
|
+
* Runs the finalizer only when this effect fails and the cause matches the provided `Filter`.
|
|
12427
|
+
*
|
|
12428
|
+
* @since 4.0.0
|
|
12429
|
+
* @category Resource Management & Finalization
|
|
12430
|
+
*/
|
|
12431
|
+
export const onErrorFilter: {
|
|
12432
|
+
/**
|
|
12433
|
+
* Runs the finalizer only when this effect fails and the cause matches the provided `Filter`.
|
|
12434
|
+
*
|
|
12435
|
+
* @since 4.0.0
|
|
12436
|
+
* @category Resource Management & Finalization
|
|
12437
|
+
*/
|
|
12438
|
+
<A, E, EB, X, XE, XR>(
|
|
12439
|
+
filter: Filter.Filter<Cause.Cause<E>, EB, X>,
|
|
12440
|
+
f: (failure: EB, cause: Cause.Cause<E>) => Effect<void, XE, XR>
|
|
12441
|
+
): <R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
|
|
12442
|
+
/**
|
|
12443
|
+
* Runs the finalizer only when this effect fails and the cause matches the provided `Filter`.
|
|
12444
|
+
*
|
|
12445
|
+
* @since 4.0.0
|
|
12446
|
+
* @category Resource Management & Finalization
|
|
12447
|
+
*/
|
|
12448
|
+
<A, E, R, EB, X, XE, XR>(
|
|
12449
|
+
self: Effect<A, E, R>,
|
|
12450
|
+
filter: Filter.Filter<Cause.Cause<E>, EB, X>,
|
|
12451
|
+
f: (failure: EB, cause: Cause.Cause<E>) => Effect<void, XE, XR>
|
|
12452
|
+
): Effect<A, E | XE, R | XR>
|
|
12453
|
+
} = internal.onErrorFilter
|
|
12454
|
+
|
|
11895
12455
|
/**
|
|
11896
12456
|
* The low level primitive that powers `onExit`.
|
|
11897
12457
|
* function is used to run a finalizer when the effect exits, regardless of the
|
|
@@ -11990,20 +12550,20 @@ export const onExit: {
|
|
|
11990
12550
|
} = internal.onExit
|
|
11991
12551
|
|
|
11992
12552
|
/**
|
|
11993
|
-
* Runs the cleanup effect only when the `Exit`
|
|
11994
|
-
*
|
|
11995
|
-
* The cleanup is skipped when the filter returns `Filter.fail`.
|
|
12553
|
+
* Runs the cleanup effect only when the `Exit` satisfies the provided
|
|
12554
|
+
* predicate.
|
|
11996
12555
|
*
|
|
11997
12556
|
* @example
|
|
11998
12557
|
* ```ts
|
|
11999
|
-
* import { Console, Effect, Exit
|
|
12000
|
-
*
|
|
12001
|
-
* const exitFilter = Filter.fromPredicate(Exit.isSuccess<number, never>)
|
|
12558
|
+
* import { Console, Effect, Exit } from "effect"
|
|
12002
12559
|
*
|
|
12003
12560
|
* const program = Effect.onExitIf(
|
|
12004
12561
|
* Effect.succeed(42),
|
|
12005
|
-
*
|
|
12006
|
-
* (
|
|
12562
|
+
* Exit.isSuccess,
|
|
12563
|
+
* (exit) =>
|
|
12564
|
+
* Exit.isSuccess(exit)
|
|
12565
|
+
* ? Console.log(`Succeeded with: ${exit.value}`)
|
|
12566
|
+
* : Effect.void
|
|
12007
12567
|
* )
|
|
12008
12568
|
* ```
|
|
12009
12569
|
*
|
|
@@ -12012,64 +12572,88 @@ export const onExit: {
|
|
|
12012
12572
|
*/
|
|
12013
12573
|
export const onExitIf: {
|
|
12014
12574
|
/**
|
|
12015
|
-
* Runs the cleanup effect only when the `Exit`
|
|
12016
|
-
*
|
|
12017
|
-
* The cleanup is skipped when the filter returns `Filter.fail`.
|
|
12575
|
+
* Runs the cleanup effect only when the `Exit` satisfies the provided
|
|
12576
|
+
* predicate.
|
|
12018
12577
|
*
|
|
12019
12578
|
* @example
|
|
12020
12579
|
* ```ts
|
|
12021
|
-
* import { Console, Effect, Exit
|
|
12022
|
-
*
|
|
12023
|
-
* const exitFilter = Filter.fromPredicate(Exit.isSuccess<number, never>)
|
|
12580
|
+
* import { Console, Effect, Exit } from "effect"
|
|
12024
12581
|
*
|
|
12025
12582
|
* const program = Effect.onExitIf(
|
|
12026
12583
|
* Effect.succeed(42),
|
|
12027
|
-
*
|
|
12028
|
-
* (
|
|
12584
|
+
* Exit.isSuccess,
|
|
12585
|
+
* (exit) =>
|
|
12586
|
+
* Exit.isSuccess(exit)
|
|
12587
|
+
* ? Console.log(`Succeeded with: ${exit.value}`)
|
|
12588
|
+
* : Effect.void
|
|
12029
12589
|
* )
|
|
12030
12590
|
* ```
|
|
12031
12591
|
*
|
|
12032
12592
|
* @since 4.0.0
|
|
12033
12593
|
* @category Resource Management & Finalization
|
|
12034
12594
|
*/
|
|
12035
|
-
<A, E, XE, XR
|
|
12036
|
-
|
|
12037
|
-
f: (
|
|
12038
|
-
pass: Filter.Pass<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
|
|
12039
|
-
exit: Exit.Exit<NoInfer<A>, NoInfer<E>>
|
|
12040
|
-
) => Effect<void, XE, XR>
|
|
12595
|
+
<A, E, XE, XR>(
|
|
12596
|
+
predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
|
|
12597
|
+
f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect<void, XE, XR>
|
|
12041
12598
|
): <R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
|
|
12042
12599
|
/**
|
|
12043
|
-
* Runs the cleanup effect only when the `Exit`
|
|
12044
|
-
*
|
|
12045
|
-
* The cleanup is skipped when the filter returns `Filter.fail`.
|
|
12600
|
+
* Runs the cleanup effect only when the `Exit` satisfies the provided
|
|
12601
|
+
* predicate.
|
|
12046
12602
|
*
|
|
12047
12603
|
* @example
|
|
12048
12604
|
* ```ts
|
|
12049
|
-
* import { Console, Effect, Exit
|
|
12050
|
-
*
|
|
12051
|
-
* const exitFilter = Filter.fromPredicate(Exit.isSuccess<number, never>)
|
|
12605
|
+
* import { Console, Effect, Exit } from "effect"
|
|
12052
12606
|
*
|
|
12053
12607
|
* const program = Effect.onExitIf(
|
|
12054
12608
|
* Effect.succeed(42),
|
|
12055
|
-
*
|
|
12056
|
-
* (
|
|
12609
|
+
* Exit.isSuccess,
|
|
12610
|
+
* (exit) =>
|
|
12611
|
+
* Exit.isSuccess(exit)
|
|
12612
|
+
* ? Console.log(`Succeeded with: ${exit.value}`)
|
|
12613
|
+
* : Effect.void
|
|
12057
12614
|
* )
|
|
12058
12615
|
* ```
|
|
12059
12616
|
*
|
|
12060
12617
|
* @since 4.0.0
|
|
12061
12618
|
* @category Resource Management & Finalization
|
|
12062
12619
|
*/
|
|
12063
|
-
<A, E, R, XE, XR
|
|
12620
|
+
<A, E, R, XE, XR>(
|
|
12064
12621
|
self: Effect<A, E, R>,
|
|
12065
|
-
|
|
12066
|
-
f: (
|
|
12067
|
-
pass: Filter.Pass<Exit.Exit<NoInfer<A>, NoInfer<E>>, Result>,
|
|
12068
|
-
exit: Exit.Exit<NoInfer<A>, NoInfer<E>>
|
|
12069
|
-
) => Effect<void, XE, XR>
|
|
12622
|
+
predicate: Predicate.Predicate<Exit.Exit<NoInfer<A>, NoInfer<E>>>,
|
|
12623
|
+
f: (exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect<void, XE, XR>
|
|
12070
12624
|
): Effect<A, E | XE, R | XR>
|
|
12071
12625
|
} = internal.onExitIf
|
|
12072
12626
|
|
|
12627
|
+
/**
|
|
12628
|
+
* Runs the cleanup effect only when the `Exit` matches the provided `Filter`.
|
|
12629
|
+
*
|
|
12630
|
+
* @since 4.0.0
|
|
12631
|
+
* @category Resource Management & Finalization
|
|
12632
|
+
*/
|
|
12633
|
+
export const onExitFilter: {
|
|
12634
|
+
/**
|
|
12635
|
+
* Runs the cleanup effect only when the `Exit` matches the provided `Filter`.
|
|
12636
|
+
*
|
|
12637
|
+
* @since 4.0.0
|
|
12638
|
+
* @category Resource Management & Finalization
|
|
12639
|
+
*/
|
|
12640
|
+
<A, E, XE, XR, B, X>(
|
|
12641
|
+
filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
|
|
12642
|
+
f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect<void, XE, XR>
|
|
12643
|
+
): <R>(self: Effect<A, E, R>) => Effect<A, E | XE, R | XR>
|
|
12644
|
+
/**
|
|
12645
|
+
* Runs the cleanup effect only when the `Exit` matches the provided `Filter`.
|
|
12646
|
+
*
|
|
12647
|
+
* @since 4.0.0
|
|
12648
|
+
* @category Resource Management & Finalization
|
|
12649
|
+
*/
|
|
12650
|
+
<A, E, R, XE, XR, B, X>(
|
|
12651
|
+
self: Effect<A, E, R>,
|
|
12652
|
+
filter: Filter.Filter<Exit.Exit<NoInfer<A>, NoInfer<E>>, B, X>,
|
|
12653
|
+
f: (b: B, exit: Exit.Exit<NoInfer<A>, NoInfer<E>>) => Effect<void, XE, XR>
|
|
12654
|
+
): Effect<A, E | XE, R | XR>
|
|
12655
|
+
} = internal.onExitFilter
|
|
12656
|
+
|
|
12073
12657
|
// -----------------------------------------------------------------------------
|
|
12074
12658
|
// Caching
|
|
12075
12659
|
// -----------------------------------------------------------------------------
|
|
@@ -12272,7 +12856,7 @@ export const cachedWithTTL: {
|
|
|
12272
12856
|
* @since 2.0.0
|
|
12273
12857
|
* @category Caching
|
|
12274
12858
|
*/
|
|
12275
|
-
(timeToLive: Duration.
|
|
12859
|
+
(timeToLive: Duration.Input): <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A, E, R>>
|
|
12276
12860
|
/**
|
|
12277
12861
|
* Returns an effect that caches its result for a specified `Duration`,
|
|
12278
12862
|
* known as "timeToLive" (TTL).
|
|
@@ -12339,7 +12923,7 @@ export const cachedWithTTL: {
|
|
|
12339
12923
|
* @since 2.0.0
|
|
12340
12924
|
* @category Caching
|
|
12341
12925
|
*/
|
|
12342
|
-
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.
|
|
12926
|
+
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.Input): Effect<Effect<A, E, R>>
|
|
12343
12927
|
} = internal.cachedWithTTL
|
|
12344
12928
|
|
|
12345
12929
|
/**
|
|
@@ -12481,7 +13065,7 @@ export const cachedInvalidateWithTTL: {
|
|
|
12481
13065
|
* @since 2.0.0
|
|
12482
13066
|
* @category Caching
|
|
12483
13067
|
*/
|
|
12484
|
-
(timeToLive: Duration.
|
|
13068
|
+
(timeToLive: Duration.Input): <A, E, R>(self: Effect<A, E, R>) => Effect<[Effect<A, E, R>, Effect<void>]>
|
|
12485
13069
|
/**
|
|
12486
13070
|
* Caches an effect's result for a specified duration and allows manual
|
|
12487
13071
|
* invalidation before expiration.
|
|
@@ -12551,7 +13135,7 @@ export const cachedInvalidateWithTTL: {
|
|
|
12551
13135
|
* @since 2.0.0
|
|
12552
13136
|
* @category Caching
|
|
12553
13137
|
*/
|
|
12554
|
-
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.
|
|
13138
|
+
<A, E, R>(self: Effect<A, E, R>, timeToLive: Duration.Input): Effect<[Effect<A, E, R>, Effect<void>]>
|
|
12555
13139
|
} = internal.cachedInvalidateWithTTL
|
|
12556
13140
|
|
|
12557
13141
|
// -----------------------------------------------------------------------------
|
|
@@ -12566,8 +13150,8 @@ export const cachedInvalidateWithTTL: {
|
|
|
12566
13150
|
* import { Effect } from "effect"
|
|
12567
13151
|
*
|
|
12568
13152
|
* const program = Effect.gen(function*() {
|
|
12569
|
-
* yield* Effect.interrupt
|
|
12570
|
-
* yield* Effect.succeed("This won't execute")
|
|
13153
|
+
* return yield* Effect.interrupt
|
|
13154
|
+
* yield* Effect.succeed("This won't execute and is unreachable")
|
|
12571
13155
|
* })
|
|
12572
13156
|
*
|
|
12573
13157
|
* Effect.runPromise(program).catch(console.error)
|
|
@@ -12667,361 +13251,115 @@ export const onInterrupt: {
|
|
|
12667
13251
|
* const fiber = Effect.runFork(program)
|
|
12668
13252
|
* // Later interrupt the task
|
|
12669
13253
|
* Effect.runFork(Fiber.interrupt(fiber))
|
|
12670
|
-
* // Output: Task was interrupted, cleaning up...
|
|
12671
|
-
* ```
|
|
12672
|
-
*
|
|
12673
|
-
* @since 2.0.0
|
|
12674
|
-
* @category Interruption
|
|
12675
|
-
*/
|
|
12676
|
-
<A, E, R, XE, XR>(
|
|
12677
|
-
self: Effect<A, E, R>,
|
|
12678
|
-
finalizer: (interruptors: ReadonlySet<number>) => Effect<void, XE, XR>
|
|
12679
|
-
): Effect<A, E | XE, R | XR>
|
|
12680
|
-
} = internal.onInterrupt
|
|
12681
|
-
|
|
12682
|
-
/**
|
|
12683
|
-
* Returns a new effect that disables interruption for the given effect.
|
|
12684
|
-
*
|
|
12685
|
-
* @example
|
|
12686
|
-
* ```ts
|
|
12687
|
-
* import { Console, Effect, Fiber } from "effect"
|
|
12688
|
-
*
|
|
12689
|
-
* const criticalTask = Effect.gen(function*() {
|
|
12690
|
-
* yield* Console.log("Starting critical section...")
|
|
12691
|
-
* yield* Effect.sleep("2 seconds")
|
|
12692
|
-
* yield* Console.log("Critical section completed")
|
|
12693
|
-
* })
|
|
12694
|
-
*
|
|
12695
|
-
* const program = Effect.uninterruptible(criticalTask)
|
|
12696
|
-
*
|
|
12697
|
-
* const fiber = Effect.runFork(program)
|
|
12698
|
-
* // Even if interrupted, the critical task will complete
|
|
12699
|
-
* Effect.runPromise(Fiber.interrupt(fiber))
|
|
12700
|
-
* ```
|
|
12701
|
-
*
|
|
12702
|
-
* @since 2.0.0
|
|
12703
|
-
* @category Interruption
|
|
12704
|
-
*/
|
|
12705
|
-
export const uninterruptible: <A, E, R>(
|
|
12706
|
-
self: Effect<A, E, R>
|
|
12707
|
-
) => Effect<A, E, R> = internal.uninterruptible
|
|
12708
|
-
|
|
12709
|
-
/**
|
|
12710
|
-
* Disables interruption and provides a restore function to restore the
|
|
12711
|
-
* interruptible state within the effect.
|
|
12712
|
-
*
|
|
12713
|
-
* @example
|
|
12714
|
-
* ```ts
|
|
12715
|
-
* import { Console, Effect } from "effect"
|
|
12716
|
-
*
|
|
12717
|
-
* const program = Effect.uninterruptibleMask((restore) =>
|
|
12718
|
-
* Effect.gen(function*() {
|
|
12719
|
-
* yield* Console.log("Uninterruptible phase...")
|
|
12720
|
-
* yield* Effect.sleep("1 second")
|
|
12721
|
-
*
|
|
12722
|
-
* // Restore interruptibility for this part
|
|
12723
|
-
* yield* restore(
|
|
12724
|
-
* Effect.gen(function*() {
|
|
12725
|
-
* yield* Console.log("Interruptible phase...")
|
|
12726
|
-
* yield* Effect.sleep("2 seconds")
|
|
12727
|
-
* })
|
|
12728
|
-
* )
|
|
12729
|
-
*
|
|
12730
|
-
* yield* Console.log("Back to uninterruptible")
|
|
12731
|
-
* })
|
|
12732
|
-
* )
|
|
12733
|
-
* ```
|
|
12734
|
-
*
|
|
12735
|
-
* @since 2.0.0
|
|
12736
|
-
* @category Interruption
|
|
12737
|
-
*/
|
|
12738
|
-
export const uninterruptibleMask: <A, E, R>(
|
|
12739
|
-
f: (
|
|
12740
|
-
restore: <AX, EX, RX>(effect: Effect<AX, EX, RX>) => Effect<AX, EX, RX>
|
|
12741
|
-
) => Effect<A, E, R>
|
|
12742
|
-
) => Effect<A, E, R> = internal.uninterruptibleMask
|
|
12743
|
-
|
|
12744
|
-
/**
|
|
12745
|
-
* This function behaves like {@link interruptible}, but it also provides a
|
|
12746
|
-
* `restore` function. This function can be used to restore the interruptibility
|
|
12747
|
-
* of any specific region of code.
|
|
12748
|
-
*
|
|
12749
|
-
* @example
|
|
12750
|
-
* ```ts
|
|
12751
|
-
* import { Console, Effect } from "effect"
|
|
12752
|
-
*
|
|
12753
|
-
* const program = Effect.interruptibleMask((restore) =>
|
|
12754
|
-
* Effect.gen(function*() {
|
|
12755
|
-
* yield* Console.log("Interruptible phase...")
|
|
12756
|
-
* yield* Effect.sleep("1 second")
|
|
12757
|
-
*
|
|
12758
|
-
* // Make this part uninterruptible
|
|
12759
|
-
* yield* restore(
|
|
12760
|
-
* Effect.gen(function*() {
|
|
12761
|
-
* yield* Console.log("Uninterruptible phase...")
|
|
12762
|
-
* yield* Effect.sleep("2 seconds")
|
|
12763
|
-
* })
|
|
12764
|
-
* )
|
|
12765
|
-
*
|
|
12766
|
-
* yield* Console.log("Back to interruptible")
|
|
12767
|
-
* })
|
|
12768
|
-
* )
|
|
12769
|
-
* ```
|
|
12770
|
-
*
|
|
12771
|
-
* @since 2.0.0
|
|
12772
|
-
* @category Interruption
|
|
12773
|
-
*/
|
|
12774
|
-
export const interruptibleMask: <A, E, R>(
|
|
12775
|
-
f: (
|
|
12776
|
-
restore: <AX, EX, RX>(effect: Effect<AX, EX, RX>) => Effect<AX, EX, RX>
|
|
12777
|
-
) => Effect<A, E, R>
|
|
12778
|
-
) => Effect<A, E, R> = internal.interruptibleMask
|
|
12779
|
-
|
|
12780
|
-
// -----------------------------------------------------------------------------
|
|
12781
|
-
// Semaphore
|
|
12782
|
-
// -----------------------------------------------------------------------------
|
|
12783
|
-
|
|
12784
|
-
/**
|
|
12785
|
-
* @category Semaphore
|
|
12786
|
-
* @since 2.0.0
|
|
12787
|
-
* @example
|
|
12788
|
-
* ```ts
|
|
12789
|
-
* import { Effect } from "effect"
|
|
12790
|
-
*
|
|
12791
|
-
* // Create and use a semaphore for controlling concurrent access
|
|
12792
|
-
* const program = Effect.gen(function*() {
|
|
12793
|
-
* const semaphore = yield* Effect.makeSemaphore(2)
|
|
12794
|
-
*
|
|
12795
|
-
* return yield* semaphore.withPermits(1)(
|
|
12796
|
-
* Effect.succeed("Resource accessed")
|
|
12797
|
-
* )
|
|
12798
|
-
* })
|
|
12799
|
-
* ```
|
|
12800
|
-
*/
|
|
12801
|
-
export interface Semaphore {
|
|
12802
|
-
/**
|
|
12803
|
-
* Adjusts the number of permits available in the semaphore.
|
|
12804
|
-
*/
|
|
12805
|
-
resize(permits: number): Effect<void>
|
|
12806
|
-
|
|
12807
|
-
/**
|
|
12808
|
-
* Runs an effect with the given number of permits and releases the permits
|
|
12809
|
-
* when the effect completes.
|
|
12810
|
-
*
|
|
12811
|
-
* **Details**
|
|
12812
|
-
*
|
|
12813
|
-
* This function acquires the specified number of permits before executing
|
|
12814
|
-
* the provided effect. Once the effect finishes, the permits are released.
|
|
12815
|
-
* If insufficient permits are available, the function will wait until they
|
|
12816
|
-
* are released by other tasks.
|
|
12817
|
-
*/
|
|
12818
|
-
withPermits(permits: number): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
|
|
12819
|
-
|
|
12820
|
-
/**
|
|
12821
|
-
* Runs an effect with the given number of permits and releases the permits
|
|
12822
|
-
* when the effect completes.
|
|
12823
|
-
*
|
|
12824
|
-
* **Details**
|
|
12825
|
-
*
|
|
12826
|
-
* This function acquires the specified number of permits before executing
|
|
12827
|
-
* the provided effect. Once the effect finishes, the permits are released.
|
|
12828
|
-
* If insufficient permits are available, the function will wait until they
|
|
12829
|
-
* are released by other tasks.
|
|
12830
|
-
*/
|
|
12831
|
-
withPermit<A, E, R>(self: Effect<A, E, R>): Effect<A, E, R>
|
|
12832
|
-
|
|
12833
|
-
/**
|
|
12834
|
-
* Runs an effect only if the specified number of permits are immediately
|
|
12835
|
-
* available.
|
|
12836
|
-
*
|
|
12837
|
-
* **Details**
|
|
12838
|
-
*
|
|
12839
|
-
* This function attempts to acquire the specified number of permits. If they
|
|
12840
|
-
* are available, it runs the effect and releases the permits after the effect
|
|
12841
|
-
* completes. If permits are not available, the effect does not execute, and
|
|
12842
|
-
* the result is `Option.none`.
|
|
12843
|
-
*/
|
|
12844
|
-
withPermitsIfAvailable(permits: number): <A, E, R>(self: Effect<A, E, R>) => Effect<Option<A>, E, R>
|
|
12845
|
-
|
|
12846
|
-
/**
|
|
12847
|
-
* Acquires the specified number of permits and returns the resulting
|
|
12848
|
-
* available permits, suspending the task if they are not yet available.
|
|
12849
|
-
* Concurrent pending `take` calls are processed in a first-in, first-out manner.
|
|
12850
|
-
*/
|
|
12851
|
-
take(permits: number): Effect<number>
|
|
12852
|
-
|
|
12853
|
-
/**
|
|
12854
|
-
* Releases the specified number of permits and returns the resulting
|
|
12855
|
-
* available permits.
|
|
12856
|
-
*/
|
|
12857
|
-
release(permits: number): Effect<number>
|
|
12858
|
-
|
|
12859
|
-
/**
|
|
12860
|
-
* Releases all permits held by this semaphore and returns the resulting available permits.
|
|
13254
|
+
* // Output: Task was interrupted, cleaning up...
|
|
13255
|
+
* ```
|
|
13256
|
+
*
|
|
13257
|
+
* @since 2.0.0
|
|
13258
|
+
* @category Interruption
|
|
12861
13259
|
*/
|
|
12862
|
-
|
|
12863
|
-
|
|
13260
|
+
<A, E, R, XE, XR>(
|
|
13261
|
+
self: Effect<A, E, R>,
|
|
13262
|
+
finalizer: (interruptors: ReadonlySet<number>) => Effect<void, XE, XR>
|
|
13263
|
+
): Effect<A, E | XE, R | XR>
|
|
13264
|
+
} = internal.onInterrupt
|
|
12864
13265
|
|
|
12865
13266
|
/**
|
|
12866
|
-
*
|
|
13267
|
+
* Returns a new effect that disables interruption for the given effect.
|
|
12867
13268
|
*
|
|
12868
13269
|
* @example
|
|
12869
13270
|
* ```ts
|
|
12870
|
-
* import { Effect } from "effect"
|
|
13271
|
+
* import { Console, Effect, Fiber } from "effect"
|
|
12871
13272
|
*
|
|
12872
|
-
* const
|
|
13273
|
+
* const criticalTask = Effect.gen(function*() {
|
|
13274
|
+
* yield* Console.log("Starting critical section...")
|
|
13275
|
+
* yield* Effect.sleep("2 seconds")
|
|
13276
|
+
* yield* Console.log("Critical section completed")
|
|
13277
|
+
* })
|
|
12873
13278
|
*
|
|
12874
|
-
* const
|
|
12875
|
-
* semaphore.withPermits(1)(
|
|
12876
|
-
* Effect.gen(function*() {
|
|
12877
|
-
* yield* Effect.log(`Task ${id} started`)
|
|
12878
|
-
* yield* Effect.sleep("1 second")
|
|
12879
|
-
* yield* Effect.log(`Task ${id} completed`)
|
|
12880
|
-
* })
|
|
12881
|
-
* )
|
|
13279
|
+
* const program = Effect.uninterruptible(criticalTask)
|
|
12882
13280
|
*
|
|
12883
|
-
*
|
|
12884
|
-
*
|
|
12885
|
-
*
|
|
12886
|
-
* task(2),
|
|
12887
|
-
* task(3),
|
|
12888
|
-
* task(4),
|
|
12889
|
-
* task(5)
|
|
12890
|
-
* ], { concurrency: "unbounded" })
|
|
13281
|
+
* const fiber = Effect.runFork(program)
|
|
13282
|
+
* // Even if interrupted, the critical task will complete
|
|
13283
|
+
* Effect.runPromise(Fiber.interrupt(fiber))
|
|
12891
13284
|
* ```
|
|
12892
13285
|
*
|
|
12893
13286
|
* @since 2.0.0
|
|
12894
|
-
* @category
|
|
13287
|
+
* @category Interruption
|
|
12895
13288
|
*/
|
|
12896
|
-
export const
|
|
13289
|
+
export const uninterruptible: <A, E, R>(
|
|
13290
|
+
self: Effect<A, E, R>
|
|
13291
|
+
) => Effect<A, E, R> = internal.uninterruptible
|
|
12897
13292
|
|
|
12898
13293
|
/**
|
|
12899
|
-
*
|
|
13294
|
+
* Disables interruption and provides a restore function to restore the
|
|
13295
|
+
* interruptible state within the effect.
|
|
12900
13296
|
*
|
|
12901
13297
|
* @example
|
|
12902
13298
|
* ```ts
|
|
12903
|
-
* import { Effect } from "effect"
|
|
13299
|
+
* import { Console, Effect } from "effect"
|
|
12904
13300
|
*
|
|
12905
|
-
* const program = Effect.
|
|
12906
|
-
*
|
|
13301
|
+
* const program = Effect.uninterruptibleMask((restore) =>
|
|
13302
|
+
* Effect.gen(function*() {
|
|
13303
|
+
* yield* Console.log("Uninterruptible phase...")
|
|
13304
|
+
* yield* Effect.sleep("1 second")
|
|
12907
13305
|
*
|
|
12908
|
-
*
|
|
12909
|
-
*
|
|
13306
|
+
* // Restore interruptibility for this part
|
|
13307
|
+
* yield* restore(
|
|
12910
13308
|
* Effect.gen(function*() {
|
|
12911
|
-
* yield*
|
|
12912
|
-
* yield* Effect.sleep("
|
|
12913
|
-
* yield* Effect.log(`Task ${id} releasing permit`)
|
|
13309
|
+
* yield* Console.log("Interruptible phase...")
|
|
13310
|
+
* yield* Effect.sleep("2 seconds")
|
|
12914
13311
|
* })
|
|
12915
13312
|
* )
|
|
12916
13313
|
*
|
|
12917
|
-
*
|
|
12918
|
-
*
|
|
12919
|
-
*
|
|
13314
|
+
* yield* Console.log("Back to uninterruptible")
|
|
13315
|
+
* })
|
|
13316
|
+
* )
|
|
12920
13317
|
* ```
|
|
12921
13318
|
*
|
|
12922
13319
|
* @since 2.0.0
|
|
12923
|
-
* @category
|
|
12924
|
-
*/
|
|
12925
|
-
export const makeSemaphore: (permits: number) => Effect<Semaphore> = internal.makeSemaphore
|
|
12926
|
-
|
|
12927
|
-
// -----------------------------------------------------------------------------
|
|
12928
|
-
// Latch
|
|
12929
|
-
// -----------------------------------------------------------------------------
|
|
12930
|
-
|
|
12931
|
-
/**
|
|
12932
|
-
* @category Latch
|
|
12933
|
-
* @since 3.8.0
|
|
12934
|
-
* @example
|
|
12935
|
-
* ```ts
|
|
12936
|
-
* import { Effect } from "effect"
|
|
12937
|
-
*
|
|
12938
|
-
* // Create and use a latch for coordination between fibers
|
|
12939
|
-
* const program = Effect.gen(function*() {
|
|
12940
|
-
* const latch = yield* Effect.makeLatch()
|
|
12941
|
-
*
|
|
12942
|
-
* // Wait for the latch to be opened
|
|
12943
|
-
* yield* latch.await
|
|
12944
|
-
*
|
|
12945
|
-
* return "Latch was opened!"
|
|
12946
|
-
* })
|
|
12947
|
-
* ```
|
|
12948
|
-
*/
|
|
12949
|
-
export interface Latch {
|
|
12950
|
-
/** open the latch, releasing all fibers waiting on it */
|
|
12951
|
-
readonly open: Effect<boolean>
|
|
12952
|
-
/** open the latch, releasing all fibers waiting on it */
|
|
12953
|
-
readonly openUnsafe: () => boolean
|
|
12954
|
-
/** release all fibers waiting on the latch, without opening it */
|
|
12955
|
-
readonly release: Effect<boolean>
|
|
12956
|
-
/** wait for the latch to be opened */
|
|
12957
|
-
readonly await: Effect<void>
|
|
12958
|
-
/** close the latch */
|
|
12959
|
-
readonly close: Effect<boolean>
|
|
12960
|
-
/** close the latch */
|
|
12961
|
-
readonly closeUnsafe: () => boolean
|
|
12962
|
-
/** only run the given effect when the latch is open */
|
|
12963
|
-
readonly whenOpen: <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
|
|
12964
|
-
}
|
|
12965
|
-
|
|
12966
|
-
/**
|
|
12967
|
-
* Creates a new Latch.
|
|
12968
|
-
*
|
|
12969
|
-
* @example
|
|
12970
|
-
* ```ts
|
|
12971
|
-
* import { Effect } from "effect"
|
|
12972
|
-
*
|
|
12973
|
-
* const latch = Effect.makeLatchUnsafe(false)
|
|
12974
|
-
*
|
|
12975
|
-
* const waiter = Effect.gen(function*() {
|
|
12976
|
-
* yield* Effect.log("Waiting for latch to open...")
|
|
12977
|
-
* yield* latch.await
|
|
12978
|
-
* yield* Effect.log("Latch opened! Continuing...")
|
|
12979
|
-
* })
|
|
12980
|
-
*
|
|
12981
|
-
* const opener = Effect.gen(function*() {
|
|
12982
|
-
* yield* Effect.sleep("2 seconds")
|
|
12983
|
-
* yield* Effect.log("Opening latch...")
|
|
12984
|
-
* yield* latch.open
|
|
12985
|
-
* })
|
|
12986
|
-
*
|
|
12987
|
-
* const program = Effect.all([waiter, opener])
|
|
12988
|
-
* ```
|
|
12989
|
-
*
|
|
12990
|
-
* @category Latch
|
|
12991
|
-
* @since 3.8.0
|
|
13320
|
+
* @category Interruption
|
|
12992
13321
|
*/
|
|
12993
|
-
export const
|
|
13322
|
+
export const uninterruptibleMask: <A, E, R>(
|
|
13323
|
+
f: (
|
|
13324
|
+
restore: <AX, EX, RX>(effect: Effect<AX, EX, RX>) => Effect<AX, EX, RX>
|
|
13325
|
+
) => Effect<A, E, R>
|
|
13326
|
+
) => Effect<A, E, R> = internal.uninterruptibleMask
|
|
12994
13327
|
|
|
12995
13328
|
/**
|
|
12996
|
-
*
|
|
13329
|
+
* This function behaves like {@link interruptible}, but it also provides a
|
|
13330
|
+
* `restore` function. This function can be used to restore the interruptibility
|
|
13331
|
+
* of any specific region of code.
|
|
12997
13332
|
*
|
|
12998
13333
|
* @example
|
|
12999
13334
|
* ```ts
|
|
13000
|
-
* import { Effect } from "effect"
|
|
13335
|
+
* import { Console, Effect } from "effect"
|
|
13001
13336
|
*
|
|
13002
|
-
* const program = Effect.
|
|
13003
|
-
*
|
|
13337
|
+
* const program = Effect.interruptibleMask((restore) =>
|
|
13338
|
+
* Effect.gen(function*() {
|
|
13339
|
+
* yield* Console.log("Interruptible phase...")
|
|
13340
|
+
* yield* Effect.sleep("1 second")
|
|
13004
13341
|
*
|
|
13005
|
-
*
|
|
13006
|
-
* yield*
|
|
13007
|
-
*
|
|
13008
|
-
*
|
|
13009
|
-
*
|
|
13342
|
+
* // Make this part uninterruptible
|
|
13343
|
+
* yield* restore(
|
|
13344
|
+
* Effect.gen(function*() {
|
|
13345
|
+
* yield* Console.log("Uninterruptible phase...")
|
|
13346
|
+
* yield* Effect.sleep("2 seconds")
|
|
13347
|
+
* })
|
|
13348
|
+
* )
|
|
13010
13349
|
*
|
|
13011
|
-
*
|
|
13012
|
-
* yield* Effect.sleep("2 seconds")
|
|
13013
|
-
* yield* Effect.log("Opening latch...")
|
|
13014
|
-
* yield* latch.open
|
|
13350
|
+
* yield* Console.log("Back to interruptible")
|
|
13015
13351
|
* })
|
|
13016
|
-
*
|
|
13017
|
-
* yield* Effect.all([waiter, opener])
|
|
13018
|
-
* })
|
|
13352
|
+
* )
|
|
13019
13353
|
* ```
|
|
13020
13354
|
*
|
|
13021
|
-
* @
|
|
13022
|
-
* @
|
|
13355
|
+
* @since 2.0.0
|
|
13356
|
+
* @category Interruption
|
|
13023
13357
|
*/
|
|
13024
|
-
export const
|
|
13358
|
+
export const interruptibleMask: <A, E, R>(
|
|
13359
|
+
f: (
|
|
13360
|
+
restore: <AX, EX, RX>(effect: Effect<AX, EX, RX>) => Effect<AX, EX, RX>
|
|
13361
|
+
) => Effect<A, E, R>
|
|
13362
|
+
) => Effect<A, E, R> = internal.interruptibleMask
|
|
13025
13363
|
|
|
13026
13364
|
// -----------------------------------------------------------------------------
|
|
13027
13365
|
// Repetition & Recursion
|
|
@@ -13640,7 +13978,7 @@ export const repeat: {
|
|
|
13640
13978
|
* attempt++
|
|
13641
13979
|
* if (attempt <= 2) {
|
|
13642
13980
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
13643
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
13981
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
13644
13982
|
* }
|
|
13645
13983
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
13646
13984
|
* return "success"
|
|
@@ -13690,7 +14028,7 @@ export const repeatOrElse: {
|
|
|
13690
14028
|
* attempt++
|
|
13691
14029
|
* if (attempt <= 2) {
|
|
13692
14030
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
13693
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
14031
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
13694
14032
|
* }
|
|
13695
14033
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
13696
14034
|
* return "success"
|
|
@@ -13743,7 +14081,7 @@ export const repeatOrElse: {
|
|
|
13743
14081
|
* attempt++
|
|
13744
14082
|
* if (attempt <= 2) {
|
|
13745
14083
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
13746
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
14084
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
13747
14085
|
* }
|
|
13748
14086
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
13749
14087
|
* return "success"
|
|
@@ -15208,7 +15546,7 @@ export const withParentSpan: {
|
|
|
15208
15546
|
* )
|
|
15209
15547
|
*
|
|
15210
15548
|
* const program = Effect.gen(function*() {
|
|
15211
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15549
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15212
15550
|
* yield* Console.log(name)
|
|
15213
15551
|
* })
|
|
15214
15552
|
* ```
|
|
@@ -15243,7 +15581,7 @@ export const request: {
|
|
|
15243
15581
|
* )
|
|
15244
15582
|
*
|
|
15245
15583
|
* const program = Effect.gen(function*() {
|
|
15246
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15584
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15247
15585
|
* yield* Console.log(name)
|
|
15248
15586
|
* })
|
|
15249
15587
|
* ```
|
|
@@ -15278,7 +15616,7 @@ export const request: {
|
|
|
15278
15616
|
* )
|
|
15279
15617
|
*
|
|
15280
15618
|
* const program = Effect.gen(function*() {
|
|
15281
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15619
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15282
15620
|
* yield* Console.log(name)
|
|
15283
15621
|
* })
|
|
15284
15622
|
* ```
|
|
@@ -15516,7 +15854,7 @@ export const forkScoped: <
|
|
|
15516
15854
|
readonly startImmediately?: boolean | undefined
|
|
15517
15855
|
readonly uninterruptible?: boolean | "inherit" | undefined
|
|
15518
15856
|
} | undefined
|
|
15519
|
-
) => [Arg] extends [Effect<infer _A, infer _E, infer _R>] ? Effect<Fiber<_A, _E>, never, _R>
|
|
15857
|
+
) => [Arg] extends [Effect<infer _A, infer _E, infer _R>] ? Effect<Fiber<_A, _E>, never, _R | Scope>
|
|
15520
15858
|
: <A, E, R>(self: Effect<A, E, R>) => Effect<Fiber<A, E>, never, R | Scope> = internal.forkScoped
|
|
15521
15859
|
|
|
15522
15860
|
/**
|
|
@@ -20339,7 +20677,7 @@ export const clockWith: <A, E, R>(
|
|
|
20339
20677
|
* @since 2.0.0
|
|
20340
20678
|
* @category Logging
|
|
20341
20679
|
*/
|
|
20342
|
-
export const logWithLevel: (level?:
|
|
20680
|
+
export const logWithLevel: (level?: Severity) => (...message: ReadonlyArray<any>) => Effect<void> =
|
|
20343
20681
|
internal.logWithLevel
|
|
20344
20682
|
|
|
20345
20683
|
/**
|
|
@@ -20767,6 +21105,86 @@ export const annotateLogs = dual<
|
|
|
20767
21105
|
})
|
|
20768
21106
|
)
|
|
20769
21107
|
|
|
21108
|
+
/**
|
|
21109
|
+
* Adds log annotations to the current scope.
|
|
21110
|
+
*
|
|
21111
|
+
* This differs from `annotateLogs`, which only annotates a specific effect.
|
|
21112
|
+
* `annotateLogsScoped` updates annotations for the entire current `Scope` and
|
|
21113
|
+
* restores the previous annotations when the scope closes.
|
|
21114
|
+
*
|
|
21115
|
+
* @example
|
|
21116
|
+
* ```ts
|
|
21117
|
+
* import { Effect } from "effect"
|
|
21118
|
+
*
|
|
21119
|
+
* const program = Effect.scoped(
|
|
21120
|
+
* Effect.gen(function*() {
|
|
21121
|
+
* yield* Effect.log("before")
|
|
21122
|
+
* yield* Effect.annotateLogsScoped({ requestId: "req-123" })
|
|
21123
|
+
* yield* Effect.log("inside scope")
|
|
21124
|
+
* })
|
|
21125
|
+
* )
|
|
21126
|
+
*
|
|
21127
|
+
* Effect.runPromise(program)
|
|
21128
|
+
* ```
|
|
21129
|
+
*
|
|
21130
|
+
* @since 4.0.0
|
|
21131
|
+
* @category Logging
|
|
21132
|
+
*/
|
|
21133
|
+
export const annotateLogsScoped: {
|
|
21134
|
+
/**
|
|
21135
|
+
* Adds log annotations to the current scope.
|
|
21136
|
+
*
|
|
21137
|
+
* This differs from `annotateLogs`, which only annotates a specific effect.
|
|
21138
|
+
* `annotateLogsScoped` updates annotations for the entire current `Scope` and
|
|
21139
|
+
* restores the previous annotations when the scope closes.
|
|
21140
|
+
*
|
|
21141
|
+
* @example
|
|
21142
|
+
* ```ts
|
|
21143
|
+
* import { Effect } from "effect"
|
|
21144
|
+
*
|
|
21145
|
+
* const program = Effect.scoped(
|
|
21146
|
+
* Effect.gen(function*() {
|
|
21147
|
+
* yield* Effect.log("before")
|
|
21148
|
+
* yield* Effect.annotateLogsScoped({ requestId: "req-123" })
|
|
21149
|
+
* yield* Effect.log("inside scope")
|
|
21150
|
+
* })
|
|
21151
|
+
* )
|
|
21152
|
+
*
|
|
21153
|
+
* Effect.runPromise(program)
|
|
21154
|
+
* ```
|
|
21155
|
+
*
|
|
21156
|
+
* @since 4.0.0
|
|
21157
|
+
* @category Logging
|
|
21158
|
+
*/
|
|
21159
|
+
(key: string, value: unknown): Effect<void, never, Scope>
|
|
21160
|
+
/**
|
|
21161
|
+
* Adds log annotations to the current scope.
|
|
21162
|
+
*
|
|
21163
|
+
* This differs from `annotateLogs`, which only annotates a specific effect.
|
|
21164
|
+
* `annotateLogsScoped` updates annotations for the entire current `Scope` and
|
|
21165
|
+
* restores the previous annotations when the scope closes.
|
|
21166
|
+
*
|
|
21167
|
+
* @example
|
|
21168
|
+
* ```ts
|
|
21169
|
+
* import { Effect } from "effect"
|
|
21170
|
+
*
|
|
21171
|
+
* const program = Effect.scoped(
|
|
21172
|
+
* Effect.gen(function*() {
|
|
21173
|
+
* yield* Effect.log("before")
|
|
21174
|
+
* yield* Effect.annotateLogsScoped({ requestId: "req-123" })
|
|
21175
|
+
* yield* Effect.log("inside scope")
|
|
21176
|
+
* })
|
|
21177
|
+
* )
|
|
21178
|
+
*
|
|
21179
|
+
* Effect.runPromise(program)
|
|
21180
|
+
* ```
|
|
21181
|
+
*
|
|
21182
|
+
* @since 4.0.0
|
|
21183
|
+
* @category Logging
|
|
21184
|
+
*/
|
|
21185
|
+
(values: Record<string, unknown>): Effect<void, never, Scope>
|
|
21186
|
+
} = internal.annotateLogsScoped
|
|
21187
|
+
|
|
20770
21188
|
/**
|
|
20771
21189
|
* Adds a span to each log line in this effect.
|
|
20772
21190
|
*
|
|
@@ -21429,18 +21847,20 @@ export const trackSuccesses: {
|
|
|
21429
21847
|
*
|
|
21430
21848
|
* @example
|
|
21431
21849
|
* ```ts
|
|
21432
|
-
* import { Effect, Metric } from "effect"
|
|
21850
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21851
|
+
*
|
|
21852
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21433
21853
|
*
|
|
21434
21854
|
* // Track error types using frequency metric
|
|
21435
21855
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21436
21856
|
*
|
|
21437
|
-
* const program = Effect.fail(new
|
|
21438
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21857
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21858
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21439
21859
|
* )
|
|
21440
21860
|
*
|
|
21441
21861
|
* Effect.runPromiseExit(program).then(() =>
|
|
21442
21862
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21443
|
-
* // Output: { occurrences: Map(1) { "
|
|
21863
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21444
21864
|
* )
|
|
21445
21865
|
* ```
|
|
21446
21866
|
*
|
|
@@ -21475,18 +21895,20 @@ export const trackErrors: {
|
|
|
21475
21895
|
*
|
|
21476
21896
|
* @example
|
|
21477
21897
|
* ```ts
|
|
21478
|
-
* import { Effect, Metric } from "effect"
|
|
21898
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21899
|
+
*
|
|
21900
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21479
21901
|
*
|
|
21480
21902
|
* // Track error types using frequency metric
|
|
21481
21903
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21482
21904
|
*
|
|
21483
|
-
* const program = Effect.fail(new
|
|
21484
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21905
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21906
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21485
21907
|
* )
|
|
21486
21908
|
*
|
|
21487
21909
|
* Effect.runPromiseExit(program).then(() =>
|
|
21488
21910
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21489
|
-
* // Output: { occurrences: Map(1) { "
|
|
21911
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21490
21912
|
* )
|
|
21491
21913
|
* ```
|
|
21492
21914
|
*
|
|
@@ -21521,18 +21943,20 @@ export const trackErrors: {
|
|
|
21521
21943
|
*
|
|
21522
21944
|
* @example
|
|
21523
21945
|
* ```ts
|
|
21524
|
-
* import { Effect, Metric } from "effect"
|
|
21946
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21947
|
+
*
|
|
21948
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21525
21949
|
*
|
|
21526
21950
|
* // Track error types using frequency metric
|
|
21527
21951
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21528
21952
|
*
|
|
21529
|
-
* const program = Effect.fail(new
|
|
21530
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21953
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21954
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21531
21955
|
* )
|
|
21532
21956
|
*
|
|
21533
21957
|
* Effect.runPromiseExit(program).then(() =>
|
|
21534
21958
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21535
|
-
* // Output: { occurrences: Map(1) { "
|
|
21959
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21536
21960
|
* )
|
|
21537
21961
|
* ```
|
|
21538
21962
|
*
|
|
@@ -21567,18 +21991,20 @@ export const trackErrors: {
|
|
|
21567
21991
|
*
|
|
21568
21992
|
* @example
|
|
21569
21993
|
* ```ts
|
|
21570
|
-
* import { Effect, Metric } from "effect"
|
|
21994
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21995
|
+
*
|
|
21996
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21571
21997
|
*
|
|
21572
21998
|
* // Track error types using frequency metric
|
|
21573
21999
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21574
22000
|
*
|
|
21575
|
-
* const program = Effect.fail(new
|
|
21576
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
22001
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
22002
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21577
22003
|
* )
|
|
21578
22004
|
*
|
|
21579
22005
|
* Effect.runPromiseExit(program).then(() =>
|
|
21580
22006
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21581
|
-
* // Output: { occurrences: Map(1) { "
|
|
22007
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21582
22008
|
* )
|
|
21583
22009
|
* ```
|
|
21584
22010
|
*
|
|
@@ -21617,18 +22043,20 @@ export const trackErrors: {
|
|
|
21617
22043
|
*
|
|
21618
22044
|
* @example
|
|
21619
22045
|
* ```ts
|
|
21620
|
-
* import { Effect, Metric } from "effect"
|
|
22046
|
+
* import { Data, Effect, Metric } from "effect"
|
|
22047
|
+
*
|
|
22048
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21621
22049
|
*
|
|
21622
22050
|
* // Track error types using frequency metric
|
|
21623
22051
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21624
22052
|
*
|
|
21625
|
-
* const program = Effect.fail(new
|
|
21626
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
22053
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
22054
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21627
22055
|
* )
|
|
21628
22056
|
*
|
|
21629
22057
|
* Effect.runPromiseExit(program).then(() =>
|
|
21630
22058
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21631
|
-
* // Output: { occurrences: Map(1) { "
|
|
22059
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21632
22060
|
* )
|
|
21633
22061
|
* ```
|
|
21634
22062
|
*
|
|
@@ -22151,8 +22579,8 @@ export const trackDuration: {
|
|
|
22151
22579
|
return onExit(self, () => {
|
|
22152
22580
|
const endTime = clock.currentTimeNanosUnsafe()
|
|
22153
22581
|
const duration = Duration.subtract(
|
|
22154
|
-
Duration.
|
|
22155
|
-
Duration.
|
|
22582
|
+
Duration.fromInputUnsafe(endTime),
|
|
22583
|
+
Duration.fromInputUnsafe(startTime)
|
|
22156
22584
|
)
|
|
22157
22585
|
const input = f === undefined ? duration : internalCall(() => f(duration))
|
|
22158
22586
|
return Metric.update(metric, input as any)
|
|
@@ -22200,136 +22628,70 @@ export class Transaction extends ServiceMap.Service<
|
|
|
22200
22628
|
>()("effect/Effect/Transaction") {}
|
|
22201
22629
|
|
|
22202
22630
|
/**
|
|
22203
|
-
*
|
|
22204
|
-
* transactional values (i.e. TxRef) that occur within the transaction body.
|
|
22205
|
-
*
|
|
22206
|
-
* In Effect transactions are optimistic with retry, that means transactions are retried when:
|
|
22631
|
+
* Accesses the current transaction state within an active transaction.
|
|
22207
22632
|
*
|
|
22208
|
-
*
|
|
22209
|
-
*
|
|
22210
|
-
*
|
|
22211
|
-
* - any of the accessed transactional values change during the execution of the transaction
|
|
22212
|
-
* due to a different transaction committing before the current.
|
|
22213
|
-
*
|
|
22214
|
-
* - parent transaction retry, if you have a transaction within another transaction and
|
|
22215
|
-
* the parent retries the child will also retry together with the parent.
|
|
22633
|
+
* This function requires `Transaction` in the context and does NOT create or strip
|
|
22634
|
+
* transaction boundaries. Use it to interact with the transaction journal (e.g. in
|
|
22635
|
+
* `TxRef` internals). To define a transaction boundary, use {@link transaction}.
|
|
22216
22636
|
*
|
|
22217
22637
|
* @example
|
|
22218
22638
|
* ```ts
|
|
22219
22639
|
* import { Effect, TxRef } from "effect"
|
|
22220
22640
|
*
|
|
22221
22641
|
* const program = Effect.gen(function*() {
|
|
22222
|
-
* const
|
|
22223
|
-
* const ref2 = yield* TxRef.make(0)
|
|
22224
|
-
*
|
|
22225
|
-
* // All operations within atomic block succeed or fail together
|
|
22226
|
-
* yield* Effect.atomic(Effect.gen(function*() {
|
|
22227
|
-
* yield* TxRef.set(ref1, 10)
|
|
22228
|
-
* yield* TxRef.set(ref2, 20)
|
|
22229
|
-
* const sum = (yield* TxRef.get(ref1)) + (yield* TxRef.get(ref2))
|
|
22230
|
-
* console.log(`Transaction sum: ${sum}`)
|
|
22231
|
-
* }))
|
|
22232
|
-
*
|
|
22233
|
-
* console.log(`Final ref1: ${yield* TxRef.get(ref1)}`) // 10
|
|
22234
|
-
* console.log(`Final ref2: ${yield* TxRef.get(ref2)}`) // 20
|
|
22235
|
-
* })
|
|
22236
|
-
* ```
|
|
22237
|
-
*
|
|
22238
|
-
* @since 4.0.0
|
|
22239
|
-
* @category Transactions
|
|
22240
|
-
*/
|
|
22241
|
-
export const atomic = <A, E, R>(
|
|
22242
|
-
effect: Effect<A, E, R>
|
|
22243
|
-
): Effect<A, E, Exclude<R, Transaction>> => atomicWith(() => effect)
|
|
22244
|
-
|
|
22245
|
-
/**
|
|
22246
|
-
* Executes a function within a transaction context, providing access to the transaction state.
|
|
22247
|
-
*
|
|
22248
|
-
* @example
|
|
22249
|
-
* ```ts
|
|
22250
|
-
* import { Effect, TxRef } from "effect"
|
|
22251
|
-
*
|
|
22252
|
-
* const program = Effect.atomicWith((txState) =>
|
|
22253
|
-
* Effect.gen(function*() {
|
|
22254
|
-
* const ref = yield* TxRef.make(0)
|
|
22255
|
-
*
|
|
22256
|
-
* // Access transaction state for debugging
|
|
22257
|
-
* console.log(`Journal size: ${txState.journal.size}`)
|
|
22258
|
-
* console.log(`Retry flag: ${txState.retry}`)
|
|
22642
|
+
* const ref = yield* Effect.transaction(TxRef.make(0))
|
|
22259
22643
|
*
|
|
22644
|
+
* yield* Effect.transaction(Effect.gen(function*() {
|
|
22260
22645
|
* yield* TxRef.set(ref, 42)
|
|
22261
22646
|
* return yield* TxRef.get(ref)
|
|
22262
|
-
* })
|
|
22263
|
-
* )
|
|
22264
|
-
*
|
|
22265
|
-
* Effect.runPromise(program).then(console.log) // 42
|
|
22647
|
+
* }))
|
|
22648
|
+
* })
|
|
22266
22649
|
* ```
|
|
22267
22650
|
*
|
|
22268
22651
|
* @since 4.0.0
|
|
22269
22652
|
* @category Transactions
|
|
22270
22653
|
*/
|
|
22271
|
-
export const
|
|
22654
|
+
export const withTxState = <A, E, R>(
|
|
22272
22655
|
f: (state: Transaction["Service"]) => Effect<A, E, R>
|
|
22273
|
-
): Effect<A, E,
|
|
22274
|
-
|
|
22275
|
-
|
|
22276
|
-
|
|
22277
|
-
|
|
22278
|
-
A,
|
|
22279
|
-
E,
|
|
22280
|
-
Exclude<R, Transaction>
|
|
22281
|
-
>
|
|
22282
|
-
}
|
|
22283
|
-
// No existing transaction, create isolated one using transactionWith
|
|
22284
|
-
return transactionWith(f)
|
|
22285
|
-
})
|
|
22656
|
+
): Effect<A, E, R | Transaction> =>
|
|
22657
|
+
flatMap(
|
|
22658
|
+
Transaction.asEffect(),
|
|
22659
|
+
(state) => internalCall(() => f(state))
|
|
22660
|
+
)
|
|
22286
22661
|
|
|
22287
22662
|
/**
|
|
22288
|
-
*
|
|
22663
|
+
* Defines a transaction boundary. Transactions are "all or nothing" with respect to changes
|
|
22664
|
+
* made to transactional values (i.e. TxRef) that occur within the transaction body.
|
|
22289
22665
|
*
|
|
22290
|
-
*
|
|
22666
|
+
* In Effect transactions are optimistic with retry, that means transactions are retried when:
|
|
22291
22667
|
*
|
|
22292
|
-
*
|
|
22293
|
-
*
|
|
22294
|
-
* This ensures complete isolation between different transaction scopes.
|
|
22668
|
+
* - the body of the transaction explicitely calls to `Effect.retryTransaction` and any of the
|
|
22669
|
+
* accessed transactional values changes.
|
|
22295
22670
|
*
|
|
22296
|
-
*
|
|
22297
|
-
*
|
|
22298
|
-
* - Parent transaction failures don't affect isolated transactions
|
|
22299
|
-
* - Isolated transaction failures don't affect parent transactions
|
|
22300
|
-
* - Each transaction has its own journal and retry logic
|
|
22671
|
+
* - any of the accessed transactional values change during the execution of the transaction
|
|
22672
|
+
* due to a different transaction committing before the current.
|
|
22301
22673
|
*
|
|
22302
|
-
*
|
|
22303
|
-
*
|
|
22304
|
-
* - For implementing independent operations that shouldn't be affected by outer transactions
|
|
22305
|
-
* - When building transaction-based systems where isolation is critical
|
|
22674
|
+
* Each call to `transaction` always creates a new isolated transaction boundary with its own
|
|
22675
|
+
* journal and retry logic.
|
|
22306
22676
|
*
|
|
22307
22677
|
* @example
|
|
22308
22678
|
* ```ts
|
|
22309
22679
|
* import { Effect, TxRef } from "effect"
|
|
22310
22680
|
*
|
|
22311
22681
|
* const program = Effect.gen(function*() {
|
|
22312
|
-
* const ref1 = yield* TxRef.make(0)
|
|
22313
|
-
* const ref2 = yield* TxRef.make(
|
|
22314
|
-
*
|
|
22315
|
-
* // Nested atomic transaction - ref1 will be part of outer transaction
|
|
22316
|
-
* yield* Effect.atomic(Effect.gen(function*() {
|
|
22317
|
-
* yield* TxRef.set(ref1, 10)
|
|
22682
|
+
* const ref1 = yield* Effect.transaction(TxRef.make(0))
|
|
22683
|
+
* const ref2 = yield* Effect.transaction(TxRef.make(0))
|
|
22318
22684
|
*
|
|
22319
|
-
*
|
|
22320
|
-
* yield* Effect.atomic(Effect.gen(function*() {
|
|
22321
|
-
* yield* TxRef.set(ref1, 20) // Part of same transaction
|
|
22322
|
-
* }))
|
|
22323
|
-
* }))
|
|
22324
|
-
*
|
|
22325
|
-
* // Isolated transaction - ref2 will be in its own transaction
|
|
22685
|
+
* // All operations within transaction block succeed or fail together
|
|
22326
22686
|
* yield* Effect.transaction(Effect.gen(function*() {
|
|
22327
|
-
* yield* TxRef.set(
|
|
22687
|
+
* yield* TxRef.set(ref1, 10)
|
|
22688
|
+
* yield* TxRef.set(ref2, 20)
|
|
22689
|
+
* const sum = (yield* TxRef.get(ref1)) + (yield* TxRef.get(ref2))
|
|
22690
|
+
* console.log(`Transaction sum: ${sum}`)
|
|
22328
22691
|
* }))
|
|
22329
22692
|
*
|
|
22330
|
-
*
|
|
22331
|
-
*
|
|
22332
|
-
* return { ref1: val1, ref2: val2 }
|
|
22693
|
+
* console.log(`Final ref1: ${yield* Effect.transaction(TxRef.get(ref1))}`) // 10
|
|
22694
|
+
* console.log(`Final ref2: ${yield* Effect.transaction(TxRef.get(ref2))}`) // 20
|
|
22333
22695
|
* })
|
|
22334
22696
|
* ```
|
|
22335
22697
|
*
|
|
@@ -22341,34 +22703,21 @@ export const transaction = <A, E, R>(
|
|
|
22341
22703
|
): Effect<A, E, Exclude<R, Transaction>> => transactionWith(() => effect)
|
|
22342
22704
|
|
|
22343
22705
|
/**
|
|
22344
|
-
*
|
|
22706
|
+
* Like {@link transaction} but provides access to the transaction state.
|
|
22345
22707
|
*
|
|
22346
|
-
*
|
|
22347
|
-
* within another transaction. This ensures complete isolation between transaction scopes.
|
|
22708
|
+
* Always creates a new isolated transaction boundary with its own journal and retry logic.
|
|
22348
22709
|
*
|
|
22349
22710
|
* @example
|
|
22350
22711
|
* ```ts
|
|
22351
22712
|
* import { Effect, TxRef } from "effect"
|
|
22352
22713
|
*
|
|
22353
|
-
* const program = Effect.transactionWith((
|
|
22714
|
+
* const program = Effect.transactionWith((_txState) =>
|
|
22354
22715
|
* Effect.gen(function*() {
|
|
22355
22716
|
* const ref = yield* TxRef.make(0)
|
|
22356
|
-
*
|
|
22357
|
-
* // This transaction is isolated - it has its own journal
|
|
22358
|
-
* // txState.journal is independent of any parent transaction
|
|
22359
|
-
*
|
|
22360
22717
|
* yield* TxRef.set(ref, 42)
|
|
22361
22718
|
* return yield* TxRef.get(ref)
|
|
22362
22719
|
* })
|
|
22363
22720
|
* )
|
|
22364
|
-
*
|
|
22365
|
-
* // Even when nested in another atomic block, this transaction is isolated
|
|
22366
|
-
* const nestedProgram = Effect.atomic(
|
|
22367
|
-
* Effect.gen(function*() {
|
|
22368
|
-
* const result = yield* program // Runs in its own isolated transaction
|
|
22369
|
-
* return result
|
|
22370
|
-
* })
|
|
22371
|
-
* )
|
|
22372
22721
|
* ```
|
|
22373
22722
|
*
|
|
22374
22723
|
* @since 4.0.0
|
|
@@ -22476,16 +22825,16 @@ function clearTransaction(state: Transaction["Service"]) {
|
|
|
22476
22825
|
*
|
|
22477
22826
|
* const program = Effect.gen(function*() {
|
|
22478
22827
|
* // create a transactional reference
|
|
22479
|
-
* const ref = yield* TxRef.make(0)
|
|
22828
|
+
* const ref = yield* Effect.transaction(TxRef.make(0))
|
|
22480
22829
|
*
|
|
22481
22830
|
* // forks a fiber that increases the value of `ref` every 100 millis
|
|
22482
22831
|
* yield* Effect.forkChild(Effect.forever(
|
|
22483
22832
|
* // update to transactional value
|
|
22484
|
-
* TxRef.update(ref, (n) => n + 1).pipe(Effect.delay("100 millis"))
|
|
22833
|
+
* Effect.transaction(TxRef.update(ref, (n) => n + 1)).pipe(Effect.delay("100 millis"))
|
|
22485
22834
|
* ))
|
|
22486
22835
|
*
|
|
22487
22836
|
* // the following will retry 10 times until the `ref` value is 10
|
|
22488
|
-
* yield* Effect.
|
|
22837
|
+
* yield* Effect.transaction(Effect.gen(function*() {
|
|
22489
22838
|
* const value = yield* TxRef.get(ref)
|
|
22490
22839
|
* if (value < 10) {
|
|
22491
22840
|
* yield* Effect.log(`retry due to value: ${value}`)
|
|
@@ -22997,18 +23346,20 @@ export const satisfiesSuccessType = <A>() => <A2 extends A, E, R>(effect: Effect
|
|
|
22997
23346
|
*
|
|
22998
23347
|
* @example
|
|
22999
23348
|
* ```ts
|
|
23000
|
-
* import { Effect } from "effect"
|
|
23349
|
+
* import { Data, Effect } from "effect"
|
|
23350
|
+
*
|
|
23351
|
+
* class ValidationError extends Data.TaggedError("ValidationError")<{}> {}
|
|
23001
23352
|
*
|
|
23002
|
-
* // Define a constraint that the error type must be
|
|
23003
|
-
* const satisfiesError = Effect.satisfiesErrorType<
|
|
23353
|
+
* // Define a constraint that the error type must be a ValidationError
|
|
23354
|
+
* const satisfiesError = Effect.satisfiesErrorType<ValidationError>()
|
|
23004
23355
|
*
|
|
23005
|
-
* // This works - Effect<number,
|
|
23006
|
-
* const validEffect = satisfiesError(Effect.fail(new
|
|
23356
|
+
* // This works - Effect<number, ValidationError, never> extends the constrained type
|
|
23357
|
+
* const validEffect = satisfiesError(Effect.fail(new ValidationError()))
|
|
23007
23358
|
*
|
|
23008
23359
|
* // This would cause a TypeScript compilation error:
|
|
23009
23360
|
* // const invalidEffect = satisfiesError(Effect.fail("string error"))
|
|
23010
23361
|
* // ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
23011
|
-
* // Type 'string' is not assignable to type '
|
|
23362
|
+
* // Type 'string' is not assignable to type 'ValidationError'
|
|
23012
23363
|
* ```
|
|
23013
23364
|
*
|
|
23014
23365
|
* @since 4.0.0
|