effect 4.0.0-beta.26 → 4.0.0-beta.28
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/Cause.d.ts +1 -1
- package/dist/ConfigProvider.d.ts +1 -1
- package/dist/Cron.d.ts +1 -1
- package/dist/Data.d.ts +3 -3
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js +2 -2
- package/dist/Data.js.map +1 -1
- package/dist/Effect.d.ts +331 -206
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +113 -72
- package/dist/Effect.js.map +1 -1
- package/dist/Encoding.d.ts +1 -1
- package/dist/ErrorReporter.d.ts +2 -4
- package/dist/ErrorReporter.d.ts.map +1 -1
- package/dist/ErrorReporter.js +1 -3
- package/dist/ErrorReporter.js.map +1 -1
- package/dist/Exit.d.ts +24 -12
- package/dist/Exit.d.ts.map +1 -1
- package/dist/Exit.js +8 -4
- package/dist/Exit.js.map +1 -1
- package/dist/Fiber.d.ts +1 -0
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/Graph.d.ts +1 -1
- package/dist/Layer.d.ts +112 -117
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +43 -44
- package/dist/Layer.js.map +1 -1
- package/dist/LayerMap.d.ts +4 -4
- package/dist/LayerMap.js +3 -3
- package/dist/ManagedRuntime.d.ts +1 -1
- package/dist/ManagedRuntime.js +1 -1
- package/dist/Metric.d.ts +2 -4
- package/dist/Metric.d.ts.map +1 -1
- package/dist/Metric.js +2 -4
- package/dist/Metric.js.map +1 -1
- package/dist/PlatformError.d.ts +2 -2
- package/dist/References.d.ts +6 -1
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +6 -1
- package/dist/References.js.map +1 -1
- package/dist/RequestResolver.d.ts +19 -19
- package/dist/RequestResolver.js +10 -10
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Schedule.d.ts +144 -82
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +58 -32
- package/dist/Schedule.js.map +1 -1
- package/dist/Scheduler.d.ts +9 -0
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +11 -0
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +3 -1
- package/dist/Schema.js.map +1 -1
- package/dist/Stdio.d.ts +6 -2
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +2 -2
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +8 -4
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +8 -4
- package/dist/Stream.js.map +1 -1
- package/dist/Types.d.ts +1 -22
- package/dist/Types.d.ts.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +3 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +12 -28
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +4 -18
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +20 -1
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +8 -0
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +65 -12
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +159 -45
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +1 -1
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +4 -11
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/ai/internal/codec-transformer.js +0 -5
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/cli/CliError.d.ts +4 -4
- package/dist/unstable/cli/CliError.js +4 -4
- package/dist/unstable/cli/Primitive.d.ts +1 -1
- package/dist/unstable/cli/Primitive.js +1 -1
- package/dist/unstable/cli/Prompt.js +31 -0
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +5 -5
- package/dist/unstable/cluster/Reply.d.ts +3 -3
- package/dist/unstable/encoding/Msgpack.d.ts +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +1 -1
- package/dist/unstable/encoding/Sse.d.ts +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
- package/dist/unstable/http/Cookies.d.ts +45 -1
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +22 -0
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/Headers.d.ts +16 -0
- package/dist/unstable/http/Headers.d.ts.map +1 -1
- package/dist/unstable/http/Headers.js +11 -0
- package/dist/unstable/http/Headers.js.map +1 -1
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpClientError.d.ts +7 -7
- package/dist/unstable/http/HttpClientRequest.d.ts +5 -0
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +21 -17
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +7 -0
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +6 -0
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +6 -6
- package/dist/unstable/http/HttpServerRequest.d.ts +11 -0
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +291 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +47 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +227 -0
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
- package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
- package/dist/unstable/http/HttpStaticServer.js +353 -0
- package/dist/unstable/http/HttpStaticServer.js.map +1 -0
- package/dist/unstable/http/Multipart.d.ts +1 -1
- package/dist/unstable/http/UrlParams.d.ts +1 -1
- package/dist/unstable/http/index.d.ts +4 -0
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +4 -0
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +5 -0
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +1 -0
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +4 -10
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +4 -6
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +39 -9
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +8 -8
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +46 -20
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +5 -5
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +2 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/Utils.js +1 -1
- package/dist/unstable/rpc/Utils.js.map +1 -1
- package/dist/unstable/schema/Model.d.ts +21 -0
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/Model.js +15 -0
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/socket/SocketServer.d.ts +3 -3
- package/dist/unstable/sql/Migrator.d.ts +1 -1
- package/dist/unstable/sql/SqlResolver.js +2 -2
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +1 -1
- package/package.json +1 -1
- package/src/Cause.ts +1 -1
- package/src/Data.ts +3 -4
- package/src/Effect.ts +331 -206
- package/src/ErrorReporter.ts +2 -4
- package/src/Exit.ts +24 -12
- package/src/Fiber.ts +1 -0
- package/src/Layer.ts +112 -117
- package/src/LayerMap.ts +4 -4
- package/src/ManagedRuntime.ts +1 -1
- package/src/Metric.ts +2 -4
- package/src/References.ts +6 -1
- package/src/RequestResolver.ts +20 -20
- package/src/Schedule.ts +144 -82
- package/src/Scheduler.ts +12 -0
- package/src/Schema.ts +3 -1
- package/src/Stdio.ts +8 -4
- package/src/Stream.ts +8 -4
- package/src/Types.ts +1 -23
- package/src/index.ts +5 -3
- package/src/internal/effect.ts +3 -0
- package/src/unstable/ai/LanguageModel.ts +16 -37
- package/src/unstable/ai/McpSchema.ts +14 -0
- package/src/unstable/ai/McpServer.ts +224 -53
- package/src/unstable/ai/Toolkit.ts +5 -14
- package/src/unstable/ai/internal/codec-transformer.ts +0 -7
- package/src/unstable/cli/CliError.ts +4 -4
- package/src/unstable/cli/Primitive.ts +1 -1
- package/src/unstable/cli/Prompt.ts +27 -0
- package/src/unstable/http/Cookies.ts +84 -0
- package/src/unstable/http/Headers.ts +34 -0
- package/src/unstable/http/HttpClientRequest.ts +21 -17
- package/src/unstable/http/HttpEffect.ts +8 -0
- package/src/unstable/http/HttpServerRequest.ts +388 -1
- package/src/unstable/http/HttpServerResponse.ts +328 -1
- package/src/unstable/http/HttpStaticServer.ts +456 -0
- package/src/unstable/http/index.ts +5 -0
- package/src/unstable/httpapi/HttpApiBuilder.ts +3 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +1 -0
- package/src/unstable/reactivity/Atom.ts +20 -26
- package/src/unstable/reactivity/AtomHttpApi.ts +45 -11
- package/src/unstable/reactivity/AtomRpc.ts +48 -17
- package/src/unstable/rpc/Rpc.ts +1 -3
- package/src/unstable/rpc/RpcMiddleware.ts +12 -6
- package/src/unstable/rpc/RpcServer.ts +2 -2
- package/src/unstable/rpc/Utils.ts +1 -1
- package/src/unstable/schema/Model.ts +31 -0
- package/src/unstable/sql/SqlResolver.ts +2 -2
package/src/Effect.ts
CHANGED
|
@@ -40,12 +40,14 @@
|
|
|
40
40
|
*
|
|
41
41
|
* @example
|
|
42
42
|
* ```ts
|
|
43
|
-
* import { Effect } from "effect"
|
|
43
|
+
* import { Data, Effect } from "effect"
|
|
44
|
+
*
|
|
45
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
44
46
|
*
|
|
45
47
|
* // Effect that may fail
|
|
46
48
|
* const divide = (a: number, b: number) =>
|
|
47
49
|
* b === 0
|
|
48
|
-
* ? Effect.fail(new
|
|
50
|
+
* ? Effect.fail(new DiscountRateError())
|
|
49
51
|
* : Effect.succeed(a / b)
|
|
50
52
|
*
|
|
51
53
|
* // Error handling
|
|
@@ -146,13 +148,15 @@ const TypeId = core.EffectTypeId
|
|
|
146
148
|
*
|
|
147
149
|
* @example
|
|
148
150
|
* ```ts
|
|
149
|
-
* import { Effect } from "effect"
|
|
151
|
+
* import { Data, Effect } from "effect"
|
|
152
|
+
*
|
|
153
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
150
154
|
*
|
|
151
155
|
* // A simple effect that succeeds with a value
|
|
152
156
|
* const success = Effect.succeed(42)
|
|
153
157
|
*
|
|
154
|
-
* // An effect that
|
|
155
|
-
* const risky = Effect.fail(new
|
|
158
|
+
* // An effect that will always fail
|
|
159
|
+
* const risky = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
156
160
|
*
|
|
157
161
|
* // Effects can be composed using generator functions
|
|
158
162
|
* const program = Effect.gen(function*() {
|
|
@@ -433,13 +437,15 @@ export declare namespace All {
|
|
|
433
437
|
* @category Models
|
|
434
438
|
* @example
|
|
435
439
|
* ```ts
|
|
436
|
-
* import { Effect } from "effect"
|
|
440
|
+
* import { Data, Effect } from "effect"
|
|
441
|
+
*
|
|
442
|
+
* class OopsError extends Data.TaggedError("OopsError")<{}> {}
|
|
437
443
|
*
|
|
438
444
|
* // EffectAny represents an Effect with any type parameters
|
|
439
445
|
* const effects: Array<Effect.All.EffectAny> = [
|
|
440
446
|
* Effect.succeed(42),
|
|
441
447
|
* Effect.succeed("hello"),
|
|
442
|
-
* Effect.fail(new
|
|
448
|
+
* Effect.fail(new OopsError())
|
|
443
449
|
* ]
|
|
444
450
|
* ```
|
|
445
451
|
*/
|
|
@@ -1518,16 +1524,18 @@ export const promise: <A>(
|
|
|
1518
1524
|
*
|
|
1519
1525
|
* @example Custom Error Handling
|
|
1520
1526
|
* ```ts
|
|
1521
|
-
* import { Effect } from "effect"
|
|
1527
|
+
* import { Data, Effect } from "effect"
|
|
1528
|
+
*
|
|
1529
|
+
* class TodoFetchError extends Data.TaggedError("TodoFetchError")<{ readonly cause: unknown }> {}
|
|
1522
1530
|
*
|
|
1523
1531
|
* const getTodo = (id: number) =>
|
|
1524
1532
|
* Effect.tryPromise({
|
|
1525
1533
|
* try: () => fetch(`https://jsonplaceholder.typicode.com/todos/${id}`),
|
|
1526
1534
|
* // remap the error
|
|
1527
|
-
* catch: (
|
|
1535
|
+
* catch: (cause) => new TodoFetchError({ cause })
|
|
1528
1536
|
* })
|
|
1529
1537
|
*
|
|
1530
|
-
* // ┌─── Effect<Response,
|
|
1538
|
+
* // ┌─── Effect<Response, TodoFetchError, never>
|
|
1531
1539
|
* // ▼
|
|
1532
1540
|
* const program = getTodo(1)
|
|
1533
1541
|
* ```
|
|
@@ -1937,16 +1945,18 @@ export const bind: {
|
|
|
1937
1945
|
*
|
|
1938
1946
|
* @example
|
|
1939
1947
|
* ```ts
|
|
1940
|
-
* import { Effect } from "effect"
|
|
1948
|
+
* import { Data, Effect } from "effect"
|
|
1949
|
+
*
|
|
1950
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
1941
1951
|
*
|
|
1942
1952
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
1943
1953
|
*
|
|
1944
1954
|
* const applyDiscount = (
|
|
1945
1955
|
* total: number,
|
|
1946
1956
|
* discountRate: number
|
|
1947
|
-
* ): Effect.Effect<number,
|
|
1957
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
1948
1958
|
* discountRate === 0
|
|
1949
|
-
* ? Effect.fail(new
|
|
1959
|
+
* ? Effect.fail(new DiscountRateError())
|
|
1950
1960
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
1951
1961
|
*
|
|
1952
1962
|
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
@@ -1986,16 +1996,18 @@ export const gen: {
|
|
|
1986
1996
|
*
|
|
1987
1997
|
* @example
|
|
1988
1998
|
* ```ts
|
|
1989
|
-
* import { Effect } from "effect"
|
|
1999
|
+
* import { Data, Effect } from "effect"
|
|
2000
|
+
*
|
|
2001
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
1990
2002
|
*
|
|
1991
2003
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
1992
2004
|
*
|
|
1993
2005
|
* const applyDiscount = (
|
|
1994
2006
|
* total: number,
|
|
1995
2007
|
* discountRate: number
|
|
1996
|
-
* ): Effect.Effect<number,
|
|
2008
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
1997
2009
|
* discountRate === 0
|
|
1998
|
-
* ? Effect.fail(new
|
|
2010
|
+
* ? Effect.fail(new DiscountRateError())
|
|
1999
2011
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2000
2012
|
*
|
|
2001
2013
|
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
@@ -2043,16 +2055,18 @@ export const gen: {
|
|
|
2043
2055
|
*
|
|
2044
2056
|
* @example
|
|
2045
2057
|
* ```ts
|
|
2046
|
-
* import { Effect } from "effect"
|
|
2058
|
+
* import { Data, Effect } from "effect"
|
|
2059
|
+
*
|
|
2060
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2047
2061
|
*
|
|
2048
2062
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
2049
2063
|
*
|
|
2050
2064
|
* const applyDiscount = (
|
|
2051
2065
|
* total: number,
|
|
2052
2066
|
* discountRate: number
|
|
2053
|
-
* ): Effect.Effect<number,
|
|
2067
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2054
2068
|
* discountRate === 0
|
|
2055
|
-
* ? Effect.fail(new
|
|
2069
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2056
2070
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2057
2071
|
*
|
|
2058
2072
|
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
@@ -2116,12 +2130,14 @@ export namespace gen {
|
|
|
2116
2130
|
* @example
|
|
2117
2131
|
* ```ts
|
|
2118
2132
|
* // Title: Creating a Failed Effect
|
|
2119
|
-
* import { Effect } from "effect"
|
|
2133
|
+
* import { Data, Effect } from "effect"
|
|
2120
2134
|
*
|
|
2121
|
-
*
|
|
2135
|
+
* class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
|
|
2136
|
+
*
|
|
2137
|
+
* // ┌─── Effect<never, OperationFailedError, never>
|
|
2122
2138
|
* // ▼
|
|
2123
2139
|
* const failure = Effect.fail(
|
|
2124
|
-
* new
|
|
2140
|
+
* new OperationFailedError()
|
|
2125
2141
|
* )
|
|
2126
2142
|
* ```
|
|
2127
2143
|
*
|
|
@@ -2138,9 +2154,11 @@ export const fail: <E>(error: E) => Effect<never, E> = internal.fail
|
|
|
2138
2154
|
*
|
|
2139
2155
|
* @example
|
|
2140
2156
|
* ```ts
|
|
2141
|
-
* import { Effect } from "effect"
|
|
2157
|
+
* import { Data, Effect } from "effect"
|
|
2158
|
+
*
|
|
2159
|
+
* class ProgramError extends Data.TaggedError("ProgramError")<{ readonly failedAt: Date }> {}
|
|
2142
2160
|
*
|
|
2143
|
-
* const program = Effect.failSync(() => new
|
|
2161
|
+
* const program = Effect.failSync(() => new ProgramError({ failedAt: new Date() }))
|
|
2144
2162
|
*
|
|
2145
2163
|
* Effect.runPromiseExit(program).then(console.log)
|
|
2146
2164
|
* // Output: { _id: 'Exit', _tag: 'Failure', cause: ... }
|
|
@@ -2294,12 +2312,14 @@ export {
|
|
|
2294
2312
|
*
|
|
2295
2313
|
* @example Custom Error Handling
|
|
2296
2314
|
* ```ts
|
|
2297
|
-
* import { Effect } from "effect"
|
|
2315
|
+
* import { Data, Effect } from "effect"
|
|
2316
|
+
*
|
|
2317
|
+
* class JsonParsingError extends Data.TaggedError("JsonParsingError")<{ readonly cause: unknown }> {}
|
|
2298
2318
|
*
|
|
2299
2319
|
* const parseJSON = (input: string) =>
|
|
2300
2320
|
* Effect.try({
|
|
2301
2321
|
* try: () => JSON.parse(input),
|
|
2302
|
-
* catch: (
|
|
2322
|
+
* catch: (cause) => new JsonParsingError({ cause })
|
|
2303
2323
|
* })
|
|
2304
2324
|
*
|
|
2305
2325
|
* Effect.runPromiseExit(parseJSON("invalid json")).then(console.log)
|
|
@@ -2436,17 +2456,17 @@ export const fromOption: <A>(
|
|
|
2436
2456
|
* ```ts
|
|
2437
2457
|
* import { Console, Effect } from "effect"
|
|
2438
2458
|
*
|
|
2439
|
-
* const input: string | null
|
|
2440
|
-
*
|
|
2441
|
-
* const program = Effect.gen(function*() {
|
|
2459
|
+
* const program = Effect.fn(function*(input: string | null) {
|
|
2442
2460
|
* const value = yield* Effect.fromNullishOr(input)
|
|
2443
2461
|
* yield* Console.log(value)
|
|
2444
|
-
* }
|
|
2462
|
+
* },
|
|
2445
2463
|
* Effect.catch(() => Console.log("missing"))
|
|
2446
2464
|
* )
|
|
2447
2465
|
*
|
|
2448
|
-
* Effect.runPromise(program)
|
|
2466
|
+
* Effect.runPromise(program(null))
|
|
2449
2467
|
* // Output: missing
|
|
2468
|
+
* Effect.runPromise(program("hello"))
|
|
2469
|
+
* // Output: hello
|
|
2450
2470
|
* ```
|
|
2451
2471
|
*
|
|
2452
2472
|
* @since 4.0.0
|
|
@@ -2515,15 +2535,17 @@ export const fromYieldable: <Self extends Yieldable.Any, A, E, R>(
|
|
|
2515
2535
|
*
|
|
2516
2536
|
* @example
|
|
2517
2537
|
* ```ts
|
|
2518
|
-
* import { Effect, pipe } from "effect"
|
|
2538
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2539
|
+
*
|
|
2540
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2519
2541
|
*
|
|
2520
2542
|
* // Function to apply a discount safely to a transaction amount
|
|
2521
2543
|
* const applyDiscount = (
|
|
2522
2544
|
* total: number,
|
|
2523
2545
|
* discountRate: number
|
|
2524
|
-
* ): Effect.Effect<number,
|
|
2546
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2525
2547
|
* discountRate === 0
|
|
2526
|
-
* ? Effect.fail(new
|
|
2548
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2527
2549
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2528
2550
|
*
|
|
2529
2551
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2581,15 +2603,17 @@ export const flatMap: {
|
|
|
2581
2603
|
*
|
|
2582
2604
|
* @example
|
|
2583
2605
|
* ```ts
|
|
2584
|
-
* import { Effect, pipe } from "effect"
|
|
2606
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2607
|
+
*
|
|
2608
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2585
2609
|
*
|
|
2586
2610
|
* // Function to apply a discount safely to a transaction amount
|
|
2587
2611
|
* const applyDiscount = (
|
|
2588
2612
|
* total: number,
|
|
2589
2613
|
* discountRate: number
|
|
2590
|
-
* ): Effect.Effect<number,
|
|
2614
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2591
2615
|
* discountRate === 0
|
|
2592
|
-
* ? Effect.fail(new
|
|
2616
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2593
2617
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2594
2618
|
*
|
|
2595
2619
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2647,15 +2671,17 @@ export const flatMap: {
|
|
|
2647
2671
|
*
|
|
2648
2672
|
* @example
|
|
2649
2673
|
* ```ts
|
|
2650
|
-
* import { Effect, pipe } from "effect"
|
|
2674
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2675
|
+
*
|
|
2676
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2651
2677
|
*
|
|
2652
2678
|
* // Function to apply a discount safely to a transaction amount
|
|
2653
2679
|
* const applyDiscount = (
|
|
2654
2680
|
* total: number,
|
|
2655
2681
|
* discountRate: number
|
|
2656
|
-
* ): Effect.Effect<number,
|
|
2682
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2657
2683
|
* discountRate === 0
|
|
2658
|
-
* ? Effect.fail(new
|
|
2684
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2659
2685
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2660
2686
|
*
|
|
2661
2687
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2743,15 +2769,17 @@ export const flatten: <A, E, R, E2, R2>(self: Effect<Effect<A, E, R>, E2, R2>) =
|
|
|
2743
2769
|
*
|
|
2744
2770
|
* @example Applying a Discount Based on Fetched Amount
|
|
2745
2771
|
* ```ts
|
|
2746
|
-
* import { Effect, pipe } from "effect"
|
|
2772
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2773
|
+
*
|
|
2774
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2747
2775
|
*
|
|
2748
2776
|
* // Function to apply a discount safely to a transaction amount
|
|
2749
2777
|
* const applyDiscount = (
|
|
2750
2778
|
* total: number,
|
|
2751
2779
|
* discountRate: number
|
|
2752
|
-
* ): Effect.Effect<number,
|
|
2780
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2753
2781
|
* discountRate === 0
|
|
2754
|
-
* ? Effect.fail(new
|
|
2782
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2755
2783
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2756
2784
|
*
|
|
2757
2785
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2824,15 +2852,17 @@ export const andThen: {
|
|
|
2824
2852
|
*
|
|
2825
2853
|
* @example Applying a Discount Based on Fetched Amount
|
|
2826
2854
|
* ```ts
|
|
2827
|
-
* import { Effect, pipe } from "effect"
|
|
2855
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2856
|
+
*
|
|
2857
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2828
2858
|
*
|
|
2829
2859
|
* // Function to apply a discount safely to a transaction amount
|
|
2830
2860
|
* const applyDiscount = (
|
|
2831
2861
|
* total: number,
|
|
2832
2862
|
* discountRate: number
|
|
2833
|
-
* ): Effect.Effect<number,
|
|
2863
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2834
2864
|
* discountRate === 0
|
|
2835
|
-
* ? Effect.fail(new
|
|
2865
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2836
2866
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2837
2867
|
*
|
|
2838
2868
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2905,15 +2935,17 @@ export const andThen: {
|
|
|
2905
2935
|
*
|
|
2906
2936
|
* @example Applying a Discount Based on Fetched Amount
|
|
2907
2937
|
* ```ts
|
|
2908
|
-
* import { Effect, pipe } from "effect"
|
|
2938
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2939
|
+
*
|
|
2940
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2909
2941
|
*
|
|
2910
2942
|
* // Function to apply a discount safely to a transaction amount
|
|
2911
2943
|
* const applyDiscount = (
|
|
2912
2944
|
* total: number,
|
|
2913
2945
|
* discountRate: number
|
|
2914
|
-
* ): Effect.Effect<number,
|
|
2946
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2915
2947
|
* discountRate === 0
|
|
2916
|
-
* ? Effect.fail(new
|
|
2948
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2917
2949
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2918
2950
|
*
|
|
2919
2951
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2986,15 +3018,17 @@ export const andThen: {
|
|
|
2986
3018
|
*
|
|
2987
3019
|
* @example Applying a Discount Based on Fetched Amount
|
|
2988
3020
|
* ```ts
|
|
2989
|
-
* import { Effect, pipe } from "effect"
|
|
3021
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3022
|
+
*
|
|
3023
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2990
3024
|
*
|
|
2991
3025
|
* // Function to apply a discount safely to a transaction amount
|
|
2992
3026
|
* const applyDiscount = (
|
|
2993
3027
|
* total: number,
|
|
2994
3028
|
* discountRate: number
|
|
2995
|
-
* ): Effect.Effect<number,
|
|
3029
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2996
3030
|
* discountRate === 0
|
|
2997
|
-
* ? Effect.fail(new
|
|
3031
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2998
3032
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2999
3033
|
*
|
|
3000
3034
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3067,15 +3101,17 @@ export const andThen: {
|
|
|
3067
3101
|
*
|
|
3068
3102
|
* @example Applying a Discount Based on Fetched Amount
|
|
3069
3103
|
* ```ts
|
|
3070
|
-
* import { Effect, pipe } from "effect"
|
|
3104
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3105
|
+
*
|
|
3106
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3071
3107
|
*
|
|
3072
3108
|
* // Function to apply a discount safely to a transaction amount
|
|
3073
3109
|
* const applyDiscount = (
|
|
3074
3110
|
* total: number,
|
|
3075
3111
|
* discountRate: number
|
|
3076
|
-
* ): Effect.Effect<number,
|
|
3112
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3077
3113
|
* discountRate === 0
|
|
3078
|
-
* ? Effect.fail(new
|
|
3114
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3079
3115
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3080
3116
|
*
|
|
3081
3117
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3134,16 +3170,18 @@ export const andThen: {
|
|
|
3134
3170
|
* @example
|
|
3135
3171
|
* ```ts
|
|
3136
3172
|
* // Title: Logging a step in a pipeline
|
|
3137
|
-
* import { Effect, pipe } from "effect"
|
|
3173
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3138
3174
|
* import { Console } from "effect"
|
|
3139
3175
|
*
|
|
3176
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3177
|
+
*
|
|
3140
3178
|
* // Function to apply a discount safely to a transaction amount
|
|
3141
3179
|
* const applyDiscount = (
|
|
3142
3180
|
* total: number,
|
|
3143
3181
|
* discountRate: number
|
|
3144
|
-
* ): Effect.Effect<number,
|
|
3182
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3145
3183
|
* discountRate === 0
|
|
3146
|
-
* ? Effect.fail(new
|
|
3184
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3147
3185
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3148
3186
|
*
|
|
3149
3187
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3193,16 +3231,18 @@ export const tap: {
|
|
|
3193
3231
|
* @example
|
|
3194
3232
|
* ```ts
|
|
3195
3233
|
* // Title: Logging a step in a pipeline
|
|
3196
|
-
* import { Effect, pipe } from "effect"
|
|
3234
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3197
3235
|
* import { Console } from "effect"
|
|
3198
3236
|
*
|
|
3237
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3238
|
+
*
|
|
3199
3239
|
* // Function to apply a discount safely to a transaction amount
|
|
3200
3240
|
* const applyDiscount = (
|
|
3201
3241
|
* total: number,
|
|
3202
3242
|
* discountRate: number
|
|
3203
|
-
* ): Effect.Effect<number,
|
|
3243
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3204
3244
|
* discountRate === 0
|
|
3205
|
-
* ? Effect.fail(new
|
|
3245
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3206
3246
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3207
3247
|
*
|
|
3208
3248
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3252,16 +3292,18 @@ export const tap: {
|
|
|
3252
3292
|
* @example
|
|
3253
3293
|
* ```ts
|
|
3254
3294
|
* // Title: Logging a step in a pipeline
|
|
3255
|
-
* import { Effect, pipe } from "effect"
|
|
3295
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3256
3296
|
* import { Console } from "effect"
|
|
3257
3297
|
*
|
|
3298
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3299
|
+
*
|
|
3258
3300
|
* // Function to apply a discount safely to a transaction amount
|
|
3259
3301
|
* const applyDiscount = (
|
|
3260
3302
|
* total: number,
|
|
3261
3303
|
* discountRate: number
|
|
3262
|
-
* ): Effect.Effect<number,
|
|
3304
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3263
3305
|
* discountRate === 0
|
|
3264
|
-
* ? Effect.fail(new
|
|
3306
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3265
3307
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3266
3308
|
*
|
|
3267
3309
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3311,16 +3353,18 @@ export const tap: {
|
|
|
3311
3353
|
* @example
|
|
3312
3354
|
* ```ts
|
|
3313
3355
|
* // Title: Logging a step in a pipeline
|
|
3314
|
-
* import { Effect, pipe } from "effect"
|
|
3356
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3315
3357
|
* import { Console } from "effect"
|
|
3316
3358
|
*
|
|
3359
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3360
|
+
*
|
|
3317
3361
|
* // Function to apply a discount safely to a transaction amount
|
|
3318
3362
|
* const applyDiscount = (
|
|
3319
3363
|
* total: number,
|
|
3320
3364
|
* discountRate: number
|
|
3321
|
-
* ): Effect.Effect<number,
|
|
3365
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3322
3366
|
* discountRate === 0
|
|
3323
|
-
* ? Effect.fail(new
|
|
3367
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3324
3368
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3325
3369
|
*
|
|
3326
3370
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3370,16 +3414,18 @@ export const tap: {
|
|
|
3370
3414
|
* @example
|
|
3371
3415
|
* ```ts
|
|
3372
3416
|
* // Title: Logging a step in a pipeline
|
|
3373
|
-
* import { Effect, pipe } from "effect"
|
|
3417
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3374
3418
|
* import { Console } from "effect"
|
|
3375
3419
|
*
|
|
3420
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3421
|
+
*
|
|
3376
3422
|
* // Function to apply a discount safely to a transaction amount
|
|
3377
3423
|
* const applyDiscount = (
|
|
3378
3424
|
* total: number,
|
|
3379
3425
|
* discountRate: number
|
|
3380
|
-
* ): Effect.Effect<number,
|
|
3426
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3381
3427
|
* discountRate === 0
|
|
3382
|
-
* ? Effect.fail(new
|
|
3428
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3383
3429
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3384
3430
|
*
|
|
3385
3431
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -5801,17 +5847,19 @@ export const catchCauseFilter: {
|
|
|
5801
5847
|
*
|
|
5802
5848
|
* @example
|
|
5803
5849
|
* ```ts
|
|
5804
|
-
* import { Effect } from "effect"
|
|
5850
|
+
* import { Data, Effect } from "effect"
|
|
5851
|
+
*
|
|
5852
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5805
5853
|
*
|
|
5806
5854
|
* // ┌─── Effect<number, string, never>
|
|
5807
5855
|
* // ▼
|
|
5808
5856
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5809
5857
|
*
|
|
5810
|
-
* // ┌─── Effect<number,
|
|
5858
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5811
5859
|
* // ▼
|
|
5812
5860
|
* const mapped = Effect.mapError(
|
|
5813
5861
|
* simulatedTask,
|
|
5814
|
-
* (message) => new
|
|
5862
|
+
* (message) => new TaskError({ message })
|
|
5815
5863
|
* )
|
|
5816
5864
|
* ```
|
|
5817
5865
|
*
|
|
@@ -5834,17 +5882,19 @@ export const mapError: {
|
|
|
5834
5882
|
*
|
|
5835
5883
|
* @example
|
|
5836
5884
|
* ```ts
|
|
5837
|
-
* import { Effect } from "effect"
|
|
5885
|
+
* import { Data, Effect } from "effect"
|
|
5886
|
+
*
|
|
5887
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5838
5888
|
*
|
|
5839
5889
|
* // ┌─── Effect<number, string, never>
|
|
5840
5890
|
* // ▼
|
|
5841
5891
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5842
5892
|
*
|
|
5843
|
-
* // ┌─── Effect<number,
|
|
5893
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5844
5894
|
* // ▼
|
|
5845
5895
|
* const mapped = Effect.mapError(
|
|
5846
5896
|
* simulatedTask,
|
|
5847
|
-
* (message) => new
|
|
5897
|
+
* (message) => new TaskError({ message })
|
|
5848
5898
|
* )
|
|
5849
5899
|
* ```
|
|
5850
5900
|
*
|
|
@@ -5867,17 +5917,19 @@ export const mapError: {
|
|
|
5867
5917
|
*
|
|
5868
5918
|
* @example
|
|
5869
5919
|
* ```ts
|
|
5870
|
-
* import { Effect } from "effect"
|
|
5920
|
+
* import { Data, Effect } from "effect"
|
|
5921
|
+
*
|
|
5922
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5871
5923
|
*
|
|
5872
5924
|
* // ┌─── Effect<number, string, never>
|
|
5873
5925
|
* // ▼
|
|
5874
5926
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5875
5927
|
*
|
|
5876
|
-
* // ┌─── Effect<number,
|
|
5928
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5877
5929
|
* // ▼
|
|
5878
5930
|
* const mapped = Effect.mapError(
|
|
5879
5931
|
* simulatedTask,
|
|
5880
|
-
* (message) => new
|
|
5932
|
+
* (message) => new TaskError({ message })
|
|
5881
5933
|
* )
|
|
5882
5934
|
* ```
|
|
5883
5935
|
*
|
|
@@ -5899,16 +5951,18 @@ export const mapError: {
|
|
|
5899
5951
|
*
|
|
5900
5952
|
* @example
|
|
5901
5953
|
* ```ts
|
|
5902
|
-
* import { Effect } from "effect"
|
|
5954
|
+
* import { Data, Effect } from "effect"
|
|
5955
|
+
*
|
|
5956
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5903
5957
|
*
|
|
5904
5958
|
* // ┌─── Effect<number, string, never>
|
|
5905
5959
|
* // ▼
|
|
5906
5960
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5907
5961
|
*
|
|
5908
|
-
* // ┌─── Effect<boolean,
|
|
5962
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5909
5963
|
* // ▼
|
|
5910
5964
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5911
|
-
* onFailure: (message) => new
|
|
5965
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5912
5966
|
* onSuccess: (n) => n > 0
|
|
5913
5967
|
* })
|
|
5914
5968
|
* ```
|
|
@@ -5932,16 +5986,18 @@ export const mapBoth: {
|
|
|
5932
5986
|
*
|
|
5933
5987
|
* @example
|
|
5934
5988
|
* ```ts
|
|
5935
|
-
* import { Effect } from "effect"
|
|
5989
|
+
* import { Data, Effect } from "effect"
|
|
5990
|
+
*
|
|
5991
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5936
5992
|
*
|
|
5937
5993
|
* // ┌─── Effect<number, string, never>
|
|
5938
5994
|
* // ▼
|
|
5939
5995
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5940
5996
|
*
|
|
5941
|
-
* // ┌─── Effect<boolean,
|
|
5997
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5942
5998
|
* // ▼
|
|
5943
5999
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5944
|
-
* onFailure: (message) => new
|
|
6000
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5945
6001
|
* onSuccess: (n) => n > 0
|
|
5946
6002
|
* })
|
|
5947
6003
|
* ```
|
|
@@ -5967,16 +6023,18 @@ export const mapBoth: {
|
|
|
5967
6023
|
*
|
|
5968
6024
|
* @example
|
|
5969
6025
|
* ```ts
|
|
5970
|
-
* import { Effect } from "effect"
|
|
6026
|
+
* import { Data, Effect } from "effect"
|
|
6027
|
+
*
|
|
6028
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5971
6029
|
*
|
|
5972
6030
|
* // ┌─── Effect<number, string, never>
|
|
5973
6031
|
* // ▼
|
|
5974
6032
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5975
6033
|
*
|
|
5976
|
-
* // ┌─── Effect<boolean,
|
|
6034
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5977
6035
|
* // ▼
|
|
5978
6036
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5979
|
-
* onFailure: (message) => new
|
|
6037
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5980
6038
|
* onSuccess: (n) => n > 0
|
|
5981
6039
|
* })
|
|
5982
6040
|
* ```
|
|
@@ -6011,11 +6069,13 @@ export const mapBoth: {
|
|
|
6011
6069
|
* @example
|
|
6012
6070
|
* ```ts
|
|
6013
6071
|
* // Title: Propagating an Error as a Defect
|
|
6014
|
-
* import { Effect } from "effect"
|
|
6072
|
+
* import { Data, Effect } from "effect"
|
|
6073
|
+
*
|
|
6074
|
+
* class DivideByZeroError extends Data.TaggedError("DivideByZeroError")<{}> {}
|
|
6015
6075
|
*
|
|
6016
6076
|
* const divide = (a: number, b: number) =>
|
|
6017
6077
|
* b === 0
|
|
6018
|
-
* ? Effect.fail(new
|
|
6078
|
+
* ? Effect.fail(new DivideByZeroError())
|
|
6019
6079
|
* : Effect.succeed(a / b)
|
|
6020
6080
|
*
|
|
6021
6081
|
* // ┌─── Effect<number, never, never>
|
|
@@ -6024,7 +6084,7 @@ export const mapBoth: {
|
|
|
6024
6084
|
*
|
|
6025
6085
|
* Effect.runPromise(program).catch(console.error)
|
|
6026
6086
|
* // Output:
|
|
6027
|
-
* // (FiberFailure)
|
|
6087
|
+
* // (FiberFailure) DivideByZeroError
|
|
6028
6088
|
* // ...stack trace...
|
|
6029
6089
|
* ```
|
|
6030
6090
|
*
|
|
@@ -6656,7 +6716,7 @@ export const tapDefect: {
|
|
|
6656
6716
|
* attempts++
|
|
6657
6717
|
* yield* Console.log(`Attempt ${attempts}`)
|
|
6658
6718
|
* if (attempts < 3) {
|
|
6659
|
-
* yield* Effect.fail("Not ready")
|
|
6719
|
+
* return yield* Effect.fail("Not ready")
|
|
6660
6720
|
* }
|
|
6661
6721
|
* return "Ready"
|
|
6662
6722
|
* })
|
|
@@ -6783,13 +6843,15 @@ export declare namespace Retry {
|
|
|
6783
6843
|
*
|
|
6784
6844
|
* @example
|
|
6785
6845
|
* ```ts
|
|
6786
|
-
* import { Effect, Schedule } from "effect"
|
|
6846
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6847
|
+
*
|
|
6848
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6787
6849
|
*
|
|
6788
6850
|
* let attempt = 0
|
|
6789
|
-
* const task = Effect.callback<string,
|
|
6851
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6790
6852
|
* attempt++
|
|
6791
6853
|
* if (attempt <= 2) {
|
|
6792
|
-
* resume(Effect.fail(new
|
|
6854
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6793
6855
|
* } else {
|
|
6794
6856
|
* resume(Effect.succeed("Success!"))
|
|
6795
6857
|
* }
|
|
@@ -6832,13 +6894,15 @@ export const retry: {
|
|
|
6832
6894
|
*
|
|
6833
6895
|
* @example
|
|
6834
6896
|
* ```ts
|
|
6835
|
-
* import { Effect, Schedule } from "effect"
|
|
6897
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6898
|
+
*
|
|
6899
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6836
6900
|
*
|
|
6837
6901
|
* let attempt = 0
|
|
6838
|
-
* const task = Effect.callback<string,
|
|
6902
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6839
6903
|
* attempt++
|
|
6840
6904
|
* if (attempt <= 2) {
|
|
6841
|
-
* resume(Effect.fail(new
|
|
6905
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6842
6906
|
* } else {
|
|
6843
6907
|
* resume(Effect.succeed("Success!"))
|
|
6844
6908
|
* }
|
|
@@ -6881,13 +6945,15 @@ export const retry: {
|
|
|
6881
6945
|
*
|
|
6882
6946
|
* @example
|
|
6883
6947
|
* ```ts
|
|
6884
|
-
* import { Effect, Schedule } from "effect"
|
|
6948
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6949
|
+
*
|
|
6950
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6885
6951
|
*
|
|
6886
6952
|
* let attempt = 0
|
|
6887
|
-
* const task = Effect.callback<string,
|
|
6953
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6888
6954
|
* attempt++
|
|
6889
6955
|
* if (attempt <= 2) {
|
|
6890
|
-
* resume(Effect.fail(new
|
|
6956
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6891
6957
|
* } else {
|
|
6892
6958
|
* resume(Effect.succeed("Success!"))
|
|
6893
6959
|
* }
|
|
@@ -6930,13 +6996,15 @@ export const retry: {
|
|
|
6930
6996
|
*
|
|
6931
6997
|
* @example
|
|
6932
6998
|
* ```ts
|
|
6933
|
-
* import { Effect, Schedule } from "effect"
|
|
6999
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
7000
|
+
*
|
|
7001
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6934
7002
|
*
|
|
6935
7003
|
* let attempt = 0
|
|
6936
|
-
* const task = Effect.callback<string,
|
|
7004
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6937
7005
|
* attempt++
|
|
6938
7006
|
* if (attempt <= 2) {
|
|
6939
|
-
* resume(Effect.fail(new
|
|
7007
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6940
7008
|
* } else {
|
|
6941
7009
|
* resume(Effect.succeed("Success!"))
|
|
6942
7010
|
* }
|
|
@@ -6983,13 +7051,15 @@ export const retry: {
|
|
|
6983
7051
|
*
|
|
6984
7052
|
* @example
|
|
6985
7053
|
* ```ts
|
|
6986
|
-
* import { Effect, Schedule } from "effect"
|
|
7054
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
7055
|
+
*
|
|
7056
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6987
7057
|
*
|
|
6988
7058
|
* let attempt = 0
|
|
6989
|
-
* const task = Effect.callback<string,
|
|
7059
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6990
7060
|
* attempt++
|
|
6991
7061
|
* if (attempt <= 2) {
|
|
6992
|
-
* resume(Effect.fail(new
|
|
7062
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6993
7063
|
* } else {
|
|
6994
7064
|
* resume(Effect.succeed("Success!"))
|
|
6995
7065
|
* }
|
|
@@ -7032,13 +7102,15 @@ export const retry: {
|
|
|
7032
7102
|
*
|
|
7033
7103
|
* @example
|
|
7034
7104
|
* ```ts
|
|
7035
|
-
* import { Effect, Schedule } from "effect"
|
|
7105
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
7106
|
+
*
|
|
7107
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
7036
7108
|
*
|
|
7037
7109
|
* let attempt = 0
|
|
7038
|
-
* const task = Effect.callback<string,
|
|
7110
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
7039
7111
|
* attempt++
|
|
7040
7112
|
* if (attempt <= 2) {
|
|
7041
|
-
* resume(Effect.fail(new
|
|
7113
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
7042
7114
|
* } else {
|
|
7043
7115
|
* resume(Effect.succeed("Success!"))
|
|
7044
7116
|
* }
|
|
@@ -7081,13 +7153,15 @@ export const retry: {
|
|
|
7081
7153
|
*
|
|
7082
7154
|
* @example
|
|
7083
7155
|
* ```ts
|
|
7084
|
-
* import { Effect, Schedule } from "effect"
|
|
7156
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
7157
|
+
*
|
|
7158
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
7085
7159
|
*
|
|
7086
7160
|
* let attempt = 0
|
|
7087
|
-
* const task = Effect.callback<string,
|
|
7161
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
7088
7162
|
* attempt++
|
|
7089
7163
|
* if (attempt <= 2) {
|
|
7090
|
-
* resume(Effect.fail(new
|
|
7164
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
7091
7165
|
* } else {
|
|
7092
7166
|
* resume(Effect.succeed("Success!"))
|
|
7093
7167
|
* }
|
|
@@ -7134,14 +7208,16 @@ export const retry: {
|
|
|
7134
7208
|
*
|
|
7135
7209
|
* @example
|
|
7136
7210
|
* ```ts
|
|
7137
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
7211
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
7212
|
+
*
|
|
7213
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
7138
7214
|
*
|
|
7139
7215
|
* let attempt = 0
|
|
7140
7216
|
* const networkRequest = Effect.gen(function*() {
|
|
7141
7217
|
* attempt++
|
|
7142
7218
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
7143
7219
|
* if (attempt < 3) {
|
|
7144
|
-
* return yield* Effect.fail(new
|
|
7220
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
7145
7221
|
* }
|
|
7146
7222
|
* return "Network data"
|
|
7147
7223
|
* })
|
|
@@ -7189,14 +7265,16 @@ export const retryOrElse: {
|
|
|
7189
7265
|
*
|
|
7190
7266
|
* @example
|
|
7191
7267
|
* ```ts
|
|
7192
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
7268
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
7269
|
+
*
|
|
7270
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
7193
7271
|
*
|
|
7194
7272
|
* let attempt = 0
|
|
7195
7273
|
* const networkRequest = Effect.gen(function*() {
|
|
7196
7274
|
* attempt++
|
|
7197
7275
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
7198
7276
|
* if (attempt < 3) {
|
|
7199
|
-
* return yield* Effect.fail(new
|
|
7277
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
7200
7278
|
* }
|
|
7201
7279
|
* return "Network data"
|
|
7202
7280
|
* })
|
|
@@ -7247,14 +7325,16 @@ export const retryOrElse: {
|
|
|
7247
7325
|
*
|
|
7248
7326
|
* @example
|
|
7249
7327
|
* ```ts
|
|
7250
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
7328
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
7329
|
+
*
|
|
7330
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
7251
7331
|
*
|
|
7252
7332
|
* let attempt = 0
|
|
7253
7333
|
* const networkRequest = Effect.gen(function*() {
|
|
7254
7334
|
* attempt++
|
|
7255
7335
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
7256
7336
|
* if (attempt < 3) {
|
|
7257
|
-
* return yield* Effect.fail(new
|
|
7337
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
7258
7338
|
* }
|
|
7259
7339
|
* return "Network data"
|
|
7260
7340
|
* })
|
|
@@ -7433,7 +7513,10 @@ export const ignoreCause: <
|
|
|
7433
7513
|
*
|
|
7434
7514
|
* const fetchUrl = Effect.gen(function*() {
|
|
7435
7515
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
7436
|
-
*
|
|
7516
|
+
* if (endpoint.url === "bad") {
|
|
7517
|
+
* return yield* Effect.fail("Unavailable")
|
|
7518
|
+
* }
|
|
7519
|
+
* return endpoint.url
|
|
7437
7520
|
* })
|
|
7438
7521
|
*
|
|
7439
7522
|
* const plan = ExecutionPlan.make(
|
|
@@ -7464,7 +7547,10 @@ export const withExecutionPlan: {
|
|
|
7464
7547
|
*
|
|
7465
7548
|
* const fetchUrl = Effect.gen(function*() {
|
|
7466
7549
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
7467
|
-
*
|
|
7550
|
+
* if (endpoint.url === "bad") {
|
|
7551
|
+
* return yield* Effect.fail("Unavailable")
|
|
7552
|
+
* }
|
|
7553
|
+
* return endpoint.url
|
|
7468
7554
|
* })
|
|
7469
7555
|
*
|
|
7470
7556
|
* const plan = ExecutionPlan.make(
|
|
@@ -7499,7 +7585,10 @@ export const withExecutionPlan: {
|
|
|
7499
7585
|
*
|
|
7500
7586
|
* const fetchUrl = Effect.gen(function*() {
|
|
7501
7587
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
7502
|
-
*
|
|
7588
|
+
* if (endpoint.url === "bad") {
|
|
7589
|
+
* return yield* Effect.fail("Unavailable")
|
|
7590
|
+
* }
|
|
7591
|
+
* return endpoint.url
|
|
7503
7592
|
* })
|
|
7504
7593
|
*
|
|
7505
7594
|
* const plan = ExecutionPlan.make(
|
|
@@ -9432,9 +9521,11 @@ export const when: {
|
|
|
9432
9521
|
* @example
|
|
9433
9522
|
* ```ts
|
|
9434
9523
|
* // Title: Handling Both Success and Failure Cases
|
|
9435
|
-
* import { Effect } from "effect"
|
|
9524
|
+
* import { Data, Effect } from "effect"
|
|
9525
|
+
*
|
|
9526
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9436
9527
|
*
|
|
9437
|
-
* const success: Effect.Effect<number,
|
|
9528
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9438
9529
|
*
|
|
9439
9530
|
* const program1 = Effect.match(success, {
|
|
9440
9531
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9445,8 +9536,8 @@ export const when: {
|
|
|
9445
9536
|
* Effect.runPromise(program1).then(console.log)
|
|
9446
9537
|
* // Output: "success: 42"
|
|
9447
9538
|
*
|
|
9448
|
-
* const failure: Effect.Effect<number,
|
|
9449
|
-
* new
|
|
9539
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9540
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9450
9541
|
* )
|
|
9451
9542
|
*
|
|
9452
9543
|
* const program2 = Effect.match(failure, {
|
|
@@ -9488,9 +9579,11 @@ export const match: {
|
|
|
9488
9579
|
* @example
|
|
9489
9580
|
* ```ts
|
|
9490
9581
|
* // Title: Handling Both Success and Failure Cases
|
|
9491
|
-
* import { Effect } from "effect"
|
|
9582
|
+
* import { Data, Effect } from "effect"
|
|
9492
9583
|
*
|
|
9493
|
-
*
|
|
9584
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9585
|
+
*
|
|
9586
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9494
9587
|
*
|
|
9495
9588
|
* const program1 = Effect.match(success, {
|
|
9496
9589
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9501,8 +9594,8 @@ export const match: {
|
|
|
9501
9594
|
* Effect.runPromise(program1).then(console.log)
|
|
9502
9595
|
* // Output: "success: 42"
|
|
9503
9596
|
*
|
|
9504
|
-
* const failure: Effect.Effect<number,
|
|
9505
|
-
* new
|
|
9597
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9598
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9506
9599
|
* )
|
|
9507
9600
|
*
|
|
9508
9601
|
* const program2 = Effect.match(failure, {
|
|
@@ -9549,9 +9642,11 @@ export const match: {
|
|
|
9549
9642
|
* @example
|
|
9550
9643
|
* ```ts
|
|
9551
9644
|
* // Title: Handling Both Success and Failure Cases
|
|
9552
|
-
* import { Effect } from "effect"
|
|
9645
|
+
* import { Data, Effect } from "effect"
|
|
9646
|
+
*
|
|
9647
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9553
9648
|
*
|
|
9554
|
-
* const success: Effect.Effect<number,
|
|
9649
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9555
9650
|
*
|
|
9556
9651
|
* const program1 = Effect.match(success, {
|
|
9557
9652
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9562,8 +9657,8 @@ export const match: {
|
|
|
9562
9657
|
* Effect.runPromise(program1).then(console.log)
|
|
9563
9658
|
* // Output: "success: 42"
|
|
9564
9659
|
*
|
|
9565
|
-
* const failure: Effect.Effect<number,
|
|
9566
|
-
* new
|
|
9660
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9661
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9567
9662
|
* )
|
|
9568
9663
|
*
|
|
9569
9664
|
* const program2 = Effect.match(failure, {
|
|
@@ -9993,9 +10088,11 @@ export const matchCauseEffectEager: {
|
|
|
9993
10088
|
*
|
|
9994
10089
|
* @example
|
|
9995
10090
|
* ```ts
|
|
9996
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
10091
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
9997
10092
|
*
|
|
9998
|
-
*
|
|
10093
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
10094
|
+
*
|
|
10095
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
9999
10096
|
*
|
|
10000
10097
|
* const program = Effect.matchCauseEffect(task, {
|
|
10001
10098
|
* onFailure: (cause) =>
|
|
@@ -10045,9 +10142,11 @@ export const matchCauseEffect: {
|
|
|
10045
10142
|
*
|
|
10046
10143
|
* @example
|
|
10047
10144
|
* ```ts
|
|
10048
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
10145
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
10146
|
+
*
|
|
10147
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
10049
10148
|
*
|
|
10050
|
-
* const task = Effect.fail(new
|
|
10149
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
10051
10150
|
*
|
|
10052
10151
|
* const program = Effect.matchCauseEffect(task, {
|
|
10053
10152
|
* onFailure: (cause) =>
|
|
@@ -10102,9 +10201,11 @@ export const matchCauseEffect: {
|
|
|
10102
10201
|
*
|
|
10103
10202
|
* @example
|
|
10104
10203
|
* ```ts
|
|
10105
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
10204
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
10205
|
+
*
|
|
10206
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
10106
10207
|
*
|
|
10107
|
-
* const task = Effect.fail(new
|
|
10208
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
10108
10209
|
*
|
|
10109
10210
|
* const program = Effect.matchCauseEffect(task, {
|
|
10110
10211
|
* onFailure: (cause) =>
|
|
@@ -10168,11 +10269,13 @@ export const matchCauseEffect: {
|
|
|
10168
10269
|
* @example
|
|
10169
10270
|
* ```ts
|
|
10170
10271
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
10171
|
-
* import { Effect } from "effect"
|
|
10272
|
+
* import { Data, Effect } from "effect"
|
|
10172
10273
|
*
|
|
10173
|
-
*
|
|
10174
|
-
*
|
|
10175
|
-
*
|
|
10274
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
10275
|
+
*
|
|
10276
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
10277
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
10278
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
10176
10279
|
* )
|
|
10177
10280
|
*
|
|
10178
10281
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -10228,11 +10331,13 @@ export const matchEffect: {
|
|
|
10228
10331
|
* @example
|
|
10229
10332
|
* ```ts
|
|
10230
10333
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
10231
|
-
* import { Effect } from "effect"
|
|
10334
|
+
* import { Data, Effect } from "effect"
|
|
10335
|
+
*
|
|
10336
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
10232
10337
|
*
|
|
10233
|
-
* const success: Effect.Effect<number,
|
|
10234
|
-
* const failure: Effect.Effect<number,
|
|
10235
|
-
* new
|
|
10338
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
10339
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
10340
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
10236
10341
|
* )
|
|
10237
10342
|
*
|
|
10238
10343
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -10293,11 +10398,13 @@ export const matchEffect: {
|
|
|
10293
10398
|
* @example
|
|
10294
10399
|
* ```ts
|
|
10295
10400
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
10296
|
-
* import { Effect } from "effect"
|
|
10401
|
+
* import { Data, Effect } from "effect"
|
|
10402
|
+
*
|
|
10403
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
10297
10404
|
*
|
|
10298
|
-
* const success: Effect.Effect<number,
|
|
10299
|
-
* const failure: Effect.Effect<number,
|
|
10300
|
-
* new
|
|
10405
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
10406
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
10407
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
10301
10408
|
* )
|
|
10302
10409
|
*
|
|
10303
10410
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -10440,7 +10547,7 @@ export const isSuccess: <A, E, R>(self: Effect<A, E, R>) => Effect<boolean, neve
|
|
|
10440
10547
|
* @since 2.0.0
|
|
10441
10548
|
* @category Environment
|
|
10442
10549
|
*/
|
|
10443
|
-
export const services: <R>() => Effect<ServiceMap.ServiceMap<R>, never, R> = internal.services
|
|
10550
|
+
export const services: <R = never>() => Effect<ServiceMap.ServiceMap<R>, never, R> = internal.services
|
|
10444
10551
|
|
|
10445
10552
|
/**
|
|
10446
10553
|
* Transforms the current service map using the provided function.
|
|
@@ -10506,7 +10613,7 @@ export const servicesWith: <R, A, E, R2>(
|
|
|
10506
10613
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10507
10614
|
*
|
|
10508
10615
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10509
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10616
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10510
10617
|
* })
|
|
10511
10618
|
*
|
|
10512
10619
|
* const program = Effect.gen(function*() {
|
|
@@ -10540,7 +10647,7 @@ export const provide: {
|
|
|
10540
10647
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10541
10648
|
*
|
|
10542
10649
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10543
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10650
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10544
10651
|
* })
|
|
10545
10652
|
*
|
|
10546
10653
|
* const program = Effect.gen(function*() {
|
|
@@ -10585,7 +10692,7 @@ export const provide: {
|
|
|
10585
10692
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10586
10693
|
*
|
|
10587
10694
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10588
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10695
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10589
10696
|
* })
|
|
10590
10697
|
*
|
|
10591
10698
|
* const program = Effect.gen(function*() {
|
|
@@ -10626,7 +10733,7 @@ export const provide: {
|
|
|
10626
10733
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10627
10734
|
*
|
|
10628
10735
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10629
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10736
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10630
10737
|
* })
|
|
10631
10738
|
*
|
|
10632
10739
|
* const program = Effect.gen(function*() {
|
|
@@ -10660,7 +10767,7 @@ export const provide: {
|
|
|
10660
10767
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10661
10768
|
*
|
|
10662
10769
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10663
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10770
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10664
10771
|
* })
|
|
10665
10772
|
*
|
|
10666
10773
|
* const program = Effect.gen(function*() {
|
|
@@ -10704,7 +10811,7 @@ export const provide: {
|
|
|
10704
10811
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10705
10812
|
*
|
|
10706
10813
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10707
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10814
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10708
10815
|
* })
|
|
10709
10816
|
*
|
|
10710
10817
|
* const program = Effect.gen(function*() {
|
|
@@ -10744,7 +10851,7 @@ export const provide: {
|
|
|
10744
10851
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
10745
10852
|
*
|
|
10746
10853
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
10747
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
10854
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
10748
10855
|
* })
|
|
10749
10856
|
*
|
|
10750
10857
|
* const program = Effect.gen(function*() {
|
|
@@ -12141,9 +12248,11 @@ export const ensuring: {
|
|
|
12141
12248
|
*
|
|
12142
12249
|
* @example
|
|
12143
12250
|
* ```ts
|
|
12144
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12251
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
12252
|
+
*
|
|
12253
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12145
12254
|
*
|
|
12146
|
-
* const task = Effect.fail(new
|
|
12255
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
12147
12256
|
*
|
|
12148
12257
|
* const program = Effect.onError(
|
|
12149
12258
|
* task,
|
|
@@ -12152,8 +12261,8 @@ export const ensuring: {
|
|
|
12152
12261
|
*
|
|
12153
12262
|
* Effect.runPromise(program).catch(console.error)
|
|
12154
12263
|
* // Output:
|
|
12155
|
-
* // Cleanup on error:
|
|
12156
|
-
* //
|
|
12264
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12265
|
+
* // TaskError: Something went wrong
|
|
12157
12266
|
* ```
|
|
12158
12267
|
*
|
|
12159
12268
|
* @since 2.0.0
|
|
@@ -12166,9 +12275,11 @@ export const onError: {
|
|
|
12166
12275
|
*
|
|
12167
12276
|
* @example
|
|
12168
12277
|
* ```ts
|
|
12169
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12278
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
12279
|
+
*
|
|
12280
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12170
12281
|
*
|
|
12171
|
-
* const task = Effect.fail(new
|
|
12282
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
12172
12283
|
*
|
|
12173
12284
|
* const program = Effect.onError(
|
|
12174
12285
|
* task,
|
|
@@ -12177,8 +12288,8 @@ export const onError: {
|
|
|
12177
12288
|
*
|
|
12178
12289
|
* Effect.runPromise(program).catch(console.error)
|
|
12179
12290
|
* // Output:
|
|
12180
|
-
* // Cleanup on error:
|
|
12181
|
-
* //
|
|
12291
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12292
|
+
* // TaskError: Something went wrong
|
|
12182
12293
|
* ```
|
|
12183
12294
|
*
|
|
12184
12295
|
* @since 2.0.0
|
|
@@ -12191,9 +12302,11 @@ export const onError: {
|
|
|
12191
12302
|
*
|
|
12192
12303
|
* @example
|
|
12193
12304
|
* ```ts
|
|
12194
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12305
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
12306
|
+
*
|
|
12307
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12195
12308
|
*
|
|
12196
|
-
* const task = Effect.fail(new
|
|
12309
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
12197
12310
|
*
|
|
12198
12311
|
* const program = Effect.onError(
|
|
12199
12312
|
* task,
|
|
@@ -12202,8 +12315,8 @@ export const onError: {
|
|
|
12202
12315
|
*
|
|
12203
12316
|
* Effect.runPromise(program).catch(console.error)
|
|
12204
12317
|
* // Output:
|
|
12205
|
-
* // Cleanup on error:
|
|
12206
|
-
* //
|
|
12318
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12319
|
+
* // TaskError: Something went wrong
|
|
12207
12320
|
* ```
|
|
12208
12321
|
*
|
|
12209
12322
|
* @since 2.0.0
|
|
@@ -13024,8 +13137,8 @@ export const cachedInvalidateWithTTL: {
|
|
|
13024
13137
|
* import { Effect } from "effect"
|
|
13025
13138
|
*
|
|
13026
13139
|
* const program = Effect.gen(function*() {
|
|
13027
|
-
* yield* Effect.interrupt
|
|
13028
|
-
* yield* Effect.succeed("This won't execute")
|
|
13140
|
+
* return yield* Effect.interrupt
|
|
13141
|
+
* yield* Effect.succeed("This won't execute and is unreachable")
|
|
13029
13142
|
* })
|
|
13030
13143
|
*
|
|
13031
13144
|
* Effect.runPromise(program).catch(console.error)
|
|
@@ -13852,7 +13965,7 @@ export const repeat: {
|
|
|
13852
13965
|
* attempt++
|
|
13853
13966
|
* if (attempt <= 2) {
|
|
13854
13967
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
13855
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
13968
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
13856
13969
|
* }
|
|
13857
13970
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
13858
13971
|
* return "success"
|
|
@@ -13902,7 +14015,7 @@ export const repeatOrElse: {
|
|
|
13902
14015
|
* attempt++
|
|
13903
14016
|
* if (attempt <= 2) {
|
|
13904
14017
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
13905
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
14018
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
13906
14019
|
* }
|
|
13907
14020
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
13908
14021
|
* return "success"
|
|
@@ -13955,7 +14068,7 @@ export const repeatOrElse: {
|
|
|
13955
14068
|
* attempt++
|
|
13956
14069
|
* if (attempt <= 2) {
|
|
13957
14070
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
13958
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
14071
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
13959
14072
|
* }
|
|
13960
14073
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
13961
14074
|
* return "success"
|
|
@@ -15420,7 +15533,7 @@ export const withParentSpan: {
|
|
|
15420
15533
|
* )
|
|
15421
15534
|
*
|
|
15422
15535
|
* const program = Effect.gen(function*() {
|
|
15423
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15536
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15424
15537
|
* yield* Console.log(name)
|
|
15425
15538
|
* })
|
|
15426
15539
|
* ```
|
|
@@ -15455,7 +15568,7 @@ export const request: {
|
|
|
15455
15568
|
* )
|
|
15456
15569
|
*
|
|
15457
15570
|
* const program = Effect.gen(function*() {
|
|
15458
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15571
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15459
15572
|
* yield* Console.log(name)
|
|
15460
15573
|
* })
|
|
15461
15574
|
* ```
|
|
@@ -15490,7 +15603,7 @@ export const request: {
|
|
|
15490
15603
|
* )
|
|
15491
15604
|
*
|
|
15492
15605
|
* const program = Effect.gen(function*() {
|
|
15493
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15606
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15494
15607
|
* yield* Console.log(name)
|
|
15495
15608
|
* })
|
|
15496
15609
|
* ```
|
|
@@ -21721,18 +21834,20 @@ export const trackSuccesses: {
|
|
|
21721
21834
|
*
|
|
21722
21835
|
* @example
|
|
21723
21836
|
* ```ts
|
|
21724
|
-
* import { Effect, Metric } from "effect"
|
|
21837
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21838
|
+
*
|
|
21839
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21725
21840
|
*
|
|
21726
21841
|
* // Track error types using frequency metric
|
|
21727
21842
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21728
21843
|
*
|
|
21729
|
-
* const program = Effect.fail(new
|
|
21730
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21844
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21845
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21731
21846
|
* )
|
|
21732
21847
|
*
|
|
21733
21848
|
* Effect.runPromiseExit(program).then(() =>
|
|
21734
21849
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21735
|
-
* // Output: { occurrences: Map(1) { "
|
|
21850
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21736
21851
|
* )
|
|
21737
21852
|
* ```
|
|
21738
21853
|
*
|
|
@@ -21767,18 +21882,20 @@ export const trackErrors: {
|
|
|
21767
21882
|
*
|
|
21768
21883
|
* @example
|
|
21769
21884
|
* ```ts
|
|
21770
|
-
* import { Effect, Metric } from "effect"
|
|
21885
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21886
|
+
*
|
|
21887
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21771
21888
|
*
|
|
21772
21889
|
* // Track error types using frequency metric
|
|
21773
21890
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21774
21891
|
*
|
|
21775
|
-
* const program = Effect.fail(new
|
|
21776
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21892
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21893
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21777
21894
|
* )
|
|
21778
21895
|
*
|
|
21779
21896
|
* Effect.runPromiseExit(program).then(() =>
|
|
21780
21897
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21781
|
-
* // Output: { occurrences: Map(1) { "
|
|
21898
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21782
21899
|
* )
|
|
21783
21900
|
* ```
|
|
21784
21901
|
*
|
|
@@ -21813,18 +21930,20 @@ export const trackErrors: {
|
|
|
21813
21930
|
*
|
|
21814
21931
|
* @example
|
|
21815
21932
|
* ```ts
|
|
21816
|
-
* import { Effect, Metric } from "effect"
|
|
21933
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21934
|
+
*
|
|
21935
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21817
21936
|
*
|
|
21818
21937
|
* // Track error types using frequency metric
|
|
21819
21938
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21820
21939
|
*
|
|
21821
|
-
* const program = Effect.fail(new
|
|
21822
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21940
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21941
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21823
21942
|
* )
|
|
21824
21943
|
*
|
|
21825
21944
|
* Effect.runPromiseExit(program).then(() =>
|
|
21826
21945
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21827
|
-
* // Output: { occurrences: Map(1) { "
|
|
21946
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21828
21947
|
* )
|
|
21829
21948
|
* ```
|
|
21830
21949
|
*
|
|
@@ -21859,18 +21978,20 @@ export const trackErrors: {
|
|
|
21859
21978
|
*
|
|
21860
21979
|
* @example
|
|
21861
21980
|
* ```ts
|
|
21862
|
-
* import { Effect, Metric } from "effect"
|
|
21981
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21982
|
+
*
|
|
21983
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21863
21984
|
*
|
|
21864
21985
|
* // Track error types using frequency metric
|
|
21865
21986
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21866
21987
|
*
|
|
21867
|
-
* const program = Effect.fail(new
|
|
21868
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21988
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21989
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21869
21990
|
* )
|
|
21870
21991
|
*
|
|
21871
21992
|
* Effect.runPromiseExit(program).then(() =>
|
|
21872
21993
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21873
|
-
* // Output: { occurrences: Map(1) { "
|
|
21994
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21874
21995
|
* )
|
|
21875
21996
|
* ```
|
|
21876
21997
|
*
|
|
@@ -21909,18 +22030,20 @@ export const trackErrors: {
|
|
|
21909
22030
|
*
|
|
21910
22031
|
* @example
|
|
21911
22032
|
* ```ts
|
|
21912
|
-
* import { Effect, Metric } from "effect"
|
|
22033
|
+
* import { Data, Effect, Metric } from "effect"
|
|
22034
|
+
*
|
|
22035
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21913
22036
|
*
|
|
21914
22037
|
* // Track error types using frequency metric
|
|
21915
22038
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21916
22039
|
*
|
|
21917
|
-
* const program = Effect.fail(new
|
|
21918
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
22040
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
22041
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21919
22042
|
* )
|
|
21920
22043
|
*
|
|
21921
22044
|
* Effect.runPromiseExit(program).then(() =>
|
|
21922
22045
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21923
|
-
* // Output: { occurrences: Map(1) { "
|
|
22046
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21924
22047
|
* )
|
|
21925
22048
|
* ```
|
|
21926
22049
|
*
|
|
@@ -23210,18 +23333,20 @@ export const satisfiesSuccessType = <A>() => <A2 extends A, E, R>(effect: Effect
|
|
|
23210
23333
|
*
|
|
23211
23334
|
* @example
|
|
23212
23335
|
* ```ts
|
|
23213
|
-
* import { Effect } from "effect"
|
|
23336
|
+
* import { Data, Effect } from "effect"
|
|
23337
|
+
*
|
|
23338
|
+
* class ValidationError extends Data.TaggedError("ValidationError")<{}> {}
|
|
23214
23339
|
*
|
|
23215
|
-
* // Define a constraint that the error type must be
|
|
23216
|
-
* const satisfiesError = Effect.satisfiesErrorType<
|
|
23340
|
+
* // Define a constraint that the error type must be a ValidationError
|
|
23341
|
+
* const satisfiesError = Effect.satisfiesErrorType<ValidationError>()
|
|
23217
23342
|
*
|
|
23218
|
-
* // This works - Effect<number,
|
|
23219
|
-
* const validEffect = satisfiesError(Effect.fail(new
|
|
23343
|
+
* // This works - Effect<number, ValidationError, never> extends the constrained type
|
|
23344
|
+
* const validEffect = satisfiesError(Effect.fail(new ValidationError()))
|
|
23220
23345
|
*
|
|
23221
23346
|
* // This would cause a TypeScript compilation error:
|
|
23222
23347
|
* // const invalidEffect = satisfiesError(Effect.fail("string error"))
|
|
23223
23348
|
* // ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
23224
|
-
* // Type 'string' is not assignable to type '
|
|
23349
|
+
* // Type 'string' is not assignable to type 'ValidationError'
|
|
23225
23350
|
* ```
|
|
23226
23351
|
*
|
|
23227
23352
|
* @since 4.0.0
|