effect 4.0.0-beta.27 → 4.0.0-beta.29
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/Brand.d.ts +1 -1
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/ConfigProvider.d.ts +1 -1
- package/dist/Cron.d.ts +1 -1
- package/dist/Data.d.ts +1 -1
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js.map +1 -1
- package/dist/Effect.d.ts +300 -184
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +99 -61
- package/dist/Effect.js.map +1 -1
- package/dist/Encoding.d.ts +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/Function.d.ts +1 -9
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +2 -10
- package/dist/Function.js.map +1 -1
- package/dist/Graph.d.ts +1 -1
- package/dist/Newtype.d.ts +291 -0
- package/dist/Newtype.d.ts.map +1 -0
- package/dist/Newtype.js +161 -0
- package/dist/Newtype.js.map +1 -0
- package/dist/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 +142 -80
- 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 +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/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +1 -1
- package/dist/SchemaAST.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 +71 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -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/Prompt.js +35 -8
- 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/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +3 -7
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientError.d.ts +7 -7
- package/dist/unstable/http/HttpClientRequest.d.ts +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/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 +7 -2
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +33 -15
- 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/AtomRegistry.js +26 -2
- package/dist/unstable/reactivity/AtomRegistry.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/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/Brand.ts +1 -1
- package/src/Data.ts +1 -2
- package/src/Effect.ts +300 -184
- package/src/Exit.ts +24 -12
- package/src/Fiber.ts +1 -0
- package/src/Function.ts +2 -10
- package/src/Newtype.ts +308 -0
- package/src/References.ts +6 -1
- package/src/RequestResolver.ts +20 -20
- package/src/Schedule.ts +142 -80
- package/src/Scheduler.ts +12 -0
- package/src/Schema.ts +4 -2
- package/src/SchemaAST.ts +1 -4
- package/src/Stdio.ts +8 -4
- package/src/Stream.ts +8 -4
- package/src/Types.ts +1 -23
- package/src/index.ts +72 -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/Prompt.ts +31 -9
- package/src/unstable/http/Cookies.ts +84 -0
- package/src/unstable/http/HttpClient.ts +5 -6
- 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/HttpApiGroup.ts +1 -0
- package/src/unstable/reactivity/Atom.ts +62 -35
- package/src/unstable/reactivity/AtomHttpApi.ts +45 -11
- package/src/unstable/reactivity/AtomRegistry.ts +30 -2
- 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/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)
|
|
@@ -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
|
*
|
|
@@ -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
|
* })
|
|
@@ -9441,9 +9521,11 @@ export const when: {
|
|
|
9441
9521
|
* @example
|
|
9442
9522
|
* ```ts
|
|
9443
9523
|
* // Title: Handling Both Success and Failure Cases
|
|
9444
|
-
* import { Effect } from "effect"
|
|
9524
|
+
* import { Data, Effect } from "effect"
|
|
9525
|
+
*
|
|
9526
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9445
9527
|
*
|
|
9446
|
-
* const success: Effect.Effect<number,
|
|
9528
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9447
9529
|
*
|
|
9448
9530
|
* const program1 = Effect.match(success, {
|
|
9449
9531
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9454,8 +9536,8 @@ export const when: {
|
|
|
9454
9536
|
* Effect.runPromise(program1).then(console.log)
|
|
9455
9537
|
* // Output: "success: 42"
|
|
9456
9538
|
*
|
|
9457
|
-
* const failure: Effect.Effect<number,
|
|
9458
|
-
* new
|
|
9539
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9540
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9459
9541
|
* )
|
|
9460
9542
|
*
|
|
9461
9543
|
* const program2 = Effect.match(failure, {
|
|
@@ -9497,9 +9579,11 @@ export const match: {
|
|
|
9497
9579
|
* @example
|
|
9498
9580
|
* ```ts
|
|
9499
9581
|
* // Title: Handling Both Success and Failure Cases
|
|
9500
|
-
* import { Effect } from "effect"
|
|
9582
|
+
* import { Data, Effect } from "effect"
|
|
9501
9583
|
*
|
|
9502
|
-
*
|
|
9584
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9585
|
+
*
|
|
9586
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9503
9587
|
*
|
|
9504
9588
|
* const program1 = Effect.match(success, {
|
|
9505
9589
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9510,8 +9594,8 @@ export const match: {
|
|
|
9510
9594
|
* Effect.runPromise(program1).then(console.log)
|
|
9511
9595
|
* // Output: "success: 42"
|
|
9512
9596
|
*
|
|
9513
|
-
* const failure: Effect.Effect<number,
|
|
9514
|
-
* new
|
|
9597
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9598
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9515
9599
|
* )
|
|
9516
9600
|
*
|
|
9517
9601
|
* const program2 = Effect.match(failure, {
|
|
@@ -9558,9 +9642,11 @@ export const match: {
|
|
|
9558
9642
|
* @example
|
|
9559
9643
|
* ```ts
|
|
9560
9644
|
* // Title: Handling Both Success and Failure Cases
|
|
9561
|
-
* import { Effect } from "effect"
|
|
9645
|
+
* import { Data, Effect } from "effect"
|
|
9646
|
+
*
|
|
9647
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9562
9648
|
*
|
|
9563
|
-
* const success: Effect.Effect<number,
|
|
9649
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9564
9650
|
*
|
|
9565
9651
|
* const program1 = Effect.match(success, {
|
|
9566
9652
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -9571,8 +9657,8 @@ export const match: {
|
|
|
9571
9657
|
* Effect.runPromise(program1).then(console.log)
|
|
9572
9658
|
* // Output: "success: 42"
|
|
9573
9659
|
*
|
|
9574
|
-
* const failure: Effect.Effect<number,
|
|
9575
|
-
* new
|
|
9660
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9661
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9576
9662
|
* )
|
|
9577
9663
|
*
|
|
9578
9664
|
* const program2 = Effect.match(failure, {
|
|
@@ -10002,9 +10088,11 @@ export const matchCauseEffectEager: {
|
|
|
10002
10088
|
*
|
|
10003
10089
|
* @example
|
|
10004
10090
|
* ```ts
|
|
10005
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
10091
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
10006
10092
|
*
|
|
10007
|
-
*
|
|
10093
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
10094
|
+
*
|
|
10095
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
10008
10096
|
*
|
|
10009
10097
|
* const program = Effect.matchCauseEffect(task, {
|
|
10010
10098
|
* onFailure: (cause) =>
|
|
@@ -10054,9 +10142,11 @@ export const matchCauseEffect: {
|
|
|
10054
10142
|
*
|
|
10055
10143
|
* @example
|
|
10056
10144
|
* ```ts
|
|
10057
|
-
* 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 }> {}
|
|
10058
10148
|
*
|
|
10059
|
-
* const task = Effect.fail(new
|
|
10149
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
10060
10150
|
*
|
|
10061
10151
|
* const program = Effect.matchCauseEffect(task, {
|
|
10062
10152
|
* onFailure: (cause) =>
|
|
@@ -10111,9 +10201,11 @@ export const matchCauseEffect: {
|
|
|
10111
10201
|
*
|
|
10112
10202
|
* @example
|
|
10113
10203
|
* ```ts
|
|
10114
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
10204
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
10115
10205
|
*
|
|
10116
|
-
*
|
|
10206
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
10207
|
+
*
|
|
10208
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
10117
10209
|
*
|
|
10118
10210
|
* const program = Effect.matchCauseEffect(task, {
|
|
10119
10211
|
* onFailure: (cause) =>
|
|
@@ -10177,11 +10269,13 @@ export const matchCauseEffect: {
|
|
|
10177
10269
|
* @example
|
|
10178
10270
|
* ```ts
|
|
10179
10271
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
10180
|
-
* import { Effect } from "effect"
|
|
10272
|
+
* import { Data, Effect } from "effect"
|
|
10181
10273
|
*
|
|
10182
|
-
*
|
|
10183
|
-
*
|
|
10184
|
-
*
|
|
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!" })
|
|
10185
10279
|
* )
|
|
10186
10280
|
*
|
|
10187
10281
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -10237,11 +10331,13 @@ export const matchEffect: {
|
|
|
10237
10331
|
* @example
|
|
10238
10332
|
* ```ts
|
|
10239
10333
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
10240
|
-
* import { Effect } from "effect"
|
|
10334
|
+
* import { Data, Effect } from "effect"
|
|
10335
|
+
*
|
|
10336
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
10241
10337
|
*
|
|
10242
|
-
* const success: Effect.Effect<number,
|
|
10243
|
-
* const failure: Effect.Effect<number,
|
|
10244
|
-
* 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!" })
|
|
10245
10341
|
* )
|
|
10246
10342
|
*
|
|
10247
10343
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -10302,11 +10398,13 @@ export const matchEffect: {
|
|
|
10302
10398
|
* @example
|
|
10303
10399
|
* ```ts
|
|
10304
10400
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
10305
|
-
* import { Effect } from "effect"
|
|
10401
|
+
* import { Data, Effect } from "effect"
|
|
10306
10402
|
*
|
|
10307
|
-
*
|
|
10308
|
-
*
|
|
10309
|
-
*
|
|
10403
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
10404
|
+
*
|
|
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!" })
|
|
10310
10408
|
* )
|
|
10311
10409
|
*
|
|
10312
10410
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -12150,9 +12248,11 @@ export const ensuring: {
|
|
|
12150
12248
|
*
|
|
12151
12249
|
* @example
|
|
12152
12250
|
* ```ts
|
|
12153
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12251
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
12154
12252
|
*
|
|
12155
|
-
*
|
|
12253
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12254
|
+
*
|
|
12255
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
12156
12256
|
*
|
|
12157
12257
|
* const program = Effect.onError(
|
|
12158
12258
|
* task,
|
|
@@ -12161,8 +12261,8 @@ export const ensuring: {
|
|
|
12161
12261
|
*
|
|
12162
12262
|
* Effect.runPromise(program).catch(console.error)
|
|
12163
12263
|
* // Output:
|
|
12164
|
-
* // Cleanup on error:
|
|
12165
|
-
* //
|
|
12264
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12265
|
+
* // TaskError: Something went wrong
|
|
12166
12266
|
* ```
|
|
12167
12267
|
*
|
|
12168
12268
|
* @since 2.0.0
|
|
@@ -12175,9 +12275,11 @@ export const onError: {
|
|
|
12175
12275
|
*
|
|
12176
12276
|
* @example
|
|
12177
12277
|
* ```ts
|
|
12178
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12278
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
12179
12279
|
*
|
|
12180
|
-
*
|
|
12280
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12281
|
+
*
|
|
12282
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
12181
12283
|
*
|
|
12182
12284
|
* const program = Effect.onError(
|
|
12183
12285
|
* task,
|
|
@@ -12186,8 +12288,8 @@ export const onError: {
|
|
|
12186
12288
|
*
|
|
12187
12289
|
* Effect.runPromise(program).catch(console.error)
|
|
12188
12290
|
* // Output:
|
|
12189
|
-
* // Cleanup on error:
|
|
12190
|
-
* //
|
|
12291
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12292
|
+
* // TaskError: Something went wrong
|
|
12191
12293
|
* ```
|
|
12192
12294
|
*
|
|
12193
12295
|
* @since 2.0.0
|
|
@@ -12200,9 +12302,11 @@ export const onError: {
|
|
|
12200
12302
|
*
|
|
12201
12303
|
* @example
|
|
12202
12304
|
* ```ts
|
|
12203
|
-
* import { Cause, Console, Effect } from "effect"
|
|
12305
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
12204
12306
|
*
|
|
12205
|
-
*
|
|
12307
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
12308
|
+
*
|
|
12309
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
12206
12310
|
*
|
|
12207
12311
|
* const program = Effect.onError(
|
|
12208
12312
|
* task,
|
|
@@ -12211,8 +12315,8 @@ export const onError: {
|
|
|
12211
12315
|
*
|
|
12212
12316
|
* Effect.runPromise(program).catch(console.error)
|
|
12213
12317
|
* // Output:
|
|
12214
|
-
* // Cleanup on error:
|
|
12215
|
-
* //
|
|
12318
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
12319
|
+
* // TaskError: Something went wrong
|
|
12216
12320
|
* ```
|
|
12217
12321
|
*
|
|
12218
12322
|
* @since 2.0.0
|
|
@@ -15429,7 +15533,7 @@ export const withParentSpan: {
|
|
|
15429
15533
|
* )
|
|
15430
15534
|
*
|
|
15431
15535
|
* const program = Effect.gen(function*() {
|
|
15432
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15536
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15433
15537
|
* yield* Console.log(name)
|
|
15434
15538
|
* })
|
|
15435
15539
|
* ```
|
|
@@ -15464,7 +15568,7 @@ export const request: {
|
|
|
15464
15568
|
* )
|
|
15465
15569
|
*
|
|
15466
15570
|
* const program = Effect.gen(function*() {
|
|
15467
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15571
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15468
15572
|
* yield* Console.log(name)
|
|
15469
15573
|
* })
|
|
15470
15574
|
* ```
|
|
@@ -15499,7 +15603,7 @@ export const request: {
|
|
|
15499
15603
|
* )
|
|
15500
15604
|
*
|
|
15501
15605
|
* const program = Effect.gen(function*() {
|
|
15502
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
15606
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
15503
15607
|
* yield* Console.log(name)
|
|
15504
15608
|
* })
|
|
15505
15609
|
* ```
|
|
@@ -21730,18 +21834,20 @@ export const trackSuccesses: {
|
|
|
21730
21834
|
*
|
|
21731
21835
|
* @example
|
|
21732
21836
|
* ```ts
|
|
21733
|
-
* import { Effect, Metric } from "effect"
|
|
21837
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21838
|
+
*
|
|
21839
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21734
21840
|
*
|
|
21735
21841
|
* // Track error types using frequency metric
|
|
21736
21842
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21737
21843
|
*
|
|
21738
|
-
* const program = Effect.fail(new
|
|
21739
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21844
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21845
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21740
21846
|
* )
|
|
21741
21847
|
*
|
|
21742
21848
|
* Effect.runPromiseExit(program).then(() =>
|
|
21743
21849
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21744
|
-
* // Output: { occurrences: Map(1) { "
|
|
21850
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21745
21851
|
* )
|
|
21746
21852
|
* ```
|
|
21747
21853
|
*
|
|
@@ -21776,18 +21882,20 @@ export const trackErrors: {
|
|
|
21776
21882
|
*
|
|
21777
21883
|
* @example
|
|
21778
21884
|
* ```ts
|
|
21779
|
-
* import { Effect, Metric } from "effect"
|
|
21885
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21886
|
+
*
|
|
21887
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21780
21888
|
*
|
|
21781
21889
|
* // Track error types using frequency metric
|
|
21782
21890
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21783
21891
|
*
|
|
21784
|
-
* const program = Effect.fail(new
|
|
21785
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21892
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21893
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21786
21894
|
* )
|
|
21787
21895
|
*
|
|
21788
21896
|
* Effect.runPromiseExit(program).then(() =>
|
|
21789
21897
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21790
|
-
* // Output: { occurrences: Map(1) { "
|
|
21898
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21791
21899
|
* )
|
|
21792
21900
|
* ```
|
|
21793
21901
|
*
|
|
@@ -21822,18 +21930,20 @@ export const trackErrors: {
|
|
|
21822
21930
|
*
|
|
21823
21931
|
* @example
|
|
21824
21932
|
* ```ts
|
|
21825
|
-
* import { Effect, Metric } from "effect"
|
|
21933
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21934
|
+
*
|
|
21935
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21826
21936
|
*
|
|
21827
21937
|
* // Track error types using frequency metric
|
|
21828
21938
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21829
21939
|
*
|
|
21830
|
-
* const program = Effect.fail(new
|
|
21831
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21940
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21941
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21832
21942
|
* )
|
|
21833
21943
|
*
|
|
21834
21944
|
* Effect.runPromiseExit(program).then(() =>
|
|
21835
21945
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21836
|
-
* // Output: { occurrences: Map(1) { "
|
|
21946
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21837
21947
|
* )
|
|
21838
21948
|
* ```
|
|
21839
21949
|
*
|
|
@@ -21868,18 +21978,20 @@ export const trackErrors: {
|
|
|
21868
21978
|
*
|
|
21869
21979
|
* @example
|
|
21870
21980
|
* ```ts
|
|
21871
|
-
* import { Effect, Metric } from "effect"
|
|
21981
|
+
* import { Data, Effect, Metric } from "effect"
|
|
21982
|
+
*
|
|
21983
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21872
21984
|
*
|
|
21873
21985
|
* // Track error types using frequency metric
|
|
21874
21986
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21875
21987
|
*
|
|
21876
|
-
* const program = Effect.fail(new
|
|
21877
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
21988
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
21989
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21878
21990
|
* )
|
|
21879
21991
|
*
|
|
21880
21992
|
* Effect.runPromiseExit(program).then(() =>
|
|
21881
21993
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21882
|
-
* // Output: { occurrences: Map(1) { "
|
|
21994
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21883
21995
|
* )
|
|
21884
21996
|
* ```
|
|
21885
21997
|
*
|
|
@@ -21918,18 +22030,20 @@ export const trackErrors: {
|
|
|
21918
22030
|
*
|
|
21919
22031
|
* @example
|
|
21920
22032
|
* ```ts
|
|
21921
|
-
* import { Effect, Metric } from "effect"
|
|
22033
|
+
* import { Data, Effect, Metric } from "effect"
|
|
22034
|
+
*
|
|
22035
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
21922
22036
|
*
|
|
21923
22037
|
* // Track error types using frequency metric
|
|
21924
22038
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
21925
22039
|
*
|
|
21926
|
-
* const program = Effect.fail(new
|
|
21927
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
22040
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
22041
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
21928
22042
|
* )
|
|
21929
22043
|
*
|
|
21930
22044
|
* Effect.runPromiseExit(program).then(() =>
|
|
21931
22045
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
21932
|
-
* // Output: { occurrences: Map(1) { "
|
|
22046
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
21933
22047
|
* )
|
|
21934
22048
|
* ```
|
|
21935
22049
|
*
|
|
@@ -23219,18 +23333,20 @@ export const satisfiesSuccessType = <A>() => <A2 extends A, E, R>(effect: Effect
|
|
|
23219
23333
|
*
|
|
23220
23334
|
* @example
|
|
23221
23335
|
* ```ts
|
|
23222
|
-
* import { Effect } from "effect"
|
|
23336
|
+
* import { Data, Effect } from "effect"
|
|
23337
|
+
*
|
|
23338
|
+
* class ValidationError extends Data.TaggedError("ValidationError")<{}> {}
|
|
23223
23339
|
*
|
|
23224
|
-
* // Define a constraint that the error type must be
|
|
23225
|
-
* const satisfiesError = Effect.satisfiesErrorType<
|
|
23340
|
+
* // Define a constraint that the error type must be a ValidationError
|
|
23341
|
+
* const satisfiesError = Effect.satisfiesErrorType<ValidationError>()
|
|
23226
23342
|
*
|
|
23227
|
-
* // This works - Effect<number,
|
|
23228
|
-
* 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()))
|
|
23229
23345
|
*
|
|
23230
23346
|
* // This would cause a TypeScript compilation error:
|
|
23231
23347
|
* // const invalidEffect = satisfiesError(Effect.fail("string error"))
|
|
23232
23348
|
* // ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
23233
|
-
* // Type 'string' is not assignable to type '
|
|
23349
|
+
* // Type 'string' is not assignable to type 'ValidationError'
|
|
23234
23350
|
* ```
|
|
23235
23351
|
*
|
|
23236
23352
|
* @since 4.0.0
|