effect 3.10.18 → 3.11.0
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/cjs/Array.js +206 -0
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/BigDecimal.js +181 -24
- package/dist/cjs/BigDecimal.js.map +1 -1
- package/dist/cjs/BigInt.js +54 -0
- package/dist/cjs/BigInt.js.map +1 -1
- package/dist/cjs/Boolean.js +24 -0
- package/dist/cjs/Boolean.js.map +1 -1
- package/dist/cjs/Brand.js +4 -0
- package/dist/cjs/Brand.js.map +1 -1
- package/dist/cjs/Channel.js +44 -4
- package/dist/cjs/Channel.js.map +1 -1
- package/dist/cjs/Chunk.js +8 -0
- package/dist/cjs/Chunk.js.map +1 -1
- package/dist/cjs/Config.js +10 -1
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Context.js +50 -1
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Cron.js +81 -67
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/Data.js +14 -0
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/DateTime.js +178 -664
- package/dist/cjs/DateTime.js.map +1 -1
- package/dist/cjs/Duration.js +2 -0
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/Effect.js +296 -4
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Either.js +38 -2
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/FiberHandle.js +6 -0
- package/dist/cjs/FiberHandle.js.map +1 -1
- package/dist/cjs/FiberMap.js +6 -0
- package/dist/cjs/FiberMap.js.map +1 -1
- package/dist/cjs/FiberSet.js +6 -0
- package/dist/cjs/FiberSet.js.map +1 -1
- package/dist/cjs/Function.js +34 -0
- package/dist/cjs/Function.js.map +1 -1
- package/dist/cjs/GlobalValue.js +2 -0
- package/dist/cjs/GlobalValue.js.map +1 -1
- package/dist/cjs/HashMap.js.map +1 -1
- package/dist/cjs/Inspectable.js +8 -4
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/Iterable.js +18 -0
- package/dist/cjs/Iterable.js.map +1 -1
- package/dist/cjs/JSONSchema.js.map +1 -1
- package/dist/cjs/List.js +4 -0
- package/dist/cjs/List.js.map +1 -1
- package/dist/cjs/Logger.js +26 -0
- package/dist/cjs/Logger.js.map +1 -1
- package/dist/cjs/Mailbox.js +2 -0
- package/dist/cjs/Mailbox.js.map +1 -1
- package/dist/cjs/ManagedRuntime.js +2 -0
- package/dist/cjs/ManagedRuntime.js.map +1 -1
- package/dist/cjs/Metric.js +10 -0
- package/dist/cjs/Metric.js.map +1 -1
- package/dist/cjs/Micro.js +1104 -1069
- package/dist/cjs/Micro.js.map +1 -1
- package/dist/cjs/Number.js +44 -0
- package/dist/cjs/Number.js.map +1 -1
- package/dist/cjs/Option.js +70 -0
- package/dist/cjs/Option.js.map +1 -1
- package/dist/cjs/Order.js +2 -0
- package/dist/cjs/Order.js.map +1 -1
- package/dist/cjs/Ordering.js +4 -0
- package/dist/cjs/Ordering.js.map +1 -1
- package/dist/cjs/Predicate.js +68 -0
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/Random.js +4 -0
- package/dist/cjs/Random.js.map +1 -1
- package/dist/cjs/RateLimiter.js +4 -0
- package/dist/cjs/RateLimiter.js.map +1 -1
- package/dist/cjs/RcMap.js +2 -0
- package/dist/cjs/RcMap.js.map +1 -1
- package/dist/cjs/RcRef.js +2 -0
- package/dist/cjs/RcRef.js.map +1 -1
- package/dist/cjs/Record.js +56 -0
- package/dist/cjs/Record.js.map +1 -1
- package/dist/cjs/Redacted.js +8 -0
- package/dist/cjs/Redacted.js.map +1 -1
- package/dist/cjs/RegExp.js +4 -0
- package/dist/cjs/RegExp.js.map +1 -1
- package/dist/cjs/Request.js +4 -0
- package/dist/cjs/Request.js.map +1 -1
- package/dist/cjs/RequestResolver.js +2 -0
- package/dist/cjs/RequestResolver.js.map +1 -1
- package/dist/cjs/Runtime.js +6 -0
- package/dist/cjs/Runtime.js.map +1 -1
- package/dist/cjs/STM.js.map +1 -1
- package/dist/cjs/Schema.js +91 -8
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/Sink.js +9 -1
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/Stream.js +179 -7
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/String.js +62 -0
- package/dist/cjs/String.js.map +1 -1
- package/dist/cjs/Struct.js +12 -0
- package/dist/cjs/Struct.js.map +1 -1
- package/dist/cjs/Symbol.js +2 -0
- package/dist/cjs/Symbol.js.map +1 -1
- package/dist/cjs/Trie.js +56 -0
- package/dist/cjs/Trie.js.map +1 -1
- package/dist/cjs/Tuple.js +18 -0
- package/dist/cjs/Tuple.js.map +1 -1
- package/dist/cjs/Utils.js +7 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/internal/channel/channelExecutor.js +5 -9
- package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
- package/dist/cjs/internal/channel.js +156 -130
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/config.js +13 -4
- package/dist/cjs/internal/config.js.map +1 -1
- package/dist/cjs/internal/context.js +46 -3
- package/dist/cjs/internal/context.js.map +1 -1
- package/dist/cjs/internal/dateTime.js +747 -0
- package/dist/cjs/internal/dateTime.js.map +1 -0
- package/dist/cjs/internal/fiberRuntime.js +34 -11
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/groupBy.js +9 -3
- package/dist/cjs/internal/groupBy.js.map +1 -1
- package/dist/cjs/internal/layer.js +1 -1
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/mailbox.js +1 -1
- package/dist/cjs/internal/mailbox.js.map +1 -1
- package/dist/cjs/internal/sink.js +25 -21
- package/dist/cjs/internal/sink.js.map +1 -1
- package/dist/cjs/internal/stream.js +70 -71
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/Array.d.ts +534 -0
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/BigDecimal.d.ts +172 -1
- package/dist/dts/BigDecimal.d.ts.map +1 -1
- package/dist/dts/BigInt.d.ts +114 -0
- package/dist/dts/BigInt.d.ts.map +1 -1
- package/dist/dts/Boolean.d.ts +56 -0
- package/dist/dts/Boolean.d.ts.map +1 -1
- package/dist/dts/Brand.d.ts +6 -0
- package/dist/dts/Brand.d.ts.map +1 -1
- package/dist/dts/Channel.d.ts +66 -5
- package/dist/dts/Channel.d.ts.map +1 -1
- package/dist/dts/Chunk.d.ts +30 -0
- package/dist/dts/Chunk.d.ts.map +1 -1
- package/dist/dts/Config.d.ts +25 -1
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +155 -0
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Cron.d.ts +21 -6
- package/dist/dts/Cron.d.ts.map +1 -1
- package/dist/dts/Data.d.ts +26 -0
- package/dist/dts/Data.d.ts.map +1 -1
- package/dist/dts/DateTime.d.ts +192 -49
- package/dist/dts/DateTime.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts +2 -0
- package/dist/dts/Duration.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +658 -1
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Either.d.ts +84 -2
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/FiberHandle.d.ts +6 -0
- package/dist/dts/FiberHandle.d.ts.map +1 -1
- package/dist/dts/FiberMap.d.ts +6 -0
- package/dist/dts/FiberMap.d.ts.map +1 -1
- package/dist/dts/FiberSet.d.ts +6 -0
- package/dist/dts/FiberSet.d.ts.map +1 -1
- package/dist/dts/Function.d.ts +50 -0
- package/dist/dts/Function.d.ts.map +1 -1
- package/dist/dts/GlobalValue.d.ts +2 -0
- package/dist/dts/GlobalValue.d.ts.map +1 -1
- package/dist/dts/HashMap.d.ts +6 -0
- package/dist/dts/HashMap.d.ts.map +1 -1
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/Iterable.d.ts +26 -0
- package/dist/dts/Iterable.d.ts.map +1 -1
- package/dist/dts/JSONSchema.d.ts +1 -0
- package/dist/dts/JSONSchema.d.ts.map +1 -1
- package/dist/dts/List.d.ts +20 -0
- package/dist/dts/List.d.ts.map +1 -1
- package/dist/dts/Logger.d.ts +34 -0
- package/dist/dts/Logger.d.ts.map +1 -1
- package/dist/dts/Mailbox.d.ts +2 -0
- package/dist/dts/Mailbox.d.ts.map +1 -1
- package/dist/dts/ManagedRuntime.d.ts +2 -0
- package/dist/dts/ManagedRuntime.d.ts.map +1 -1
- package/dist/dts/Metric.d.ts +18 -0
- package/dist/dts/Metric.d.ts.map +1 -1
- package/dist/dts/Micro.d.ts +880 -863
- package/dist/dts/Micro.d.ts.map +1 -1
- package/dist/dts/Number.d.ts +104 -0
- package/dist/dts/Number.d.ts.map +1 -1
- package/dist/dts/Option.d.ts +142 -0
- package/dist/dts/Option.d.ts.map +1 -1
- package/dist/dts/Order.d.ts +2 -0
- package/dist/dts/Order.d.ts.map +1 -1
- package/dist/dts/Ordering.d.ts +8 -0
- package/dist/dts/Ordering.d.ts.map +1 -1
- package/dist/dts/Predicate.d.ts +104 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/Random.d.ts +4 -0
- package/dist/dts/Random.d.ts.map +1 -1
- package/dist/dts/RateLimiter.d.ts +4 -0
- package/dist/dts/RateLimiter.d.ts.map +1 -1
- package/dist/dts/RcMap.d.ts +6 -0
- package/dist/dts/RcMap.d.ts.map +1 -1
- package/dist/dts/RcRef.d.ts +2 -0
- package/dist/dts/RcRef.d.ts.map +1 -1
- package/dist/dts/Record.d.ts +136 -0
- package/dist/dts/Record.d.ts.map +1 -1
- package/dist/dts/Redacted.d.ts +8 -0
- package/dist/dts/Redacted.d.ts.map +1 -1
- package/dist/dts/RegExp.d.ts +4 -0
- package/dist/dts/RegExp.d.ts.map +1 -1
- package/dist/dts/Request.d.ts +4 -0
- package/dist/dts/Request.d.ts.map +1 -1
- package/dist/dts/RequestResolver.d.ts +6 -0
- package/dist/dts/RequestResolver.d.ts.map +1 -1
- package/dist/dts/Runtime.d.ts +18 -0
- package/dist/dts/Runtime.d.ts.map +1 -1
- package/dist/dts/STM.d.ts +2 -0
- package/dist/dts/STM.d.ts.map +1 -1
- package/dist/dts/Schema.d.ts +90 -0
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +8 -0
- package/dist/dts/Sink.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +394 -32
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/String.d.ts +94 -0
- package/dist/dts/String.d.ts.map +1 -1
- package/dist/dts/Struct.d.ts +24 -0
- package/dist/dts/Struct.d.ts.map +1 -1
- package/dist/dts/Symbol.d.ts +2 -0
- package/dist/dts/Symbol.d.ts.map +1 -1
- package/dist/dts/Trie.d.ts +132 -0
- package/dist/dts/Trie.d.ts.map +1 -1
- package/dist/dts/Tuple.d.ts +42 -0
- package/dist/dts/Tuple.d.ts.map +1 -1
- package/dist/dts/Types.d.ts +24 -0
- package/dist/dts/Types.d.ts.map +1 -1
- package/dist/dts/Utils.d.ts +4 -0
- package/dist/dts/Utils.d.ts.map +1 -1
- package/dist/dts/internal/context.d.ts +1 -1
- package/dist/dts/internal/context.d.ts.map +1 -1
- package/dist/dts/internal/dateTime.d.ts +2 -0
- package/dist/dts/internal/dateTime.d.ts.map +1 -0
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Array.js +208 -0
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/BigDecimal.js +175 -20
- package/dist/esm/BigDecimal.js.map +1 -1
- package/dist/esm/BigInt.js +54 -0
- package/dist/esm/BigInt.js.map +1 -1
- package/dist/esm/Boolean.js +24 -0
- package/dist/esm/Boolean.js.map +1 -1
- package/dist/esm/Brand.js +4 -0
- package/dist/esm/Brand.js.map +1 -1
- package/dist/esm/Channel.js +42 -2
- package/dist/esm/Channel.js.map +1 -1
- package/dist/esm/Chunk.js +8 -0
- package/dist/esm/Chunk.js.map +1 -1
- package/dist/esm/Config.js +9 -0
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Context.js +49 -0
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Cron.js +81 -67
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/Data.js +16 -0
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/DateTime.js +176 -627
- package/dist/esm/DateTime.js.map +1 -1
- package/dist/esm/Duration.js +2 -0
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/Effect.js +297 -0
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Either.js +40 -2
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/FiberHandle.js +6 -0
- package/dist/esm/FiberHandle.js.map +1 -1
- package/dist/esm/FiberMap.js +6 -0
- package/dist/esm/FiberMap.js.map +1 -1
- package/dist/esm/FiberSet.js +6 -0
- package/dist/esm/FiberSet.js.map +1 -1
- package/dist/esm/Function.js +34 -0
- package/dist/esm/Function.js.map +1 -1
- package/dist/esm/GlobalValue.js +2 -0
- package/dist/esm/GlobalValue.js.map +1 -1
- package/dist/esm/HashMap.js.map +1 -1
- package/dist/esm/Inspectable.js +8 -4
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/Iterable.js +18 -0
- package/dist/esm/Iterable.js.map +1 -1
- package/dist/esm/JSONSchema.js.map +1 -1
- package/dist/esm/List.js +4 -0
- package/dist/esm/List.js.map +1 -1
- package/dist/esm/Logger.js +26 -0
- package/dist/esm/Logger.js.map +1 -1
- package/dist/esm/Mailbox.js +2 -0
- package/dist/esm/Mailbox.js.map +1 -1
- package/dist/esm/ManagedRuntime.js +2 -0
- package/dist/esm/ManagedRuntime.js.map +1 -1
- package/dist/esm/Metric.js +10 -0
- package/dist/esm/Metric.js.map +1 -1
- package/dist/esm/Micro.js +1077 -1037
- package/dist/esm/Micro.js.map +1 -1
- package/dist/esm/Number.js +44 -0
- package/dist/esm/Number.js.map +1 -1
- package/dist/esm/Option.js +72 -0
- package/dist/esm/Option.js.map +1 -1
- package/dist/esm/Order.js +2 -0
- package/dist/esm/Order.js.map +1 -1
- package/dist/esm/Ordering.js +4 -0
- package/dist/esm/Ordering.js.map +1 -1
- package/dist/esm/Predicate.js +68 -0
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/Random.js +4 -0
- package/dist/esm/Random.js.map +1 -1
- package/dist/esm/RateLimiter.js +4 -0
- package/dist/esm/RateLimiter.js.map +1 -1
- package/dist/esm/RcMap.js +2 -0
- package/dist/esm/RcMap.js.map +1 -1
- package/dist/esm/RcRef.js +2 -0
- package/dist/esm/RcRef.js.map +1 -1
- package/dist/esm/Record.js +56 -0
- package/dist/esm/Record.js.map +1 -1
- package/dist/esm/Redacted.js +8 -0
- package/dist/esm/Redacted.js.map +1 -1
- package/dist/esm/RegExp.js +4 -0
- package/dist/esm/RegExp.js.map +1 -1
- package/dist/esm/Request.js +4 -0
- package/dist/esm/Request.js.map +1 -1
- package/dist/esm/RequestResolver.js +2 -0
- package/dist/esm/RequestResolver.js.map +1 -1
- package/dist/esm/Runtime.js +6 -0
- package/dist/esm/Runtime.js.map +1 -1
- package/dist/esm/STM.js.map +1 -1
- package/dist/esm/Schema.js +88 -0
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/Sink.js +8 -0
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/Stream.js +183 -5
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/String.js +62 -0
- package/dist/esm/String.js.map +1 -1
- package/dist/esm/Struct.js +12 -0
- package/dist/esm/Struct.js.map +1 -1
- package/dist/esm/Symbol.js +2 -0
- package/dist/esm/Symbol.js.map +1 -1
- package/dist/esm/Trie.js +56 -0
- package/dist/esm/Trie.js.map +1 -1
- package/dist/esm/Tuple.js +22 -0
- package/dist/esm/Tuple.js.map +1 -1
- package/dist/esm/Utils.js +5 -0
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/internal/channel/channelExecutor.js +5 -7
- package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
- package/dist/esm/internal/channel.js +152 -129
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/config.js +11 -3
- package/dist/esm/internal/config.js.map +1 -1
- package/dist/esm/internal/context.js +42 -2
- package/dist/esm/internal/context.js.map +1 -1
- package/dist/esm/internal/dateTime.js +704 -0
- package/dist/esm/internal/dateTime.js.map +1 -0
- package/dist/esm/internal/fiberRuntime.js +31 -9
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/groupBy.js +9 -3
- package/dist/esm/internal/groupBy.js.map +1 -1
- package/dist/esm/internal/layer.js +1 -1
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/mailbox.js +1 -1
- package/dist/esm/internal/mailbox.js.map +1 -1
- package/dist/esm/internal/sink.js +23 -20
- package/dist/esm/internal/sink.js.map +1 -1
- package/dist/esm/internal/stream.js +66 -69
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +534 -0
- package/src/BigDecimal.ts +247 -21
- package/src/BigInt.ts +114 -0
- package/src/Boolean.ts +56 -0
- package/src/Brand.ts +6 -0
- package/src/Channel.ts +81 -5
- package/src/Chunk.ts +32 -0
- package/src/Config.ts +26 -1
- package/src/Context.ts +163 -0
- package/src/Cron.ts +91 -68
- package/src/Data.ts +26 -0
- package/src/DateTime.ts +307 -757
- package/src/Duration.ts +2 -0
- package/src/Effect.ts +910 -1
- package/src/Either.ts +84 -2
- package/src/FiberHandle.ts +6 -0
- package/src/FiberMap.ts +6 -0
- package/src/FiberSet.ts +6 -0
- package/src/Function.ts +50 -0
- package/src/GlobalValue.ts +2 -0
- package/src/HashMap.ts +6 -0
- package/src/Inspectable.ts +11 -7
- package/src/Iterable.ts +26 -0
- package/src/JSONSchema.ts +1 -0
- package/src/List.ts +24 -0
- package/src/Logger.ts +34 -0
- package/src/Mailbox.ts +2 -0
- package/src/ManagedRuntime.ts +2 -0
- package/src/Metric.ts +18 -0
- package/src/Micro.ts +2007 -1745
- package/src/Number.ts +104 -0
- package/src/Option.ts +142 -0
- package/src/Order.ts +2 -0
- package/src/Ordering.ts +8 -0
- package/src/Predicate.ts +104 -0
- package/src/Random.ts +4 -0
- package/src/RateLimiter.ts +4 -0
- package/src/RcMap.ts +6 -0
- package/src/RcRef.ts +2 -0
- package/src/Record.ts +136 -0
- package/src/Redacted.ts +8 -0
- package/src/RegExp.ts +4 -0
- package/src/Request.ts +4 -0
- package/src/RequestResolver.ts +6 -0
- package/src/Runtime.ts +18 -0
- package/src/STM.ts +2 -0
- package/src/Schema.ts +124 -0
- package/src/Sink.ts +11 -0
- package/src/Stream.ts +399 -44
- package/src/String.ts +94 -0
- package/src/Struct.ts +24 -0
- package/src/Symbol.ts +2 -0
- package/src/Trie.ts +132 -0
- package/src/Tuple.ts +42 -0
- package/src/Types.ts +24 -0
- package/src/Utils.ts +8 -0
- package/src/internal/channel/channelExecutor.ts +37 -33
- package/src/internal/channel.ts +504 -467
- package/src/internal/config.ts +18 -6
- package/src/internal/context.ts +56 -4
- package/src/internal/dateTime.ts +1126 -0
- package/src/internal/fiberRuntime.ts +35 -16
- package/src/internal/groupBy.ts +13 -22
- package/src/internal/layer.ts +5 -8
- package/src/internal/mailbox.ts +6 -4
- package/src/internal/sink.ts +55 -35
- package/src/internal/stream.ts +299 -299
- package/src/internal/version.ts +1 -1
package/dist/esm/Effect.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { dual } from "./Function.js";
|
|
2
|
+
import * as internalCause from "./internal/cause.js";
|
|
2
3
|
import * as _console from "./internal/console.js";
|
|
3
4
|
import { TagProto } from "./internal/context.js";
|
|
4
5
|
import * as effect from "./internal/core-effect.js";
|
|
@@ -12,6 +13,7 @@ import * as _runtime from "./internal/runtime.js";
|
|
|
12
13
|
import * as _schedule from "./internal/schedule.js";
|
|
13
14
|
import * as Request from "./Request.js";
|
|
14
15
|
import * as Scheduler from "./Scheduler.js";
|
|
16
|
+
import { internalCall, isGeneratorFunction } from "./Utils.js";
|
|
15
17
|
/**
|
|
16
18
|
* @since 2.0.0
|
|
17
19
|
* @category Symbols
|
|
@@ -36,6 +38,7 @@ export const isEffect = core.isEffect;
|
|
|
36
38
|
* be recomputed upon next evaluation.
|
|
37
39
|
*
|
|
38
40
|
* @example
|
|
41
|
+
* ```ts
|
|
39
42
|
* import { Effect, Console } from "effect"
|
|
40
43
|
*
|
|
41
44
|
* let i = 1
|
|
@@ -63,6 +66,7 @@ export const isEffect = core.isEffect;
|
|
|
63
66
|
* // result 1
|
|
64
67
|
* // expensive task...
|
|
65
68
|
* // result 2
|
|
69
|
+
* ```
|
|
66
70
|
*
|
|
67
71
|
* @since 2.0.0
|
|
68
72
|
* @category Caching
|
|
@@ -74,6 +78,7 @@ export const cachedWithTTL = circular.cached;
|
|
|
74
78
|
* invalidating the cached value before it naturally expires.
|
|
75
79
|
*
|
|
76
80
|
* @example
|
|
81
|
+
* ```ts
|
|
77
82
|
* import { Effect, Console } from "effect"
|
|
78
83
|
*
|
|
79
84
|
* let i = 1
|
|
@@ -104,6 +109,7 @@ export const cachedWithTTL = circular.cached;
|
|
|
104
109
|
* // result 1
|
|
105
110
|
* // expensive task...
|
|
106
111
|
* // result 2
|
|
112
|
+
* ```
|
|
107
113
|
*
|
|
108
114
|
* @since 2.0.0
|
|
109
115
|
* @category Caching
|
|
@@ -115,6 +121,7 @@ export const cachedInvalidateWithTTL = circular.cachedInvalidateWithTTL;
|
|
|
115
121
|
* the logic.
|
|
116
122
|
*
|
|
117
123
|
* @example
|
|
124
|
+
* ```ts
|
|
118
125
|
* import { Effect, Console } from "effect"
|
|
119
126
|
*
|
|
120
127
|
* let i = 1
|
|
@@ -148,6 +155,7 @@ export const cachedInvalidateWithTTL = circular.cachedInvalidateWithTTL;
|
|
|
148
155
|
* // expensive task...
|
|
149
156
|
* // result 3
|
|
150
157
|
* // result 3
|
|
158
|
+
* ```
|
|
151
159
|
*
|
|
152
160
|
* @since 2.0.0
|
|
153
161
|
* @category Caching
|
|
@@ -159,6 +167,7 @@ export const cached = effect.memoize;
|
|
|
159
167
|
* recompute them.
|
|
160
168
|
*
|
|
161
169
|
* @example
|
|
170
|
+
* ```ts
|
|
162
171
|
* import { Effect, Random } from "effect"
|
|
163
172
|
*
|
|
164
173
|
* const program = Effect.gen(function* () {
|
|
@@ -181,6 +190,7 @@ export const cached = effect.memoize;
|
|
|
181
190
|
* // memoized version:
|
|
182
191
|
* // 5
|
|
183
192
|
* // 5
|
|
193
|
+
* ```
|
|
184
194
|
*
|
|
185
195
|
* @since 2.0.0
|
|
186
196
|
* @category Caching
|
|
@@ -191,6 +201,7 @@ export const cachedFunction = circular.cachedFunction;
|
|
|
191
201
|
* called.
|
|
192
202
|
*
|
|
193
203
|
* @example
|
|
204
|
+
* ```ts
|
|
194
205
|
* import { Effect, Console } from "effect"
|
|
195
206
|
*
|
|
196
207
|
* const program = Effect.gen(function* () {
|
|
@@ -206,6 +217,7 @@ export const cachedFunction = circular.cachedFunction;
|
|
|
206
217
|
* // task1
|
|
207
218
|
* // task1
|
|
208
219
|
* // task2
|
|
220
|
+
* ```
|
|
209
221
|
*
|
|
210
222
|
* @since 2.0.0
|
|
211
223
|
* @category Caching
|
|
@@ -261,6 +273,7 @@ export const once = effect.once;
|
|
|
261
273
|
* @see {@link forEach} for iterating over elements and applying an effect.
|
|
262
274
|
*
|
|
263
275
|
* @example
|
|
276
|
+
* ```ts
|
|
264
277
|
* // Title: Combining Effects in Tuples
|
|
265
278
|
* import { Effect, Console } from "effect"
|
|
266
279
|
*
|
|
@@ -278,6 +291,7 @@ export const once = effect.once;
|
|
|
278
291
|
* // 42
|
|
279
292
|
* // Hello
|
|
280
293
|
* // [ 42, 'Hello' ]
|
|
294
|
+
* ```
|
|
281
295
|
*
|
|
282
296
|
* @example
|
|
283
297
|
* // Title: Combining Effects in Iterables
|
|
@@ -426,6 +440,7 @@ export const all = fiberRuntime.all;
|
|
|
426
440
|
* your data and then apply operations to it.
|
|
427
441
|
*
|
|
428
442
|
* @example
|
|
443
|
+
* ```ts
|
|
429
444
|
* import { Effect, pipe } from "effect"
|
|
430
445
|
*
|
|
431
446
|
* const task1 = Effect.succeed(1).pipe(
|
|
@@ -449,6 +464,7 @@ export const all = fiberRuntime.all;
|
|
|
449
464
|
* // timestamp=... level=INFO fiber=#3 message="task2 done"
|
|
450
465
|
* // timestamp=... level=INFO fiber=#2 message="task1 done"
|
|
451
466
|
* // [ 1, 'hello' ]
|
|
467
|
+
* ```
|
|
452
468
|
*
|
|
453
469
|
* @since 2.0.0
|
|
454
470
|
* @category Collecting
|
|
@@ -510,6 +526,7 @@ export const filter = fiberRuntime.filter;
|
|
|
510
526
|
* @see {@link filter} for concurrent filtering without mapping.
|
|
511
527
|
*
|
|
512
528
|
* @example
|
|
529
|
+
* ```ts
|
|
513
530
|
* import { Console, Effect, Option } from "effect"
|
|
514
531
|
*
|
|
515
532
|
* const task = (n: number) =>
|
|
@@ -530,6 +547,7 @@ export const filter = fiberRuntime.filter;
|
|
|
530
547
|
* // task3 done
|
|
531
548
|
* // task4 done
|
|
532
549
|
* // [ 2, 4 ]
|
|
550
|
+
* ```
|
|
533
551
|
*
|
|
534
552
|
* @since 2.0.0
|
|
535
553
|
* @category Filtering
|
|
@@ -566,6 +584,7 @@ export const findFirst = effect.findFirst;
|
|
|
566
584
|
* @see {@link all} for combining multiple effects into one.
|
|
567
585
|
*
|
|
568
586
|
* @example
|
|
587
|
+
* ```ts
|
|
569
588
|
* // Title: Applying Effects to Iterable Elements
|
|
570
589
|
* import { Effect, Console } from "effect"
|
|
571
590
|
*
|
|
@@ -581,6 +600,7 @@ export const findFirst = effect.findFirst;
|
|
|
581
600
|
* // Currently at index 3
|
|
582
601
|
* // Currently at index 4
|
|
583
602
|
* // [ 2, 4, 6, 8, 10 ]
|
|
603
|
+
* ```
|
|
584
604
|
*
|
|
585
605
|
* @example
|
|
586
606
|
* // Title: Using discard to Ignore Results
|
|
@@ -639,6 +659,7 @@ export const mergeAll = fiberRuntime.mergeAll;
|
|
|
639
659
|
* @see {@link validateFirst} for a function that stops at the first success.
|
|
640
660
|
*
|
|
641
661
|
* @example
|
|
662
|
+
* ```ts
|
|
642
663
|
* import { Effect } from "effect"
|
|
643
664
|
*
|
|
644
665
|
* // ┌─── Effect<[string[], number[]], never, never>
|
|
@@ -654,6 +675,7 @@ export const mergeAll = fiberRuntime.mergeAll;
|
|
|
654
675
|
* Effect.runPromise(program).then(console.log, console.error)
|
|
655
676
|
* // Output:
|
|
656
677
|
* // [ [ '1 is not even', '3 is not even' ], [ 0, 2, 4 ] ]
|
|
678
|
+
* ```
|
|
657
679
|
*
|
|
658
680
|
* @since 2.0.0
|
|
659
681
|
* @category Error Accumulation
|
|
@@ -734,6 +756,7 @@ export const takeWhile = effect.takeWhile;
|
|
|
734
756
|
* @see {@link partition} when you need to separate successes and failures instead of losing successes with errors.
|
|
735
757
|
*
|
|
736
758
|
* @example
|
|
759
|
+
* ```ts
|
|
737
760
|
* import { Effect, Console } from "effect"
|
|
738
761
|
*
|
|
739
762
|
* // ┌─── Effect<number[], string[], never>
|
|
@@ -760,6 +783,7 @@ export const takeWhile = effect.takeWhile;
|
|
|
760
783
|
* // failure: [ '4 is not less that 4', '5 is not less that 4' ]
|
|
761
784
|
* // }
|
|
762
785
|
* // }
|
|
786
|
+
* ```
|
|
763
787
|
*
|
|
764
788
|
* @since 2.0.0
|
|
765
789
|
* @category Error Accumulation
|
|
@@ -781,6 +805,7 @@ export const validateAll = fiberRuntime.validateAll;
|
|
|
781
805
|
* @see {@link firstSuccessOf} for a similar function that processes multiple effects and returns the first successful one or the last error.
|
|
782
806
|
*
|
|
783
807
|
* @example
|
|
808
|
+
* ```ts
|
|
784
809
|
* import { Effect, Console } from "effect"
|
|
785
810
|
*
|
|
786
811
|
* // ┌─── Effect<number, string[], never>
|
|
@@ -797,6 +822,7 @@ export const validateAll = fiberRuntime.validateAll;
|
|
|
797
822
|
* // Output:
|
|
798
823
|
* // item 4
|
|
799
824
|
* // 4
|
|
825
|
+
* ```
|
|
800
826
|
*
|
|
801
827
|
* @since 2.0.0
|
|
802
828
|
* @category Error Accumulation
|
|
@@ -827,6 +853,7 @@ export const validateFirst = fiberRuntime.validateFirst;
|
|
|
827
853
|
* behavior of the returned effect.
|
|
828
854
|
*
|
|
829
855
|
* @example
|
|
856
|
+
* ```ts
|
|
830
857
|
* // Title: Wrapping a Callback API
|
|
831
858
|
* import { Effect } from "effect"
|
|
832
859
|
* import * as NodeFS from "node:fs"
|
|
@@ -847,6 +874,7 @@ export const validateFirst = fiberRuntime.validateFirst;
|
|
|
847
874
|
* // ┌─── Effect<Buffer, Error, never>
|
|
848
875
|
* // ▼
|
|
849
876
|
* const program = readFile("example.txt")
|
|
877
|
+
* ```
|
|
850
878
|
*
|
|
851
879
|
* @example
|
|
852
880
|
* // Title: Handling Interruption with Cleanup
|
|
@@ -937,12 +965,14 @@ export const asyncEffect = _runtime.asyncEffect;
|
|
|
937
965
|
* the "this" of the effect.
|
|
938
966
|
*
|
|
939
967
|
* @example
|
|
968
|
+
* ```ts
|
|
940
969
|
* import { Effect } from "effect"
|
|
941
970
|
*
|
|
942
971
|
* const throwingFunction = () => { throw new Error() }
|
|
943
972
|
* const blowUp = Effect.custom(throwingFunction, function() {
|
|
944
973
|
* return Effect.succeed(this.effect_instruction_i0())
|
|
945
974
|
* })
|
|
975
|
+
* ```
|
|
946
976
|
*
|
|
947
977
|
* @since 2.0.0
|
|
948
978
|
* @category Creating Effects
|
|
@@ -965,6 +995,7 @@ export const withFiberRuntime = core.withFiberRuntime;
|
|
|
965
995
|
* @see {@link succeed} to create an effect that represents a successful value.
|
|
966
996
|
*
|
|
967
997
|
* @example
|
|
998
|
+
* ```ts
|
|
968
999
|
* // Title: Creating a Failed Effect
|
|
969
1000
|
* import { Effect } from "effect"
|
|
970
1001
|
*
|
|
@@ -973,6 +1004,7 @@ export const withFiberRuntime = core.withFiberRuntime;
|
|
|
973
1004
|
* const failure = Effect.fail(
|
|
974
1005
|
* new Error("Operation failed due to network error")
|
|
975
1006
|
* )
|
|
1007
|
+
* ```
|
|
976
1008
|
*
|
|
977
1009
|
* @since 2.0.0
|
|
978
1010
|
* @category Creating Effects
|
|
@@ -1014,6 +1046,7 @@ export const failCauseSync = core.failCauseSync;
|
|
|
1014
1046
|
* @see {@link dieMessage} for a variant that throws a `RuntimeException` with a message.
|
|
1015
1047
|
*
|
|
1016
1048
|
* @example
|
|
1049
|
+
* ```ts
|
|
1017
1050
|
* // Title: Terminating on Division by Zero with a Specified Error
|
|
1018
1051
|
* import { Effect } from "effect"
|
|
1019
1052
|
*
|
|
@@ -1030,6 +1063,7 @@ export const failCauseSync = core.failCauseSync;
|
|
|
1030
1063
|
* // Output:
|
|
1031
1064
|
* // (FiberFailure) Error: Cannot divide by zero
|
|
1032
1065
|
* // ...stack trace...
|
|
1066
|
+
* ```
|
|
1033
1067
|
*
|
|
1034
1068
|
* @since 2.0.0
|
|
1035
1069
|
* @category Creating Effects
|
|
@@ -1058,6 +1092,7 @@ export const die = core.die;
|
|
|
1058
1092
|
* lazily.
|
|
1059
1093
|
*
|
|
1060
1094
|
* @example
|
|
1095
|
+
* ```ts
|
|
1061
1096
|
* // Title: Terminating on Division by Zero with a Specified Message
|
|
1062
1097
|
* import { Effect } from "effect"
|
|
1063
1098
|
*
|
|
@@ -1074,6 +1109,7 @@ export const die = core.die;
|
|
|
1074
1109
|
* // Output:
|
|
1075
1110
|
* // (FiberFailure) RuntimeException: Cannot divide by zero
|
|
1076
1111
|
* // ...stack trace...
|
|
1112
|
+
* ```
|
|
1077
1113
|
*
|
|
1078
1114
|
* @since 2.0.0
|
|
1079
1115
|
* @category Creating Effects
|
|
@@ -1107,6 +1143,7 @@ export const dieSync = core.dieSync;
|
|
|
1107
1143
|
* effects and return the final result at the end.
|
|
1108
1144
|
*
|
|
1109
1145
|
* @example
|
|
1146
|
+
* ```ts
|
|
1110
1147
|
* import { Effect } from "effect"
|
|
1111
1148
|
*
|
|
1112
1149
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
@@ -1133,6 +1170,7 @@ export const dieSync = core.dieSync;
|
|
|
1133
1170
|
* const finalAmount = addServiceCharge(discountedAmount)
|
|
1134
1171
|
* return `Final amount to charge: ${finalAmount}`
|
|
1135
1172
|
* })
|
|
1173
|
+
* ```
|
|
1136
1174
|
*
|
|
1137
1175
|
* @since 2.0.0
|
|
1138
1176
|
* @category Creating Effects
|
|
@@ -1179,6 +1217,7 @@ export const none = effect.none;
|
|
|
1179
1217
|
* @see {@link tryPromise} for a version that can handle failures.
|
|
1180
1218
|
*
|
|
1181
1219
|
* @example
|
|
1220
|
+
* ```ts
|
|
1182
1221
|
* // Title: Delayed Message
|
|
1183
1222
|
* import { Effect } from "effect"
|
|
1184
1223
|
*
|
|
@@ -1195,6 +1234,7 @@ export const none = effect.none;
|
|
|
1195
1234
|
* // ┌─── Effect<string, never, never>
|
|
1196
1235
|
* // ▼
|
|
1197
1236
|
* const program = delay("Async operation completed successfully!")
|
|
1237
|
+
* ```
|
|
1198
1238
|
*
|
|
1199
1239
|
* @since 2.0.0
|
|
1200
1240
|
* @category Creating Effects
|
|
@@ -1211,6 +1251,7 @@ export const promise = effect.promise;
|
|
|
1211
1251
|
* @see {@link fail} to create an effect that represents a failure.
|
|
1212
1252
|
*
|
|
1213
1253
|
* @example
|
|
1254
|
+
* ```ts
|
|
1214
1255
|
* // Title: Creating a Successful Effect
|
|
1215
1256
|
* import { Effect } from "effect"
|
|
1216
1257
|
*
|
|
@@ -1219,6 +1260,7 @@ export const promise = effect.promise;
|
|
|
1219
1260
|
* // ┌─── Effect<number, never, never>
|
|
1220
1261
|
* // ▼
|
|
1221
1262
|
* const success = Effect.succeed(42)
|
|
1263
|
+
* ```
|
|
1222
1264
|
*
|
|
1223
1265
|
* @since 2.0.0
|
|
1224
1266
|
* @category Creating Effects
|
|
@@ -1253,6 +1295,7 @@ export const succeedSome = effect.succeedSome;
|
|
|
1253
1295
|
* - **Unifying Return Types**: Can help TypeScript unify return types in situations where multiple branches of logic return different effects, simplifying type inference.
|
|
1254
1296
|
*
|
|
1255
1297
|
* @example
|
|
1298
|
+
* ```ts
|
|
1256
1299
|
* // Title: Lazy Evaluation with Side Effects
|
|
1257
1300
|
* import { Effect } from "effect"
|
|
1258
1301
|
*
|
|
@@ -1267,6 +1310,7 @@ export const succeedSome = effect.succeedSome;
|
|
|
1267
1310
|
*
|
|
1268
1311
|
* console.log(Effect.runSync(good)) // Output: 1
|
|
1269
1312
|
* console.log(Effect.runSync(good)) // Output: 2
|
|
1313
|
+
* ```
|
|
1270
1314
|
*
|
|
1271
1315
|
* @example
|
|
1272
1316
|
* // Title: Recursive Fibonacci
|
|
@@ -1339,6 +1383,7 @@ export const suspend = core.suspend;
|
|
|
1339
1383
|
* @see {@link try_ | try} for a version that can handle failures.
|
|
1340
1384
|
*
|
|
1341
1385
|
* @example
|
|
1386
|
+
* ```ts
|
|
1342
1387
|
* // Title: Logging a Message
|
|
1343
1388
|
* import { Effect } from "effect"
|
|
1344
1389
|
*
|
|
@@ -1350,6 +1395,7 @@ export const suspend = core.suspend;
|
|
|
1350
1395
|
* // ┌─── Effect<void, never, never>
|
|
1351
1396
|
* // ▼
|
|
1352
1397
|
* const program = log("Hello, World!")
|
|
1398
|
+
* ```
|
|
1353
1399
|
*
|
|
1354
1400
|
* @since 2.0.0
|
|
1355
1401
|
* @category Creating Effects
|
|
@@ -1392,6 +1438,7 @@ _catch as catch };
|
|
|
1392
1438
|
* @see {@link catchAllCause} for a version that can recover from both recoverable and unrecoverable errors.
|
|
1393
1439
|
*
|
|
1394
1440
|
* @example
|
|
1441
|
+
* ```ts
|
|
1395
1442
|
* // Title: Providing Recovery Logic for Recoverable Errors
|
|
1396
1443
|
* import { Effect, Random } from "effect"
|
|
1397
1444
|
*
|
|
@@ -1424,6 +1471,7 @@ _catch as catch };
|
|
|
1424
1471
|
* Effect.succeed(`Recovering from ${error._tag}`)
|
|
1425
1472
|
* )
|
|
1426
1473
|
* )
|
|
1474
|
+
* ```
|
|
1427
1475
|
*
|
|
1428
1476
|
* @since 2.0.0
|
|
1429
1477
|
* @category Error handling
|
|
@@ -1447,6 +1495,7 @@ export const catchAll = core.catchAll;
|
|
|
1447
1495
|
* dynamically loaded plugins, controlled recovery might be needed.
|
|
1448
1496
|
*
|
|
1449
1497
|
* @example
|
|
1498
|
+
* ```ts
|
|
1450
1499
|
* // Title: Recovering from All Errors
|
|
1451
1500
|
* import { Cause, Effect } from "effect"
|
|
1452
1501
|
*
|
|
@@ -1464,6 +1513,7 @@ export const catchAll = core.catchAll;
|
|
|
1464
1513
|
*
|
|
1465
1514
|
* Effect.runPromise(recovered).then(console.log)
|
|
1466
1515
|
* // Output: "Recovered from a regular error"
|
|
1516
|
+
* ```
|
|
1467
1517
|
*
|
|
1468
1518
|
* @since 2.0.0
|
|
1469
1519
|
* @category Error handling
|
|
@@ -1493,6 +1543,7 @@ export const catchAllCause = core.catchAllCause;
|
|
|
1493
1543
|
* dynamically loaded plugins, controlled recovery might be needed.
|
|
1494
1544
|
*
|
|
1495
1545
|
* @example
|
|
1546
|
+
* ```ts
|
|
1496
1547
|
* // Title: Handling All Defects
|
|
1497
1548
|
* import { Effect, Cause, Console } from "effect"
|
|
1498
1549
|
*
|
|
@@ -1517,6 +1568,7 @@ export const catchAllCause = core.catchAllCause;
|
|
|
1517
1568
|
* // _tag: "Success",
|
|
1518
1569
|
* // value: undefined
|
|
1519
1570
|
* // }
|
|
1571
|
+
* ```
|
|
1520
1572
|
*
|
|
1521
1573
|
* @since 2.0.0
|
|
1522
1574
|
* @category Error handling
|
|
@@ -1534,6 +1586,7 @@ export const catchAllDefect = effect.catchAllDefect;
|
|
|
1534
1586
|
* error type unless a user-defined type guard is used to narrow the type.
|
|
1535
1587
|
*
|
|
1536
1588
|
* @example
|
|
1589
|
+
* ```ts
|
|
1537
1590
|
* // Title: Catching Specific Errors with a Predicate
|
|
1538
1591
|
* import { Effect, Random } from "effect"
|
|
1539
1592
|
*
|
|
@@ -1568,6 +1621,7 @@ export const catchAllDefect = effect.catchAllDefect;
|
|
|
1568
1621
|
* () => Effect.succeed("Recovering from HttpError")
|
|
1569
1622
|
* )
|
|
1570
1623
|
* )
|
|
1624
|
+
* ```
|
|
1571
1625
|
*
|
|
1572
1626
|
* @since 2.0.0
|
|
1573
1627
|
* @category Error handling
|
|
@@ -1588,6 +1642,7 @@ export const catchIf = core.catchIf;
|
|
|
1588
1642
|
* @see {@link catchIf} for a version that allows you to recover from errors based on a predicate.
|
|
1589
1643
|
*
|
|
1590
1644
|
* @example
|
|
1645
|
+
* ```ts
|
|
1591
1646
|
* // Title: Handling Specific Errors with Effect.catchSome
|
|
1592
1647
|
* import { Effect, Random, Option } from "effect"
|
|
1593
1648
|
*
|
|
@@ -1625,6 +1680,7 @@ export const catchIf = core.catchIf;
|
|
|
1625
1680
|
* }
|
|
1626
1681
|
* })
|
|
1627
1682
|
* )
|
|
1683
|
+
* ```
|
|
1628
1684
|
*
|
|
1629
1685
|
* @since 2.0.0
|
|
1630
1686
|
* @category Error handling
|
|
@@ -1664,6 +1720,7 @@ export const catchSomeCause = effect.catchSomeCause;
|
|
|
1664
1720
|
* - If the defect does not match, the function returns `Option.none`, allowing the defect to propagate.
|
|
1665
1721
|
*
|
|
1666
1722
|
* @example
|
|
1723
|
+
* ```ts
|
|
1667
1724
|
* // Title: Handling Specific Defects
|
|
1668
1725
|
* import { Effect, Cause, Option, Console } from "effect"
|
|
1669
1726
|
*
|
|
@@ -1694,6 +1751,7 @@ export const catchSomeCause = effect.catchSomeCause;
|
|
|
1694
1751
|
* // defect: { _tag: 'RuntimeException' }
|
|
1695
1752
|
* // }
|
|
1696
1753
|
* // }
|
|
1754
|
+
* ```
|
|
1697
1755
|
*
|
|
1698
1756
|
* @since 2.0.0
|
|
1699
1757
|
* @category Error handling
|
|
@@ -1717,6 +1775,7 @@ export const catchSomeDefect = effect.catchSomeDefect;
|
|
|
1717
1775
|
* types at once.
|
|
1718
1776
|
*
|
|
1719
1777
|
* @example
|
|
1778
|
+
* ```ts
|
|
1720
1779
|
* // Title: Handling Errors by Tag
|
|
1721
1780
|
* import { Effect, Random } from "effect"
|
|
1722
1781
|
*
|
|
@@ -1750,6 +1809,7 @@ export const catchSomeDefect = effect.catchSomeDefect;
|
|
|
1750
1809
|
* Effect.succeed("Recovering from HttpError")
|
|
1751
1810
|
* )
|
|
1752
1811
|
* )
|
|
1812
|
+
* ```
|
|
1753
1813
|
*
|
|
1754
1814
|
* @since 2.0.0
|
|
1755
1815
|
* @category Error handling
|
|
@@ -1770,6 +1830,7 @@ export const catchTag = effect.catchTag;
|
|
|
1770
1830
|
* field is used to identify and match errors.
|
|
1771
1831
|
*
|
|
1772
1832
|
* @example
|
|
1833
|
+
* ```ts
|
|
1773
1834
|
* // Title: Handling Multiple Tagged Error Types at Once
|
|
1774
1835
|
* import { Effect, Random } from "effect"
|
|
1775
1836
|
*
|
|
@@ -1805,6 +1866,7 @@ export const catchTag = effect.catchTag;
|
|
|
1805
1866
|
* Effect.succeed(`Recovering from ValidationError`)
|
|
1806
1867
|
* })
|
|
1807
1868
|
* )
|
|
1869
|
+
* ```
|
|
1808
1870
|
*
|
|
1809
1871
|
* @since 2.0.0
|
|
1810
1872
|
* @category Error handling
|
|
@@ -1822,6 +1884,7 @@ export const catchTags = effect.catchTags;
|
|
|
1822
1884
|
* interruptions, etc.).
|
|
1823
1885
|
*
|
|
1824
1886
|
* @example
|
|
1887
|
+
* ```ts
|
|
1825
1888
|
* import { Effect, Console } from "effect"
|
|
1826
1889
|
*
|
|
1827
1890
|
* // ┌─── Effect<number, string, never>
|
|
@@ -1834,6 +1897,7 @@ export const catchTags = effect.catchTags;
|
|
|
1834
1897
|
* const cause = yield* Effect.cause(program)
|
|
1835
1898
|
* yield* Console.log(cause)
|
|
1836
1899
|
* })
|
|
1900
|
+
* ```
|
|
1837
1901
|
*
|
|
1838
1902
|
* @since 2.0.0
|
|
1839
1903
|
* @category Error handling
|
|
@@ -1855,6 +1919,7 @@ export const eventually = effect.eventually;
|
|
|
1855
1919
|
* side effects of the effect and do not need to handle or process its outcome.
|
|
1856
1920
|
*
|
|
1857
1921
|
* @example
|
|
1922
|
+
* ```ts
|
|
1858
1923
|
* import { Effect } from "effect"
|
|
1859
1924
|
*
|
|
1860
1925
|
* // ┌─── Effect<number, string, never>
|
|
@@ -1864,6 +1929,7 @@ export const eventually = effect.eventually;
|
|
|
1864
1929
|
* // ┌─── Effect<void, never, never>
|
|
1865
1930
|
* // ▼
|
|
1866
1931
|
* const program = Effect.ignore(task)
|
|
1932
|
+
* ```
|
|
1867
1933
|
*
|
|
1868
1934
|
* @since 2.0.0
|
|
1869
1935
|
* @category Error handling
|
|
@@ -1889,6 +1955,7 @@ export const ignoreLogged = effect.ignoreLogged;
|
|
|
1889
1955
|
* it easier to manage and respond to errors from multiple operations at once.
|
|
1890
1956
|
*
|
|
1891
1957
|
* @example
|
|
1958
|
+
* ```ts
|
|
1892
1959
|
* import { Effect } from "effect"
|
|
1893
1960
|
*
|
|
1894
1961
|
* const fail1 = Effect.fail("Oh uh!")
|
|
@@ -1907,6 +1974,7 @@ export const ignoreLogged = effect.ignoreLogged;
|
|
|
1907
1974
|
* // _tag: 'Failure',
|
|
1908
1975
|
* // cause: { _id: 'Cause', _tag: 'Fail', failure: [ 'Oh uh!', 'Oh no!' ] }
|
|
1909
1976
|
* // }
|
|
1977
|
+
* ```
|
|
1910
1978
|
*
|
|
1911
1979
|
* @since 2.0.0
|
|
1912
1980
|
* @category Error handling
|
|
@@ -1928,6 +1996,7 @@ export const parallelErrors = effect.parallelErrors;
|
|
|
1928
1996
|
* @see {@link unsandbox} to restore the original error handling.
|
|
1929
1997
|
*
|
|
1930
1998
|
* @example
|
|
1999
|
+
* ```ts
|
|
1931
2000
|
* import { Effect, Console } from "effect"
|
|
1932
2001
|
*
|
|
1933
2002
|
* // ┌─── Effect<string, Error, never>
|
|
@@ -1962,6 +2031,7 @@ export const parallelErrors = effect.parallelErrors;
|
|
|
1962
2031
|
* // Output:
|
|
1963
2032
|
* // Caught a defect: Oh uh!
|
|
1964
2033
|
* // fallback result on failure
|
|
2034
|
+
* ```
|
|
1965
2035
|
*
|
|
1966
2036
|
* @since 2.0.0
|
|
1967
2037
|
* @category Error handling
|
|
@@ -1984,6 +2054,7 @@ export const sandbox = effect.sandbox;
|
|
|
1984
2054
|
* @see {@link retryOrElse} for a version that allows you to run a fallback.
|
|
1985
2055
|
*
|
|
1986
2056
|
* @example
|
|
2057
|
+
* ```ts
|
|
1987
2058
|
* import { Effect, Schedule } from "effect"
|
|
1988
2059
|
*
|
|
1989
2060
|
* let count = 0
|
|
@@ -2012,6 +2083,7 @@ export const sandbox = effect.sandbox;
|
|
|
2012
2083
|
* // failure
|
|
2013
2084
|
* // success
|
|
2014
2085
|
* // yay!
|
|
2086
|
+
* ```
|
|
2015
2087
|
*
|
|
2016
2088
|
* @since 2.0.0
|
|
2017
2089
|
* @category Error handling
|
|
@@ -2029,6 +2101,7 @@ export const retry = _schedule.retry_combined;
|
|
|
2029
2101
|
* @see {@link retry} for a version that does not run a fallback effect.
|
|
2030
2102
|
*
|
|
2031
2103
|
* @example
|
|
2104
|
+
* ```ts
|
|
2032
2105
|
* import { Effect, Schedule, Console } from "effect"
|
|
2033
2106
|
*
|
|
2034
2107
|
* let count = 0
|
|
@@ -2060,6 +2133,7 @@ export const retry = _schedule.retry_combined;
|
|
|
2060
2133
|
* // failure
|
|
2061
2134
|
* // orElse
|
|
2062
2135
|
* // default value
|
|
2136
|
+
* ```
|
|
2063
2137
|
*
|
|
2064
2138
|
* @since 2.0.0
|
|
2065
2139
|
* @category Error handling
|
|
@@ -2091,6 +2165,7 @@ export {
|
|
|
2091
2165
|
* throw errors.
|
|
2092
2166
|
*
|
|
2093
2167
|
* @example
|
|
2168
|
+
* ```ts
|
|
2094
2169
|
* // Title: Safe JSON Parsing
|
|
2095
2170
|
* import { Effect } from "effect"
|
|
2096
2171
|
*
|
|
@@ -2102,6 +2177,7 @@ export {
|
|
|
2102
2177
|
* // ▼
|
|
2103
2178
|
* const program = parse("")
|
|
2104
2179
|
*
|
|
2180
|
+
* ```
|
|
2105
2181
|
* @example
|
|
2106
2182
|
* // Title: Custom Error Handling
|
|
2107
2183
|
* import { Effect } from "effect"
|
|
@@ -2172,6 +2248,7 @@ export const tryMapPromise = effect.tryMapPromise;
|
|
|
2172
2248
|
* @see {@link promise} if the effectful computation is asynchronous and does not throw errors.
|
|
2173
2249
|
*
|
|
2174
2250
|
* @example
|
|
2251
|
+
* ```ts
|
|
2175
2252
|
* // Title: Fetching a TODO Item
|
|
2176
2253
|
* import { Effect } from "effect"
|
|
2177
2254
|
*
|
|
@@ -2184,6 +2261,7 @@ export const tryMapPromise = effect.tryMapPromise;
|
|
|
2184
2261
|
* // ┌─── Effect<Response, UnknownException, never>
|
|
2185
2262
|
* // ▼
|
|
2186
2263
|
* const program = getTodo(1)
|
|
2264
|
+
* ```
|
|
2187
2265
|
*
|
|
2188
2266
|
* @example
|
|
2189
2267
|
* // Title: Custom Error Handling
|
|
@@ -2266,6 +2344,7 @@ export const checkInterruptible = core.checkInterruptible;
|
|
|
2266
2344
|
* @see {@link Effect.uninterruptible} for creating an uninterruptible effect.
|
|
2267
2345
|
*
|
|
2268
2346
|
* @example
|
|
2347
|
+
* ```ts
|
|
2269
2348
|
* import { Effect } from "effect"
|
|
2270
2349
|
*
|
|
2271
2350
|
* const longRunningTask = Effect.gen(function* () {
|
|
@@ -2295,6 +2374,7 @@ export const checkInterruptible = core.checkInterruptible;
|
|
|
2295
2374
|
* // }
|
|
2296
2375
|
* // }
|
|
2297
2376
|
* // Heavy processing done.
|
|
2377
|
+
* ```
|
|
2298
2378
|
*
|
|
2299
2379
|
* @since 2.0.0
|
|
2300
2380
|
* @category Interruption
|
|
@@ -2340,6 +2420,7 @@ export const uninterruptibleMask = core.uninterruptibleMask;
|
|
|
2340
2420
|
* or failing with specified error if the predicate fails
|
|
2341
2421
|
*
|
|
2342
2422
|
* @example
|
|
2423
|
+
* ```ts
|
|
2343
2424
|
* import { Effect } from "effect"
|
|
2344
2425
|
*
|
|
2345
2426
|
* const isPositive = (n: number): boolean => n > 0
|
|
@@ -2349,6 +2430,7 @@ export const uninterruptibleMask = core.uninterruptibleMask;
|
|
|
2349
2430
|
*
|
|
2350
2431
|
* // fails with `"0 is not positive"`
|
|
2351
2432
|
* Effect.liftPredicate(0, isPositive, n => `${n} is not positive`)
|
|
2433
|
+
* ```
|
|
2352
2434
|
*
|
|
2353
2435
|
* @category Condition Checking
|
|
2354
2436
|
* @since 3.4.0
|
|
@@ -2361,6 +2443,7 @@ export const liftPredicate = effect.liftPredicate;
|
|
|
2361
2443
|
* replace it with a new constant value.
|
|
2362
2444
|
*
|
|
2363
2445
|
* @example
|
|
2446
|
+
* ```ts
|
|
2364
2447
|
* // Title: Replacing a Value
|
|
2365
2448
|
* import { pipe, Effect } from "effect"
|
|
2366
2449
|
*
|
|
@@ -2369,6 +2452,7 @@ export const liftPredicate = effect.liftPredicate;
|
|
|
2369
2452
|
*
|
|
2370
2453
|
* Effect.runPromise(program).then(console.log)
|
|
2371
2454
|
* // Output: "new value"
|
|
2455
|
+
* ```
|
|
2372
2456
|
*
|
|
2373
2457
|
* @since 2.0.0
|
|
2374
2458
|
* @category Mapping
|
|
@@ -2412,6 +2496,7 @@ export const asVoid = core.asVoid;
|
|
|
2412
2496
|
* treat an error as a valid result.
|
|
2413
2497
|
*
|
|
2414
2498
|
* @example
|
|
2499
|
+
* ```ts
|
|
2415
2500
|
* import { Effect } from "effect"
|
|
2416
2501
|
*
|
|
2417
2502
|
* // ┌─── Effect<number, string, never>
|
|
@@ -2421,6 +2506,7 @@ export const asVoid = core.asVoid;
|
|
|
2421
2506
|
* // ┌─── Effect<string, number, never>
|
|
2422
2507
|
* // ▼
|
|
2423
2508
|
* const flipped = Effect.flip(program)
|
|
2509
|
+
* ```
|
|
2424
2510
|
*
|
|
2425
2511
|
* @since 2.0.0
|
|
2426
2512
|
* @category Mapping
|
|
@@ -2461,6 +2547,7 @@ export const flipWith = effect.flipWith;
|
|
|
2461
2547
|
* @see {@link flatMap} or {@link andThen} for a version that can return a new effect.
|
|
2462
2548
|
*
|
|
2463
2549
|
* @example
|
|
2550
|
+
* ```ts
|
|
2464
2551
|
* // Title: Adding a Service Charge
|
|
2465
2552
|
* import { pipe, Effect } from "effect"
|
|
2466
2553
|
*
|
|
@@ -2475,6 +2562,7 @@ export const flipWith = effect.flipWith;
|
|
|
2475
2562
|
*
|
|
2476
2563
|
* Effect.runPromise(finalAmount).then(console.log)
|
|
2477
2564
|
* // Output: 101
|
|
2565
|
+
* ```
|
|
2478
2566
|
* @since 2.0.0
|
|
2479
2567
|
* @category Mapping
|
|
2480
2568
|
*/
|
|
@@ -2499,6 +2587,7 @@ export const map = core.map;
|
|
|
2499
2587
|
* input collection type.
|
|
2500
2588
|
*
|
|
2501
2589
|
* @example
|
|
2590
|
+
* ```ts
|
|
2502
2591
|
* import { Effect } from "effect"
|
|
2503
2592
|
*
|
|
2504
2593
|
* // Define an initial state and a transformation function
|
|
@@ -2517,6 +2606,7 @@ export const map = core.map;
|
|
|
2517
2606
|
* // Output:
|
|
2518
2607
|
* // 6
|
|
2519
2608
|
* // [ 'A', 'BB', 'CCC' ]
|
|
2609
|
+
* ```
|
|
2520
2610
|
*
|
|
2521
2611
|
* @since 2.0.0
|
|
2522
2612
|
* @category Mapping
|
|
@@ -2535,6 +2625,7 @@ export const mapAccum = effect.mapAccum;
|
|
|
2535
2625
|
* @see {@link mapError} for a version that operates on the error channel.
|
|
2536
2626
|
*
|
|
2537
2627
|
* @example
|
|
2628
|
+
* ```ts
|
|
2538
2629
|
* import { Effect } from "effect"
|
|
2539
2630
|
*
|
|
2540
2631
|
* // ┌─── Effect<number, string, never>
|
|
@@ -2547,6 +2638,7 @@ export const mapAccum = effect.mapAccum;
|
|
|
2547
2638
|
* onFailure: (message) => new Error(message),
|
|
2548
2639
|
* onSuccess: (n) => n > 0
|
|
2549
2640
|
* })
|
|
2641
|
+
* ```
|
|
2550
2642
|
*
|
|
2551
2643
|
* @since 2.0.0
|
|
2552
2644
|
* @category Mapping
|
|
@@ -2566,6 +2658,7 @@ export const mapBoth = core.mapBoth;
|
|
|
2566
2658
|
* @see {@link orElseFail} if you want to replace the error with a new one.
|
|
2567
2659
|
*
|
|
2568
2660
|
* @example
|
|
2661
|
+
* ```ts
|
|
2569
2662
|
* import { Effect } from "effect"
|
|
2570
2663
|
*
|
|
2571
2664
|
* // ┌─── Effect<number, string, never>
|
|
@@ -2578,6 +2671,7 @@ export const mapBoth = core.mapBoth;
|
|
|
2578
2671
|
* simulatedTask,
|
|
2579
2672
|
* (message) => new Error(message)
|
|
2580
2673
|
* )
|
|
2674
|
+
* ```
|
|
2581
2675
|
*
|
|
2582
2676
|
* @since 2.0.0
|
|
2583
2677
|
* @category Mapping
|
|
@@ -2605,6 +2699,7 @@ export const mapErrorCause = effect.mapErrorCause;
|
|
|
2605
2699
|
* errors as part of the outcome.
|
|
2606
2700
|
*
|
|
2607
2701
|
* @example
|
|
2702
|
+
* ```ts
|
|
2608
2703
|
* import { Effect } from "effect"
|
|
2609
2704
|
*
|
|
2610
2705
|
* // ┌─── Effect<number, string, never>
|
|
@@ -2614,6 +2709,7 @@ export const mapErrorCause = effect.mapErrorCause;
|
|
|
2614
2709
|
* // ┌─── Effect<number | string, never, never>
|
|
2615
2710
|
* // ▼
|
|
2616
2711
|
* const recovered = Effect.merge(program)
|
|
2712
|
+
* ```
|
|
2617
2713
|
*
|
|
2618
2714
|
* @since 2.0.0
|
|
2619
2715
|
* @category Mapping
|
|
@@ -2762,6 +2858,15 @@ export const scope = fiberRuntime.scope;
|
|
|
2762
2858
|
* @category scoping, resources & finalization
|
|
2763
2859
|
*/
|
|
2764
2860
|
export const scopeWith = fiberRuntime.scopeWith;
|
|
2861
|
+
/**
|
|
2862
|
+
* Creates a `Scope`, passes it to the specified effectful function, and then
|
|
2863
|
+
* closes the scope as soon as the effect is complete (whether through success,
|
|
2864
|
+
* failure, or interruption).
|
|
2865
|
+
*
|
|
2866
|
+
* @since 3.11.0
|
|
2867
|
+
* @category scoping, resources & finalization
|
|
2868
|
+
*/
|
|
2869
|
+
export const scopedWith = fiberRuntime.scopedWith;
|
|
2765
2870
|
/**
|
|
2766
2871
|
* Scopes all resources used in this workflow to the lifetime of the workflow,
|
|
2767
2872
|
* ensuring that their finalizers are run as soon as this workflow completes
|
|
@@ -3085,6 +3190,7 @@ export const timedWith = effect.timedWith;
|
|
|
3085
3190
|
* @see {@link timeoutTo} for a version that allows specifying both success and timeout handlers.
|
|
3086
3191
|
*
|
|
3087
3192
|
* @example
|
|
3193
|
+
* ```ts
|
|
3088
3194
|
* import { Effect } from "effect"
|
|
3089
3195
|
*
|
|
3090
3196
|
* const task = Effect.gen(function* () {
|
|
@@ -3110,6 +3216,7 @@ export const timedWith = effect.timedWith;
|
|
|
3110
3216
|
* // failure: { _tag: 'TimeoutException' }
|
|
3111
3217
|
* // }
|
|
3112
3218
|
* // }
|
|
3219
|
+
* ```
|
|
3113
3220
|
*
|
|
3114
3221
|
* @since 2.0.0
|
|
3115
3222
|
* @category delays & timeouts
|
|
@@ -3135,6 +3242,7 @@ export const timeout = circular.timeout;
|
|
|
3135
3242
|
* @see {@link timeoutTo} for a version that allows specifying both success and timeout handlers.
|
|
3136
3243
|
*
|
|
3137
3244
|
* @example
|
|
3245
|
+
* ```ts
|
|
3138
3246
|
* import { Effect } from "effect"
|
|
3139
3247
|
*
|
|
3140
3248
|
* const task = Effect.gen(function* () {
|
|
@@ -3158,6 +3266,7 @@ export const timeout = circular.timeout;
|
|
|
3158
3266
|
* // { _id: 'Option', _tag: 'Some', value: 'Result' },
|
|
3159
3267
|
* // { _id: 'Option', _tag: 'None' }
|
|
3160
3268
|
* // ]
|
|
3269
|
+
* ```
|
|
3161
3270
|
*
|
|
3162
3271
|
* @since 3.1.0
|
|
3163
3272
|
* @category delays & timeouts
|
|
@@ -3182,6 +3291,7 @@ export const timeoutOption = circular.timeoutOption;
|
|
|
3182
3291
|
* @see {@link timeoutTo} for a version that allows specifying both success and timeout handlers.
|
|
3183
3292
|
*
|
|
3184
3293
|
* @example
|
|
3294
|
+
* ```ts
|
|
3185
3295
|
* import { Effect } from "effect"
|
|
3186
3296
|
*
|
|
3187
3297
|
* const task = Effect.gen(function* () {
|
|
@@ -3214,6 +3324,7 @@ export const timeoutOption = circular.timeoutOption;
|
|
|
3214
3324
|
* // failure: MyTimeoutError { _tag: 'MyTimeoutError' }
|
|
3215
3325
|
* // }
|
|
3216
3326
|
* // }
|
|
3327
|
+
* ```
|
|
3217
3328
|
*
|
|
3218
3329
|
* @since 2.0.0
|
|
3219
3330
|
* @category delays & timeouts
|
|
@@ -3237,6 +3348,7 @@ export const timeoutFail = circular.timeoutFail;
|
|
|
3237
3348
|
* @see {@link timeoutTo} for a version that allows specifying both success and timeout handlers.
|
|
3238
3349
|
*
|
|
3239
3350
|
* @example
|
|
3351
|
+
* ```ts
|
|
3240
3352
|
* import { Effect, Cause } from "effect"
|
|
3241
3353
|
*
|
|
3242
3354
|
* const task = Effect.gen(function* () {
|
|
@@ -3261,6 +3373,7 @@ export const timeoutFail = circular.timeoutFail;
|
|
|
3261
3373
|
* // _tag: 'Failure',
|
|
3262
3374
|
* // cause: { _id: 'Cause', _tag: 'Die', defect: 'Timed out!' }
|
|
3263
3375
|
* // }
|
|
3376
|
+
* ```
|
|
3264
3377
|
*
|
|
3265
3378
|
* @since 2.0.0
|
|
3266
3379
|
* @category delays & timeouts
|
|
@@ -3288,6 +3401,7 @@ export const timeoutFailCause = circular.timeoutFailCause;
|
|
|
3288
3401
|
* @see {@link timeoutFailCause} for a version that raises a custom defect.
|
|
3289
3402
|
*
|
|
3290
3403
|
* @example
|
|
3404
|
+
* ```ts
|
|
3291
3405
|
* import { Effect, Either } from "effect"
|
|
3292
3406
|
*
|
|
3293
3407
|
* const task = Effect.gen(function* () {
|
|
@@ -3315,6 +3429,7 @@ export const timeoutFailCause = circular.timeoutFailCause;
|
|
|
3315
3429
|
* // _tag: "Left",
|
|
3316
3430
|
* // left: "Timed out!"
|
|
3317
3431
|
* // }
|
|
3432
|
+
* ```
|
|
3318
3433
|
*
|
|
3319
3434
|
* @since 2.0.0
|
|
3320
3435
|
* @category delays & timeouts
|
|
@@ -3381,6 +3496,7 @@ export const mapInputContext = core.mapInputContext;
|
|
|
3381
3496
|
* @see {@link provideService} for providing a service to an effect.
|
|
3382
3497
|
*
|
|
3383
3498
|
* @example
|
|
3499
|
+
* ```ts
|
|
3384
3500
|
* import { Context, Effect, Layer } from "effect"
|
|
3385
3501
|
*
|
|
3386
3502
|
* class Database extends Context.Tag("Database")<
|
|
@@ -3412,6 +3528,7 @@ export const mapInputContext = core.mapInputContext;
|
|
|
3412
3528
|
* // Output:
|
|
3413
3529
|
* // timestamp=... level=INFO fiber=#0 message="Executing query: SELECT * FROM users"
|
|
3414
3530
|
* // []
|
|
3531
|
+
* ```
|
|
3415
3532
|
*
|
|
3416
3533
|
* @since 2.0.0
|
|
3417
3534
|
* @category Context
|
|
@@ -3430,6 +3547,7 @@ export const provide = layer.effect_provide;
|
|
|
3430
3547
|
* @see {@link provide} for providing multiple layers to an effect.
|
|
3431
3548
|
*
|
|
3432
3549
|
* @example
|
|
3550
|
+
* ```ts
|
|
3433
3551
|
* import { Effect, Context } from "effect"
|
|
3434
3552
|
*
|
|
3435
3553
|
* // Declaring a tag for a service that generates random numbers
|
|
@@ -3457,6 +3575,7 @@ export const provide = layer.effect_provide;
|
|
|
3457
3575
|
* Effect.runPromise(runnable)
|
|
3458
3576
|
* // Example Output:
|
|
3459
3577
|
* // random number: 0.8241872233134417
|
|
3578
|
+
* ```
|
|
3460
3579
|
*
|
|
3461
3580
|
* @since 2.0.0
|
|
3462
3581
|
* @category Context
|
|
@@ -3527,6 +3646,7 @@ export const updateService = effect.updateService;
|
|
|
3527
3646
|
* @see {@link let_ let}
|
|
3528
3647
|
*
|
|
3529
3648
|
* @example
|
|
3649
|
+
* ```ts
|
|
3530
3650
|
* import { Effect, pipe } from "effect"
|
|
3531
3651
|
*
|
|
3532
3652
|
* const result = pipe(
|
|
@@ -3536,6 +3656,7 @@ export const updateService = effect.updateService;
|
|
|
3536
3656
|
* Effect.let("sum", ({ x, y }) => x + y)
|
|
3537
3657
|
* )
|
|
3538
3658
|
* assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 })
|
|
3659
|
+
* ```
|
|
3539
3660
|
*
|
|
3540
3661
|
* @category Do notation
|
|
3541
3662
|
* @since 2.0.0
|
|
@@ -3556,6 +3677,7 @@ export const Do = effect.Do;
|
|
|
3556
3677
|
* @see {@link let_ let}
|
|
3557
3678
|
*
|
|
3558
3679
|
* @example
|
|
3680
|
+
* ```ts
|
|
3559
3681
|
* import { Effect, pipe } from "effect"
|
|
3560
3682
|
*
|
|
3561
3683
|
* const result = pipe(
|
|
@@ -3565,6 +3687,7 @@ export const Do = effect.Do;
|
|
|
3565
3687
|
* Effect.let("sum", ({ x, y }) => x + y)
|
|
3566
3688
|
* )
|
|
3567
3689
|
* assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 })
|
|
3690
|
+
* ```
|
|
3568
3691
|
*
|
|
3569
3692
|
* @category Do notation
|
|
3570
3693
|
* @since 2.0.0
|
|
@@ -3576,6 +3699,7 @@ export const bind = effect.bind;
|
|
|
3576
3699
|
* results in a Do notation pipeline.
|
|
3577
3700
|
*
|
|
3578
3701
|
* @example
|
|
3702
|
+
* ```ts
|
|
3579
3703
|
* import { Effect, Either, pipe } from "effect"
|
|
3580
3704
|
*
|
|
3581
3705
|
* const result = pipe(
|
|
@@ -3587,6 +3711,7 @@ export const bind = effect.bind;
|
|
|
3587
3711
|
* }), { concurrency: 2, mode: "either" })
|
|
3588
3712
|
* )
|
|
3589
3713
|
* assert.deepStrictEqual(Effect.runSync(result), { x: 2, a: Either.right(2), b: Either.left("oops") })
|
|
3714
|
+
* ```
|
|
3590
3715
|
*
|
|
3591
3716
|
* @category Do notation
|
|
3592
3717
|
* @since 3.7.0
|
|
@@ -3607,6 +3732,7 @@ export const bindAll = circular.bindAll;
|
|
|
3607
3732
|
* @see {@link let_ let}
|
|
3608
3733
|
*
|
|
3609
3734
|
* @example
|
|
3735
|
+
* ```ts
|
|
3610
3736
|
* import { Effect, pipe } from "effect"
|
|
3611
3737
|
*
|
|
3612
3738
|
* const result = pipe(
|
|
@@ -3616,6 +3742,7 @@ export const bindAll = circular.bindAll;
|
|
|
3616
3742
|
* Effect.let("sum", ({ x, y }) => x + y)
|
|
3617
3743
|
* )
|
|
3618
3744
|
* assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 })
|
|
3745
|
+
* ```
|
|
3619
3746
|
*
|
|
3620
3747
|
* @category Do notation
|
|
3621
3748
|
* @since 2.0.0
|
|
@@ -3638,6 +3765,7 @@ export {
|
|
|
3638
3765
|
* @see {@link bindTo}
|
|
3639
3766
|
*
|
|
3640
3767
|
* @example
|
|
3768
|
+
* ```ts
|
|
3641
3769
|
* import { Effect, pipe } from "effect"
|
|
3642
3770
|
*
|
|
3643
3771
|
* const result = pipe(
|
|
@@ -3648,6 +3776,7 @@ export {
|
|
|
3648
3776
|
* )
|
|
3649
3777
|
* assert.deepStrictEqual(Effect.runSync(result), { x: 2, y: 3, sum: 5 })
|
|
3650
3778
|
*
|
|
3779
|
+
* ```
|
|
3651
3780
|
* @category Do notation
|
|
3652
3781
|
* @since 2.0.0
|
|
3653
3782
|
*/
|
|
@@ -3670,6 +3799,7 @@ let_ as let };
|
|
|
3670
3799
|
* @see {@link exit} for a version that uses `Exit` instead.
|
|
3671
3800
|
*
|
|
3672
3801
|
* @example
|
|
3802
|
+
* ```ts
|
|
3673
3803
|
* // Title: Using Effect.option to Handle Errors
|
|
3674
3804
|
* import { Effect } from "effect"
|
|
3675
3805
|
*
|
|
@@ -3702,6 +3832,7 @@ let_ as let };
|
|
|
3702
3832
|
* // _tag: 'Failure',
|
|
3703
3833
|
* // cause: { _id: 'Cause', _tag: 'Die', defect: 'Boom!' }
|
|
3704
3834
|
* // }
|
|
3835
|
+
* ```
|
|
3705
3836
|
*
|
|
3706
3837
|
* @since 2.0.0
|
|
3707
3838
|
* @category Outcome Encapsulation
|
|
@@ -3726,6 +3857,7 @@ export const option = effect.option;
|
|
|
3726
3857
|
* @see {@link exit} for a version that uses `Exit` instead.
|
|
3727
3858
|
*
|
|
3728
3859
|
* @example
|
|
3860
|
+
* ```ts
|
|
3729
3861
|
* import { Effect, Either, Random } from "effect"
|
|
3730
3862
|
*
|
|
3731
3863
|
* class HttpError {
|
|
@@ -3761,6 +3893,7 @@ export const option = effect.option;
|
|
|
3761
3893
|
* onRight: (value) => value // Do nothing in case of success
|
|
3762
3894
|
* })
|
|
3763
3895
|
* })
|
|
3896
|
+
* ```
|
|
3764
3897
|
*
|
|
3765
3898
|
* @since 2.0.0
|
|
3766
3899
|
* @category Outcome Encapsulation
|
|
@@ -3783,6 +3916,7 @@ export const either = core.either;
|
|
|
3783
3916
|
* @see {@link either} for a version that uses `Either` instead.
|
|
3784
3917
|
*
|
|
3785
3918
|
* @example
|
|
3919
|
+
* ```ts
|
|
3786
3920
|
* import { Effect, Cause, Console, Exit } from "effect"
|
|
3787
3921
|
*
|
|
3788
3922
|
* // Simulating a runtime error
|
|
@@ -3814,6 +3948,7 @@ export const either = core.either;
|
|
|
3814
3948
|
* // _tag: "Success",
|
|
3815
3949
|
* // value: undefined
|
|
3816
3950
|
* // }
|
|
3951
|
+
* ```
|
|
3817
3952
|
*
|
|
3818
3953
|
* @since 2.0.0
|
|
3819
3954
|
* @category Outcome Encapsulation
|
|
@@ -3830,6 +3965,7 @@ export const exit = core.exit;
|
|
|
3830
3965
|
* failure. Additionally, if the effect is interrupted, the `Deferred` will also be interrupted.
|
|
3831
3966
|
*
|
|
3832
3967
|
* @example
|
|
3968
|
+
* ```ts
|
|
3833
3969
|
* import { Deferred, Effect } from "effect"
|
|
3834
3970
|
*
|
|
3835
3971
|
* // Define an effect that succeeds
|
|
@@ -3853,6 +3989,7 @@ export const exit = core.exit;
|
|
|
3853
3989
|
* // Output:
|
|
3854
3990
|
* // 42
|
|
3855
3991
|
* // true
|
|
3992
|
+
* ```
|
|
3856
3993
|
*
|
|
3857
3994
|
* @since 2.0.0
|
|
3858
3995
|
* @category Synchronization Utilities
|
|
@@ -3868,6 +4005,7 @@ export {
|
|
|
3868
4005
|
* is executed. If it is `false`, the `onFalse` effect is executed instead.
|
|
3869
4006
|
*
|
|
3870
4007
|
* @example
|
|
4008
|
+
* ```ts
|
|
3871
4009
|
* // Title: Simulating a Coin Flip
|
|
3872
4010
|
* import { Effect, Random, Console } from "effect"
|
|
3873
4011
|
*
|
|
@@ -3878,6 +4016,7 @@ export {
|
|
|
3878
4016
|
*
|
|
3879
4017
|
* Effect.runFork(flipTheCoin)
|
|
3880
4018
|
*
|
|
4019
|
+
* ```
|
|
3881
4020
|
* @since 2.0.0
|
|
3882
4021
|
* @category Conditional Operators
|
|
3883
4022
|
*/
|
|
@@ -3917,6 +4056,7 @@ export const filterOrElse = effect.filterOrElse;
|
|
|
3917
4056
|
* Let's explore this concept through an example:
|
|
3918
4057
|
*
|
|
3919
4058
|
* @example
|
|
4059
|
+
* ```ts
|
|
3920
4060
|
* import { Effect, pipe } from "effect"
|
|
3921
4061
|
*
|
|
3922
4062
|
* // Define a user interface
|
|
@@ -3937,6 +4077,7 @@ export const filterOrElse = effect.filterOrElse;
|
|
|
3937
4077
|
* // 'user' now has the type `User` (not `User | null`)
|
|
3938
4078
|
* Effect.andThen((user) => user.name)
|
|
3939
4079
|
* )
|
|
4080
|
+
* ```
|
|
3940
4081
|
*
|
|
3941
4082
|
* @since 2.0.0
|
|
3942
4083
|
* @category Filtering
|
|
@@ -3980,6 +4121,7 @@ export const unlessEffect = effect.unlessEffect;
|
|
|
3980
4121
|
* @see {@link unless} for a version that executes the effect when the condition is `false`.
|
|
3981
4122
|
*
|
|
3982
4123
|
* @example
|
|
4124
|
+
* ```ts
|
|
3983
4125
|
* // Title: Conditional Effect Execution
|
|
3984
4126
|
* import { Effect, Option } from "effect"
|
|
3985
4127
|
*
|
|
@@ -4005,6 +4147,7 @@ export const unlessEffect = effect.unlessEffect;
|
|
|
4005
4147
|
* // _id: "Option",
|
|
4006
4148
|
* // _tag: "None"
|
|
4007
4149
|
* // }
|
|
4150
|
+
* ```
|
|
4008
4151
|
*
|
|
4009
4152
|
* @since 2.0.0
|
|
4010
4153
|
* @category Conditional Operators
|
|
@@ -4028,6 +4171,7 @@ export const when = effect.when;
|
|
|
4028
4171
|
* @see {@link unlessEffect} for a version that executes the effect when the condition is `false`.
|
|
4029
4172
|
*
|
|
4030
4173
|
* @example
|
|
4174
|
+
* ```ts
|
|
4031
4175
|
* // Title: Using an Effect as a Condition
|
|
4032
4176
|
* import { Effect, Random } from "effect"
|
|
4033
4177
|
*
|
|
@@ -4038,6 +4182,7 @@ export const when = effect.when;
|
|
|
4038
4182
|
* console.log(Effect.runSync(randomIntOption))
|
|
4039
4183
|
* // Example Output:
|
|
4040
4184
|
* // { _id: 'Option', _tag: 'Some', value: 8609104974198840 }
|
|
4185
|
+
* ```
|
|
4041
4186
|
*
|
|
4042
4187
|
* @since 2.0.0
|
|
4043
4188
|
* @category Conditional Operators
|
|
@@ -4088,6 +4233,7 @@ export const whenRef = effect.whenRef;
|
|
|
4088
4233
|
* changing the original one.
|
|
4089
4234
|
*
|
|
4090
4235
|
* @example
|
|
4236
|
+
* ```ts
|
|
4091
4237
|
* import { pipe, Effect } from "effect"
|
|
4092
4238
|
*
|
|
4093
4239
|
* // Function to apply a discount safely to a transaction amount
|
|
@@ -4110,6 +4256,7 @@ export const whenRef = effect.whenRef;
|
|
|
4110
4256
|
*
|
|
4111
4257
|
* Effect.runPromise(finalAmount).then(console.log)
|
|
4112
4258
|
* // Output: 95
|
|
4259
|
+
* ```
|
|
4113
4260
|
*
|
|
4114
4261
|
* @since 2.0.0
|
|
4115
4262
|
* @category sequencing
|
|
@@ -4149,6 +4296,7 @@ export const flatMap = core.flatMap;
|
|
|
4149
4296
|
* treating them as effects.
|
|
4150
4297
|
*
|
|
4151
4298
|
* @example
|
|
4299
|
+
* ```ts
|
|
4152
4300
|
* // Title: Applying a Discount Based on Fetched Amount
|
|
4153
4301
|
* import { pipe, Effect } from "effect"
|
|
4154
4302
|
*
|
|
@@ -4183,6 +4331,7 @@ export const flatMap = core.flatMap;
|
|
|
4183
4331
|
*
|
|
4184
4332
|
* Effect.runPromise(result2).then(console.log)
|
|
4185
4333
|
* // Output: 190
|
|
4334
|
+
* ```
|
|
4186
4335
|
*
|
|
4187
4336
|
* @since 2.0.0
|
|
4188
4337
|
* @category sequencing
|
|
@@ -4263,6 +4412,7 @@ export const summarized = effect.summarized;
|
|
|
4263
4412
|
* will fail too.
|
|
4264
4413
|
*
|
|
4265
4414
|
* @example
|
|
4415
|
+
* ```ts
|
|
4266
4416
|
* // Title: Logging a step in a pipeline
|
|
4267
4417
|
* import { Console, Effect, pipe } from "effect"
|
|
4268
4418
|
*
|
|
@@ -4290,6 +4440,7 @@ export const summarized = effect.summarized;
|
|
|
4290
4440
|
* // Output:
|
|
4291
4441
|
* // Apply a discount to: 100
|
|
4292
4442
|
* // 95
|
|
4443
|
+
* ```
|
|
4293
4444
|
*
|
|
4294
4445
|
* @since 2.0.0
|
|
4295
4446
|
* @category sequencing
|
|
@@ -4307,6 +4458,7 @@ export const tap = core.tap;
|
|
|
4307
4458
|
* altering the result.
|
|
4308
4459
|
*
|
|
4309
4460
|
* @example
|
|
4461
|
+
* ```ts
|
|
4310
4462
|
* import { Effect, Random, Console } from "effect"
|
|
4311
4463
|
*
|
|
4312
4464
|
* // Simulate a task that might fail
|
|
@@ -4326,6 +4478,7 @@ export const tap = core.tap;
|
|
|
4326
4478
|
* Effect.runFork(tapping)
|
|
4327
4479
|
* // Example Output:
|
|
4328
4480
|
* // failure: random number is negative
|
|
4481
|
+
* ```
|
|
4329
4482
|
*
|
|
4330
4483
|
* @since 2.0.0
|
|
4331
4484
|
* @category sequencing
|
|
@@ -4342,6 +4495,7 @@ export const tapBoth = effect.tapBoth;
|
|
|
4342
4495
|
* severe errors.
|
|
4343
4496
|
*
|
|
4344
4497
|
* @example
|
|
4498
|
+
* ```ts
|
|
4345
4499
|
* import { Effect, Console } from "effect"
|
|
4346
4500
|
*
|
|
4347
4501
|
* // Simulate a task that fails with a recoverable error
|
|
@@ -4369,6 +4523,7 @@ export const tapBoth = effect.tapBoth;
|
|
|
4369
4523
|
* // Output:
|
|
4370
4524
|
* // defect: RuntimeException: Something went wrong
|
|
4371
4525
|
* // ... stack trace ...
|
|
4526
|
+
* ```
|
|
4372
4527
|
*
|
|
4373
4528
|
* @since 2.0.0
|
|
4374
4529
|
* @category sequencing
|
|
@@ -4384,6 +4539,7 @@ export const tapDefect = effect.tapDefect;
|
|
|
4384
4539
|
* while the operation you provide can inspect or act on it.
|
|
4385
4540
|
*
|
|
4386
4541
|
* @example
|
|
4542
|
+
* ```ts
|
|
4387
4543
|
* import { Effect, Console } from "effect"
|
|
4388
4544
|
*
|
|
4389
4545
|
* // Simulate a task that fails with an error
|
|
@@ -4397,6 +4553,7 @@ export const tapDefect = effect.tapDefect;
|
|
|
4397
4553
|
* Effect.runFork(tapping)
|
|
4398
4554
|
* // Output:
|
|
4399
4555
|
* // expected error: NetworkError
|
|
4556
|
+
* ```
|
|
4400
4557
|
*
|
|
4401
4558
|
* @since 2.0.0
|
|
4402
4559
|
* @category sequencing
|
|
@@ -4412,6 +4569,7 @@ export const tapError = effect.tapError;
|
|
|
4412
4569
|
* without modifying the error or the overall result of the effect.
|
|
4413
4570
|
*
|
|
4414
4571
|
* @example
|
|
4572
|
+
* ```ts
|
|
4415
4573
|
* import { Effect, Console } from "effect"
|
|
4416
4574
|
*
|
|
4417
4575
|
* class NetworkError {
|
|
@@ -4436,6 +4594,7 @@ export const tapError = effect.tapError;
|
|
|
4436
4594
|
* Effect.runFork(tapping)
|
|
4437
4595
|
* // Output:
|
|
4438
4596
|
* // expected error: 504
|
|
4597
|
+
* ```
|
|
4439
4598
|
*
|
|
4440
4599
|
* @since 2.0.0
|
|
4441
4600
|
* @category sequencing
|
|
@@ -4451,6 +4610,7 @@ export const tapErrorTag = effect.tapErrorTag;
|
|
|
4451
4610
|
* altering the error or the overall result of the effect.
|
|
4452
4611
|
*
|
|
4453
4612
|
* @example
|
|
4613
|
+
* ```ts
|
|
4454
4614
|
* import { Effect, Console } from "effect"
|
|
4455
4615
|
*
|
|
4456
4616
|
* // Create a task that fails with a NetworkError
|
|
@@ -4477,6 +4637,7 @@ export const tapErrorTag = effect.tapErrorTag;
|
|
|
4477
4637
|
* // Output:
|
|
4478
4638
|
* // error cause: RuntimeException: Something went wrong
|
|
4479
4639
|
* // ... stack trace ...
|
|
4640
|
+
* ```
|
|
4480
4641
|
*
|
|
4481
4642
|
* @since 2.0.0
|
|
4482
4643
|
* @category sequencing
|
|
@@ -4508,6 +4669,7 @@ export const forever = effect.forever;
|
|
|
4508
4669
|
* ```
|
|
4509
4670
|
*
|
|
4510
4671
|
* @example
|
|
4672
|
+
* ```ts
|
|
4511
4673
|
* // Title: Effectful Iteration
|
|
4512
4674
|
* import { Effect } from "effect"
|
|
4513
4675
|
*
|
|
@@ -4524,6 +4686,7 @@ export const forever = effect.forever;
|
|
|
4524
4686
|
*
|
|
4525
4687
|
* Effect.runPromise(result).then(console.log)
|
|
4526
4688
|
* // Output: 6
|
|
4689
|
+
* ```
|
|
4527
4690
|
*
|
|
4528
4691
|
* @since 2.0.0
|
|
4529
4692
|
* @category Looping
|
|
@@ -4556,6 +4719,7 @@ export const iterate = effect.iterate;
|
|
|
4556
4719
|
* discarded, and the final result will be `void`.
|
|
4557
4720
|
*
|
|
4558
4721
|
* @example
|
|
4722
|
+
* ```ts
|
|
4559
4723
|
* // Title: Looping with Collected Results
|
|
4560
4724
|
* import { Effect } from "effect"
|
|
4561
4725
|
*
|
|
@@ -4575,6 +4739,7 @@ export const iterate = effect.iterate;
|
|
|
4575
4739
|
*
|
|
4576
4740
|
* Effect.runPromise(result).then(console.log)
|
|
4577
4741
|
* // Output: [1, 2, 3, 4, 5]
|
|
4742
|
+
* ```
|
|
4578
4743
|
*
|
|
4579
4744
|
* @example
|
|
4580
4745
|
* // Title: Loop with Discarded Results
|
|
@@ -4616,6 +4781,7 @@ export const loop = effect.loop;
|
|
|
4616
4781
|
* an additional time.
|
|
4617
4782
|
*
|
|
4618
4783
|
* @example
|
|
4784
|
+
* ```ts
|
|
4619
4785
|
* // Success Example
|
|
4620
4786
|
* import { Effect, Schedule, Console } from "effect"
|
|
4621
4787
|
*
|
|
@@ -4624,6 +4790,7 @@ export const loop = effect.loop;
|
|
|
4624
4790
|
* const program = Effect.repeat(action, policy)
|
|
4625
4791
|
*
|
|
4626
4792
|
* Effect.runPromise(program).then((n) => console.log(`repetitions: ${n}`))
|
|
4793
|
+
* ```
|
|
4627
4794
|
*
|
|
4628
4795
|
* @example
|
|
4629
4796
|
* // Failure Example
|
|
@@ -4659,12 +4826,14 @@ export const repeat = _schedule.repeat_combined;
|
|
|
4659
4826
|
* initially and then repeats it one additional time if it succeeds.
|
|
4660
4827
|
*
|
|
4661
4828
|
* @example
|
|
4829
|
+
* ```ts
|
|
4662
4830
|
* import { Effect, Console } from "effect"
|
|
4663
4831
|
*
|
|
4664
4832
|
* const action = Console.log("success")
|
|
4665
4833
|
* const program = Effect.repeatN(action, 2)
|
|
4666
4834
|
*
|
|
4667
4835
|
* Effect.runPromise(program)
|
|
4836
|
+
* ```
|
|
4668
4837
|
*
|
|
4669
4838
|
* @since 2.0.0
|
|
4670
4839
|
* @category repetition / recursion
|
|
@@ -4679,6 +4848,7 @@ export const repeatN = effect.repeatN;
|
|
|
4679
4848
|
* initially and then repeats it an additional time if it succeeds.
|
|
4680
4849
|
*
|
|
4681
4850
|
* @example
|
|
4851
|
+
* ```ts
|
|
4682
4852
|
* import { Effect, Schedule } from "effect"
|
|
4683
4853
|
*
|
|
4684
4854
|
* let count = 0
|
|
@@ -4708,6 +4878,7 @@ export const repeatN = effect.repeatN;
|
|
|
4708
4878
|
* )
|
|
4709
4879
|
*
|
|
4710
4880
|
* Effect.runPromise(program).then((n) => console.log(`repetitions: ${n}`))
|
|
4881
|
+
* ```
|
|
4711
4882
|
*
|
|
4712
4883
|
* @since 2.0.0
|
|
4713
4884
|
* @category repetition / recursion
|
|
@@ -4830,6 +5001,7 @@ export const isSuccess = effect.isSuccess;
|
|
|
4830
5001
|
* @see {@link matchEffect} if you need to perform side effects in the handlers.
|
|
4831
5002
|
*
|
|
4832
5003
|
* @example
|
|
5004
|
+
* ```ts
|
|
4833
5005
|
* import { Effect } from "effect"
|
|
4834
5006
|
*
|
|
4835
5007
|
* const success: Effect.Effect<number, Error> = Effect.succeed(42)
|
|
@@ -4855,6 +5027,7 @@ export const isSuccess = effect.isSuccess;
|
|
|
4855
5027
|
* // Run and log the result of the failed effect
|
|
4856
5028
|
* Effect.runPromise(program2).then(console.log)
|
|
4857
5029
|
* // Output: "failure: Uh oh!"
|
|
5030
|
+
* ```
|
|
4858
5031
|
*
|
|
4859
5032
|
* @since 2.0.0
|
|
4860
5033
|
* @category getters & folding
|
|
@@ -4890,6 +5063,7 @@ export const matchCause = core.matchCause;
|
|
|
4890
5063
|
* @see {@link matchEffect} if you don't need to handle the cause of the failure.
|
|
4891
5064
|
*
|
|
4892
5065
|
* @example
|
|
5066
|
+
* ```ts
|
|
4893
5067
|
* import { Effect, Console } from "effect"
|
|
4894
5068
|
*
|
|
4895
5069
|
* const task: Effect.Effect<number, Error> = Effect.die("Uh oh!")
|
|
@@ -4917,6 +5091,7 @@ export const matchCause = core.matchCause;
|
|
|
4917
5091
|
*
|
|
4918
5092
|
* Effect.runSync(program)
|
|
4919
5093
|
* // Output: "Die: Uh oh!"
|
|
5094
|
+
* ```
|
|
4920
5095
|
*
|
|
4921
5096
|
* @since 2.0.0
|
|
4922
5097
|
* @category getters & folding
|
|
@@ -4945,6 +5120,7 @@ export const matchEffect = core.matchEffect;
|
|
|
4945
5120
|
* To adjust the log level, use the `Logger.withMinimumLogLevel` function.
|
|
4946
5121
|
*
|
|
4947
5122
|
* @example
|
|
5123
|
+
* ```ts
|
|
4948
5124
|
* import { Cause, Effect } from "effect"
|
|
4949
5125
|
*
|
|
4950
5126
|
* const program = Effect.log(
|
|
@@ -4958,6 +5134,7 @@ export const matchEffect = core.matchEffect;
|
|
|
4958
5134
|
* // Output:
|
|
4959
5135
|
* // timestamp=... level=INFO fiber=#0 message=message1 message=message2 cause="Error: Oh no!
|
|
4960
5136
|
* // Error: Oh uh!"
|
|
5137
|
+
* ```
|
|
4961
5138
|
*
|
|
4962
5139
|
* @since 2.0.0
|
|
4963
5140
|
* @category Logging
|
|
@@ -4985,12 +5162,14 @@ export const logTrace = effect.logTrace;
|
|
|
4985
5162
|
* `Logger.withMinimumLogLevel` and set the log level to `LogLevel.Debug`.
|
|
4986
5163
|
*
|
|
4987
5164
|
* @example
|
|
5165
|
+
* ```ts
|
|
4988
5166
|
* import { Effect, Logger, LogLevel } from "effect"
|
|
4989
5167
|
*
|
|
4990
5168
|
* const program = Effect.logDebug("message1").pipe(Logger.withMinimumLogLevel(LogLevel.Debug))
|
|
4991
5169
|
*
|
|
4992
5170
|
* // Effect.runFork(program)
|
|
4993
5171
|
* // timestamp=... level=DEBUG fiber=#0 message=message1
|
|
5172
|
+
* ```
|
|
4994
5173
|
*
|
|
4995
5174
|
* @since 2.0.0
|
|
4996
5175
|
* @category Logging
|
|
@@ -5030,6 +5209,7 @@ export const logFatal = effect.logFatal;
|
|
|
5030
5209
|
* time-sensitive processes.
|
|
5031
5210
|
*
|
|
5032
5211
|
* @example
|
|
5212
|
+
* ```ts
|
|
5033
5213
|
* import { Effect } from "effect"
|
|
5034
5214
|
*
|
|
5035
5215
|
* const program = Effect.gen(function*() {
|
|
@@ -5039,6 +5219,7 @@ export const logFatal = effect.logFatal;
|
|
|
5039
5219
|
*
|
|
5040
5220
|
* // Effect.runFork(program)
|
|
5041
5221
|
* // timestamp=... level=INFO fiber=#0 message="The job is finished!" myspan=1011ms
|
|
5222
|
+
* ```
|
|
5042
5223
|
*
|
|
5043
5224
|
* @since 2.0.0
|
|
5044
5225
|
* @category Logging
|
|
@@ -5050,6 +5231,7 @@ export const withLogSpan = effect.withLogSpan;
|
|
|
5050
5231
|
* to log messages, making them more informative and easier to trace.
|
|
5051
5232
|
*
|
|
5052
5233
|
* @example
|
|
5234
|
+
* ```ts
|
|
5053
5235
|
* import { Effect } from "effect"
|
|
5054
5236
|
*
|
|
5055
5237
|
* const program = Effect.gen(function*() {
|
|
@@ -5060,6 +5242,7 @@ export const withLogSpan = effect.withLogSpan;
|
|
|
5060
5242
|
* // Effect.runFork(program)
|
|
5061
5243
|
* // timestamp=... level=INFO fiber=#0 message=message1 key=value
|
|
5062
5244
|
* // timestamp=... level=INFO fiber=#0 message=message2 key=value
|
|
5245
|
+
* ```
|
|
5063
5246
|
*
|
|
5064
5247
|
* @since 2.0.0
|
|
5065
5248
|
* @category Logging
|
|
@@ -5072,6 +5255,7 @@ export const annotateLogs = effect.annotateLogs;
|
|
|
5072
5255
|
* defined `Scope`, making it easier to manage context-specific logging.
|
|
5073
5256
|
*
|
|
5074
5257
|
* @example
|
|
5258
|
+
* ```ts
|
|
5075
5259
|
* import { Effect } from "effect"
|
|
5076
5260
|
*
|
|
5077
5261
|
* const program = Effect.gen(function*() {
|
|
@@ -5086,6 +5270,7 @@ export const annotateLogs = effect.annotateLogs;
|
|
|
5086
5270
|
* // timestamp=... level=INFO fiber=#0 message=message1 key=value
|
|
5087
5271
|
* // timestamp=... level=INFO fiber=#0 message=message2 key=value
|
|
5088
5272
|
* // timestamp=... level=INFO fiber=#0 message="no annotations again"
|
|
5273
|
+
* ```
|
|
5089
5274
|
*
|
|
5090
5275
|
* @since 3.1.0
|
|
5091
5276
|
* @category Logging
|
|
@@ -5121,6 +5306,7 @@ export const withUnhandledErrorLogLevel = core.withUnhandledErrorLogLevel;
|
|
|
5121
5306
|
* @see {@link orDieWith} if you need to customize the error.
|
|
5122
5307
|
*
|
|
5123
5308
|
* @example
|
|
5309
|
+
* ```ts
|
|
5124
5310
|
* // Title: Propagating an Error as a Defect
|
|
5125
5311
|
* import { Effect } from "effect"
|
|
5126
5312
|
*
|
|
@@ -5137,6 +5323,7 @@ export const withUnhandledErrorLogLevel = core.withUnhandledErrorLogLevel;
|
|
|
5137
5323
|
* // Output:
|
|
5138
5324
|
* // (FiberFailure) Error: Cannot divide by zero
|
|
5139
5325
|
* // ...stack trace...
|
|
5326
|
+
* ```
|
|
5140
5327
|
*
|
|
5141
5328
|
* @since 2.0.0
|
|
5142
5329
|
* @category Converting Failures to Defects
|
|
@@ -5160,6 +5347,7 @@ export const orDie = core.orDie;
|
|
|
5160
5347
|
* @see {@link orDie} if you don't need to customize the error.
|
|
5161
5348
|
*
|
|
5162
5349
|
* @example
|
|
5350
|
+
* ```ts
|
|
5163
5351
|
* // Title: Customizing Defect
|
|
5164
5352
|
* import { Effect } from "effect"
|
|
5165
5353
|
*
|
|
@@ -5179,6 +5367,7 @@ export const orDie = core.orDie;
|
|
|
5179
5367
|
* // Output:
|
|
5180
5368
|
* // (FiberFailure) Error: defect: Cannot divide by zero
|
|
5181
5369
|
* // ...stack trace...
|
|
5370
|
+
* ```
|
|
5182
5371
|
*
|
|
5183
5372
|
* @since 2.0.0
|
|
5184
5373
|
* @category Converting Failures to Defects
|
|
@@ -5195,6 +5384,7 @@ export const orDieWith = core.orDieWith;
|
|
|
5195
5384
|
* @see {@link catchAll} if you need to access the error in the fallback effect.
|
|
5196
5385
|
*
|
|
5197
5386
|
* @example
|
|
5387
|
+
* ```ts
|
|
5198
5388
|
* import { Effect } from "effect"
|
|
5199
5389
|
*
|
|
5200
5390
|
* const success = Effect.succeed("success")
|
|
@@ -5210,6 +5400,7 @@ export const orDieWith = core.orDieWith;
|
|
|
5210
5400
|
* const program2 = Effect.orElse(failure, () => fallback)
|
|
5211
5401
|
* console.log(Effect.runSync(program2))
|
|
5212
5402
|
* // Output: "fallback"
|
|
5403
|
+
* ```
|
|
5213
5404
|
*
|
|
5214
5405
|
* @since 2.0.0
|
|
5215
5406
|
* @category Fallback
|
|
@@ -5228,6 +5419,7 @@ export const orElse = core.orElse;
|
|
|
5228
5419
|
* @see {@link mapError} if you need to access the error to transform it.
|
|
5229
5420
|
*
|
|
5230
5421
|
* @example
|
|
5422
|
+
* ```ts
|
|
5231
5423
|
* import { Effect } from "effect"
|
|
5232
5424
|
*
|
|
5233
5425
|
* const validate = (age: number): Effect.Effect<number, string> => {
|
|
@@ -5249,6 +5441,7 @@ export const orElse = core.orElse;
|
|
|
5249
5441
|
* // _tag: 'Failure',
|
|
5250
5442
|
* // cause: { _id: 'Cause', _tag: 'Fail', failure: 'invalid age' }
|
|
5251
5443
|
* // }
|
|
5444
|
+
* ```
|
|
5252
5445
|
*
|
|
5253
5446
|
* @since 2.0.0
|
|
5254
5447
|
* @category Fallback
|
|
@@ -5272,6 +5465,7 @@ export const orElseFail = effect.orElseFail;
|
|
|
5272
5465
|
* already succeeds, it will remain unchanged.
|
|
5273
5466
|
*
|
|
5274
5467
|
* @example
|
|
5468
|
+
* ```ts
|
|
5275
5469
|
* import { Effect } from "effect"
|
|
5276
5470
|
*
|
|
5277
5471
|
* const validate = (age: number): Effect.Effect<number, string> => {
|
|
@@ -5289,6 +5483,7 @@ export const orElseFail = effect.orElseFail;
|
|
|
5289
5483
|
* console.log(Effect.runSyncExit(program))
|
|
5290
5484
|
* // Output:
|
|
5291
5485
|
* // { _id: 'Exit', _tag: 'Success', value: 18 }
|
|
5486
|
+
* ```
|
|
5292
5487
|
*
|
|
5293
5488
|
* @since 2.0.0
|
|
5294
5489
|
* @category Fallback
|
|
@@ -5312,6 +5507,7 @@ export const orElseSucceed = effect.orElseSucceed;
|
|
|
5312
5507
|
* error.
|
|
5313
5508
|
*
|
|
5314
5509
|
* @example
|
|
5510
|
+
* ```ts
|
|
5315
5511
|
* import { Effect, Console } from "effect"
|
|
5316
5512
|
*
|
|
5317
5513
|
* interface Config {
|
|
@@ -5358,6 +5554,7 @@ export const orElseSucceed = effect.orElseSucceed;
|
|
|
5358
5554
|
* // Unavailable config for node2
|
|
5359
5555
|
* // Config for node3 found
|
|
5360
5556
|
* // { host: 'node3.example.com', port: 8080, apiKey: '12345-abcde' }
|
|
5557
|
+
* ```
|
|
5361
5558
|
*
|
|
5362
5559
|
* @since 2.0.0
|
|
5363
5560
|
* @category Fallback
|
|
@@ -5489,6 +5686,7 @@ export const unsafeMakeLatch = circular.unsafeMakeLatch;
|
|
|
5489
5686
|
* @category latch
|
|
5490
5687
|
* @since 3.8.0
|
|
5491
5688
|
* @example
|
|
5689
|
+
* ```ts
|
|
5492
5690
|
* import { Effect } from "effect"
|
|
5493
5691
|
*
|
|
5494
5692
|
* Effect.gen(function*() {
|
|
@@ -5505,6 +5703,7 @@ export const unsafeMakeLatch = circular.unsafeMakeLatch;
|
|
|
5505
5703
|
* yield* latch.open
|
|
5506
5704
|
* yield* fiber.await
|
|
5507
5705
|
* })
|
|
5706
|
+
* ```
|
|
5508
5707
|
*/
|
|
5509
5708
|
export const makeLatch = circular.makeLatch;
|
|
5510
5709
|
/**
|
|
@@ -5521,6 +5720,7 @@ export const makeLatch = circular.makeLatch;
|
|
|
5521
5720
|
* `runFork` is a good default choice.
|
|
5522
5721
|
*
|
|
5523
5722
|
* @example
|
|
5723
|
+
* ```ts
|
|
5524
5724
|
* // Title: Running an Effect in the Background
|
|
5525
5725
|
* import { Effect, Console, Schedule, Fiber } from "effect"
|
|
5526
5726
|
*
|
|
@@ -5538,6 +5738,7 @@ export const makeLatch = circular.makeLatch;
|
|
|
5538
5738
|
* setTimeout(() => {
|
|
5539
5739
|
* Effect.runFork(Fiber.interrupt(fiber))
|
|
5540
5740
|
* }, 500)
|
|
5741
|
+
* ```
|
|
5541
5742
|
*
|
|
5542
5743
|
* @since 2.0.0
|
|
5543
5744
|
* @category Running Effects
|
|
@@ -5563,11 +5764,13 @@ export const runCallback = _runtime.unsafeRunEffect;
|
|
|
5563
5764
|
* @see {@link runPromiseExit} for a version that returns an `Exit` type instead of rejecting.
|
|
5564
5765
|
*
|
|
5565
5766
|
* @example
|
|
5767
|
+
* ```ts
|
|
5566
5768
|
* // Title: Running a Successful Effect as a Promise
|
|
5567
5769
|
* import { Effect } from "effect"
|
|
5568
5770
|
*
|
|
5569
5771
|
* Effect.runPromise(Effect.succeed(1)).then(console.log)
|
|
5570
5772
|
* // Output: 1
|
|
5773
|
+
* ```
|
|
5571
5774
|
*
|
|
5572
5775
|
* @example
|
|
5573
5776
|
* //Example: Handling a Failing Effect as a Rejected Promise
|
|
@@ -5598,6 +5801,7 @@ export const runPromise = _runtime.unsafeRunPromiseEffect;
|
|
|
5598
5801
|
* a `Cause` type.
|
|
5599
5802
|
*
|
|
5600
5803
|
* @example
|
|
5804
|
+
* ```ts
|
|
5601
5805
|
* // Title: Handling Results as Exit
|
|
5602
5806
|
* import { Effect } from "effect"
|
|
5603
5807
|
*
|
|
@@ -5622,6 +5826,7 @@ export const runPromise = _runtime.unsafeRunPromiseEffect;
|
|
|
5622
5826
|
* // failure: "my error"
|
|
5623
5827
|
* // }
|
|
5624
5828
|
* // }
|
|
5829
|
+
* ```
|
|
5625
5830
|
*
|
|
5626
5831
|
* @since 2.0.0
|
|
5627
5832
|
* @category Running Effects
|
|
@@ -5643,6 +5848,7 @@ export const runPromiseExit = _runtime.unsafeRunPromiseExitEffect;
|
|
|
5643
5848
|
* throwing an error.
|
|
5644
5849
|
*
|
|
5645
5850
|
* @example
|
|
5851
|
+
* ```ts
|
|
5646
5852
|
* // Title: Synchronous Logging
|
|
5647
5853
|
* import { Effect } from "effect"
|
|
5648
5854
|
*
|
|
@@ -5656,6 +5862,7 @@ export const runPromiseExit = _runtime.unsafeRunPromiseExitEffect;
|
|
|
5656
5862
|
*
|
|
5657
5863
|
* console.log(result)
|
|
5658
5864
|
* // Output: 1
|
|
5865
|
+
* ```
|
|
5659
5866
|
*
|
|
5660
5867
|
* @example
|
|
5661
5868
|
* // Title: Incorrect Usage with Failing or Async Effects
|
|
@@ -5704,6 +5911,7 @@ export const runSync = _runtime.unsafeRunSyncEffect;
|
|
|
5704
5911
|
* resolved synchronously.
|
|
5705
5912
|
*
|
|
5706
5913
|
* @example
|
|
5914
|
+
* ```ts
|
|
5707
5915
|
* // Title: Handling Results as Exit
|
|
5708
5916
|
* import { Effect } from "effect"
|
|
5709
5917
|
*
|
|
@@ -5726,6 +5934,7 @@ export const runSync = _runtime.unsafeRunSyncEffect;
|
|
|
5726
5934
|
* // failure: "my error"
|
|
5727
5935
|
* // }
|
|
5728
5936
|
* // }
|
|
5937
|
+
* ```
|
|
5729
5938
|
*
|
|
5730
5939
|
* @example
|
|
5731
5940
|
* // Title: Asynchronous Operation Resulting in Die
|
|
@@ -5766,6 +5975,7 @@ export const runSyncExit = _runtime.unsafeRunSyncExitEffect;
|
|
|
5766
5975
|
* @see {@link zip} for a version that stops at the first error.
|
|
5767
5976
|
*
|
|
5768
5977
|
* @example
|
|
5978
|
+
* ```ts
|
|
5769
5979
|
* import { Effect, Console } from "effect"
|
|
5770
5980
|
*
|
|
5771
5981
|
* const task1 = Console.log("task1").pipe(Effect.as(1))
|
|
@@ -5793,6 +6003,7 @@ export const runSyncExit = _runtime.unsafeRunSyncExitEffect;
|
|
|
5793
6003
|
* // right: { _id: 'Cause', _tag: 'Fail', failure: 'Oh no!' }
|
|
5794
6004
|
* // }
|
|
5795
6005
|
* // }
|
|
6006
|
+
* ```
|
|
5796
6007
|
*
|
|
5797
6008
|
* @since 2.0.0
|
|
5798
6009
|
* @category Error Accumulation
|
|
@@ -5821,6 +6032,7 @@ export const validateWith = fiberRuntime.validateWith;
|
|
|
5821
6032
|
* @see {@link validate} for a version that accumulates errors.
|
|
5822
6033
|
*
|
|
5823
6034
|
* @example
|
|
6035
|
+
* ```ts
|
|
5824
6036
|
* // Title: Combining Two Effects Sequentially
|
|
5825
6037
|
* import { Effect } from "effect"
|
|
5826
6038
|
*
|
|
@@ -5844,6 +6056,7 @@ export const validateWith = fiberRuntime.validateWith;
|
|
|
5844
6056
|
* // timestamp=... level=INFO fiber=#0 message="task1 done"
|
|
5845
6057
|
* // timestamp=... level=INFO fiber=#0 message="task2 done"
|
|
5846
6058
|
* // [ 1, 'hello' ]
|
|
6059
|
+
* ```
|
|
5847
6060
|
*
|
|
5848
6061
|
* @example
|
|
5849
6062
|
* // Title: Combining Two Effects Concurrently
|
|
@@ -5889,6 +6102,7 @@ export const zip = fiberRuntime.zipOptions;
|
|
|
5889
6102
|
* @see {@link zipRight} for a version that returns the result of the second effect.
|
|
5890
6103
|
*
|
|
5891
6104
|
* @example
|
|
6105
|
+
* ```ts
|
|
5892
6106
|
* import { Effect } from "effect"
|
|
5893
6107
|
*
|
|
5894
6108
|
* const task1 = Effect.succeed(1).pipe(
|
|
@@ -5907,6 +6121,7 @@ export const zip = fiberRuntime.zipOptions;
|
|
|
5907
6121
|
* // timestamp=... level=INFO fiber=#0 message="task1 done"
|
|
5908
6122
|
* // timestamp=... level=INFO fiber=#0 message="task2 done"
|
|
5909
6123
|
* // 1
|
|
6124
|
+
* ```
|
|
5910
6125
|
*
|
|
5911
6126
|
* @since 2.0.0
|
|
5912
6127
|
* @category Zipping
|
|
@@ -5930,6 +6145,7 @@ export const zipLeft = fiberRuntime.zipLeftOptions;
|
|
|
5930
6145
|
* @see {@link zipLeft} for a version that returns the result of the first effect.
|
|
5931
6146
|
*
|
|
5932
6147
|
* @example
|
|
6148
|
+
* ```ts
|
|
5933
6149
|
* import { Effect } from "effect"
|
|
5934
6150
|
*
|
|
5935
6151
|
* const task1 = Effect.succeed(1).pipe(
|
|
@@ -5948,6 +6164,7 @@ export const zipLeft = fiberRuntime.zipLeftOptions;
|
|
|
5948
6164
|
* // timestamp=... level=INFO fiber=#0 message="task1 done"
|
|
5949
6165
|
* // timestamp=... level=INFO fiber=#0 message="task2 done"
|
|
5950
6166
|
* // hello
|
|
6167
|
+
* ```
|
|
5951
6168
|
*
|
|
5952
6169
|
* @since 2.0.0
|
|
5953
6170
|
* @category Zipping
|
|
@@ -5969,6 +6186,7 @@ export const zipRight = fiberRuntime.zipRightOptions;
|
|
|
5969
6186
|
* use the `{ concurrent: true }` option.
|
|
5970
6187
|
*
|
|
5971
6188
|
* @example
|
|
6189
|
+
* ```ts
|
|
5972
6190
|
* // Title: Combining Effects with a Custom Function
|
|
5973
6191
|
* import { Effect } from "effect"
|
|
5974
6192
|
*
|
|
@@ -5993,6 +6211,7 @@ export const zipRight = fiberRuntime.zipRightOptions;
|
|
|
5993
6211
|
* // timestamp=... level=INFO fiber=#3 message="task1 done"
|
|
5994
6212
|
* // timestamp=... level=INFO fiber=#2 message="task2 done"
|
|
5995
6213
|
* // 6
|
|
6214
|
+
* ```
|
|
5996
6215
|
*
|
|
5997
6216
|
* @since 2.0.0
|
|
5998
6217
|
* @category Zipping
|
|
@@ -6069,6 +6288,7 @@ export const withTracerScoped = fiberRuntime.withTracerScoped;
|
|
|
6069
6288
|
* @since 2.0.0
|
|
6070
6289
|
* @category Tracing
|
|
6071
6290
|
* @example
|
|
6291
|
+
* ```ts
|
|
6072
6292
|
* import { Effect } from "effect"
|
|
6073
6293
|
*
|
|
6074
6294
|
* Effect.succeed(42).pipe(
|
|
@@ -6076,6 +6296,7 @@ export const withTracerScoped = fiberRuntime.withTracerScoped;
|
|
|
6076
6296
|
* // the span will not be registered with the tracer
|
|
6077
6297
|
* Effect.withTracerEnabled(false)
|
|
6078
6298
|
* )
|
|
6299
|
+
* ```
|
|
6079
6300
|
*/
|
|
6080
6301
|
export const withTracerEnabled = core.withTracerEnabled;
|
|
6081
6302
|
/**
|
|
@@ -6166,6 +6387,7 @@ export const withSpan = effect.withSpan;
|
|
|
6166
6387
|
* @since 3.2.0
|
|
6167
6388
|
* @category Tracing
|
|
6168
6389
|
* @example
|
|
6390
|
+
* ```ts
|
|
6169
6391
|
* import { Effect } from "effect"
|
|
6170
6392
|
*
|
|
6171
6393
|
* const getTodo = Effect.functionWithSpan({
|
|
@@ -6175,6 +6397,7 @@ export const withSpan = effect.withSpan;
|
|
|
6175
6397
|
* attributes: { id }
|
|
6176
6398
|
* })
|
|
6177
6399
|
* })
|
|
6400
|
+
* ```
|
|
6178
6401
|
*/
|
|
6179
6402
|
export const functionWithSpan = effect.functionWithSpan;
|
|
6180
6403
|
/**
|
|
@@ -6205,6 +6428,7 @@ export const withParentSpan = effect.withParentSpan;
|
|
|
6205
6428
|
* value.
|
|
6206
6429
|
*
|
|
6207
6430
|
* @example
|
|
6431
|
+
* ```ts
|
|
6208
6432
|
* import { Effect } from "effect"
|
|
6209
6433
|
*
|
|
6210
6434
|
* // ┌─── Effect<number, NoSuchElementException, never>
|
|
@@ -6230,6 +6454,7 @@ export const withParentSpan = effect.withParentSpan;
|
|
|
6230
6454
|
* // failure: { _tag: 'NoSuchElementException' }
|
|
6231
6455
|
* // }
|
|
6232
6456
|
* // }
|
|
6457
|
+
* ```
|
|
6233
6458
|
*
|
|
6234
6459
|
* @since 2.0.0
|
|
6235
6460
|
* @category Optional Wrapping
|
|
@@ -6247,6 +6472,7 @@ export const fromNullable = effect.fromNullable;
|
|
|
6247
6472
|
* unchanged.
|
|
6248
6473
|
*
|
|
6249
6474
|
* @example
|
|
6475
|
+
* ```ts
|
|
6250
6476
|
* import { Effect } from "effect"
|
|
6251
6477
|
*
|
|
6252
6478
|
* // ┌─── Effect<number, NoSuchElementException, never>
|
|
@@ -6270,6 +6496,7 @@ export const fromNullable = effect.fromNullable;
|
|
|
6270
6496
|
*
|
|
6271
6497
|
* Effect.runPromise(option2).then(console.log)
|
|
6272
6498
|
* // Output: { _tag: 'None' }
|
|
6499
|
+
* ```
|
|
6273
6500
|
*
|
|
6274
6501
|
* @since 2.0.0
|
|
6275
6502
|
* @category Optional Wrapping
|
|
@@ -6303,6 +6530,7 @@ const makeTagProxy = TagClass => {
|
|
|
6303
6530
|
};
|
|
6304
6531
|
/**
|
|
6305
6532
|
* @example
|
|
6533
|
+
* ```ts
|
|
6306
6534
|
* import { Effect, Layer } from "effect"
|
|
6307
6535
|
*
|
|
6308
6536
|
* class MapTag extends Effect.Tag("MapTag")<MapTag, Map<string, string>>() {
|
|
@@ -6311,6 +6539,7 @@ const makeTagProxy = TagClass => {
|
|
|
6311
6539
|
* Effect.sync(() => new Map())
|
|
6312
6540
|
* )
|
|
6313
6541
|
* }
|
|
6542
|
+
* ```
|
|
6314
6543
|
*
|
|
6315
6544
|
* @since 2.0.0
|
|
6316
6545
|
* @category Context
|
|
@@ -6337,6 +6566,7 @@ export const Tag = id => () => {
|
|
|
6337
6566
|
};
|
|
6338
6567
|
/**
|
|
6339
6568
|
* @example
|
|
6569
|
+
* ```ts
|
|
6340
6570
|
* import { Effect } from 'effect';
|
|
6341
6571
|
*
|
|
6342
6572
|
* class Prefix extends Effect.Service<Prefix>()("Prefix", {
|
|
@@ -6356,6 +6586,7 @@ export const Tag = id => () => {
|
|
|
6356
6586
|
* }),
|
|
6357
6587
|
* dependencies: [Prefix.Default]
|
|
6358
6588
|
* }) {}
|
|
6589
|
+
* ```
|
|
6359
6590
|
*
|
|
6360
6591
|
* @since 3.9.0
|
|
6361
6592
|
* @category Context
|
|
@@ -6445,4 +6676,70 @@ export const Service = function () {
|
|
|
6445
6676
|
return proxy === true ? makeTagProxy(TagClass) : TagClass;
|
|
6446
6677
|
};
|
|
6447
6678
|
};
|
|
6679
|
+
/**
|
|
6680
|
+
* Creates a function that returns an Effect which is automatically traced with a span pointing to the call site.
|
|
6681
|
+
*
|
|
6682
|
+
* The function can be created both using a generator function that can yield effects or using a normal function.
|
|
6683
|
+
*
|
|
6684
|
+
* @since 3.11.0
|
|
6685
|
+
* @category function
|
|
6686
|
+
*
|
|
6687
|
+
* @example
|
|
6688
|
+
* import { Effect } from "effect"
|
|
6689
|
+
*
|
|
6690
|
+
* const logExample = Effect.fn("logExample")(
|
|
6691
|
+
* function*<N extends number>(n: N) {
|
|
6692
|
+
* yield* Effect.annotateCurrentSpan("n", n)
|
|
6693
|
+
* yield* Effect.logInfo(`got: ${n}`)
|
|
6694
|
+
* yield* Effect.fail(new Error())
|
|
6695
|
+
* },
|
|
6696
|
+
* Effect.delay("1 second")
|
|
6697
|
+
* )
|
|
6698
|
+
*
|
|
6699
|
+
* Effect.runFork(
|
|
6700
|
+
* // this location is printed on the stack trace of the following `Effect.logError`
|
|
6701
|
+
* logExample(100).pipe(
|
|
6702
|
+
* Effect.catchAllCause(Effect.logError)
|
|
6703
|
+
* )
|
|
6704
|
+
* )
|
|
6705
|
+
*/
|
|
6706
|
+
export const fn = (name, options) => (body, ...pipeables) => {
|
|
6707
|
+
return function (...args) {
|
|
6708
|
+
const limit = Error.stackTraceLimit;
|
|
6709
|
+
Error.stackTraceLimit = 2;
|
|
6710
|
+
const error = new Error();
|
|
6711
|
+
Error.stackTraceLimit = limit;
|
|
6712
|
+
let cache = false;
|
|
6713
|
+
const captureStackTrace = () => {
|
|
6714
|
+
if (cache !== false) {
|
|
6715
|
+
return cache;
|
|
6716
|
+
}
|
|
6717
|
+
if (error.stack) {
|
|
6718
|
+
const stack = error.stack.trim().split("\n");
|
|
6719
|
+
cache = stack.slice(2).join("\n").trim();
|
|
6720
|
+
return cache;
|
|
6721
|
+
}
|
|
6722
|
+
};
|
|
6723
|
+
let effect;
|
|
6724
|
+
let fnError = undefined;
|
|
6725
|
+
try {
|
|
6726
|
+
effect = isGeneratorFunction(body) ? gen(() => internalCall(() => body.apply(this, args))) : body.apply(this, args);
|
|
6727
|
+
} catch (error) {
|
|
6728
|
+
fnError = error;
|
|
6729
|
+
effect = die(error);
|
|
6730
|
+
}
|
|
6731
|
+
try {
|
|
6732
|
+
for (const x of pipeables) {
|
|
6733
|
+
effect = x(effect);
|
|
6734
|
+
}
|
|
6735
|
+
} catch (error) {
|
|
6736
|
+
effect = fnError ? failCause(internalCause.sequential(internalCause.die(fnError), internalCause.die(error))) : die(error);
|
|
6737
|
+
}
|
|
6738
|
+
const opts = options && "captureStackTrace" in options ? options : {
|
|
6739
|
+
captureStackTrace,
|
|
6740
|
+
...options
|
|
6741
|
+
};
|
|
6742
|
+
return withSpan(effect, name, opts);
|
|
6743
|
+
};
|
|
6744
|
+
};
|
|
6448
6745
|
//# sourceMappingURL=Effect.js.map
|