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/dist/Effect.d.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
|
|
@@ -111,13 +113,15 @@ declare const TypeId: "~effect/Effect";
|
|
|
111
113
|
*
|
|
112
114
|
* @example
|
|
113
115
|
* ```ts
|
|
114
|
-
* import { Effect } from "effect"
|
|
116
|
+
* import { Data, Effect } from "effect"
|
|
117
|
+
*
|
|
118
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
115
119
|
*
|
|
116
120
|
* // A simple effect that succeeds with a value
|
|
117
121
|
* const success = Effect.succeed(42)
|
|
118
122
|
*
|
|
119
|
-
* // An effect that
|
|
120
|
-
* const risky = Effect.fail(new
|
|
123
|
+
* // An effect that will always fail
|
|
124
|
+
* const risky = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
121
125
|
*
|
|
122
126
|
* // Effects can be composed using generator functions
|
|
123
127
|
* const program = Effect.gen(function*() {
|
|
@@ -367,13 +371,15 @@ export declare namespace All {
|
|
|
367
371
|
* @category Models
|
|
368
372
|
* @example
|
|
369
373
|
* ```ts
|
|
370
|
-
* import { Effect } from "effect"
|
|
374
|
+
* import { Data, Effect } from "effect"
|
|
375
|
+
*
|
|
376
|
+
* class OopsError extends Data.TaggedError("OopsError")<{}> {}
|
|
371
377
|
*
|
|
372
378
|
* // EffectAny represents an Effect with any type parameters
|
|
373
379
|
* const effects: Array<Effect.All.EffectAny> = [
|
|
374
380
|
* Effect.succeed(42),
|
|
375
381
|
* Effect.succeed("hello"),
|
|
376
|
-
* Effect.fail(new
|
|
382
|
+
* Effect.fail(new OopsError())
|
|
377
383
|
* ]
|
|
378
384
|
* ```
|
|
379
385
|
*/
|
|
@@ -1352,16 +1358,18 @@ export declare const promise: <A>(evaluate: (signal: AbortSignal) => PromiseLike
|
|
|
1352
1358
|
*
|
|
1353
1359
|
* @example Custom Error Handling
|
|
1354
1360
|
* ```ts
|
|
1355
|
-
* import { Effect } from "effect"
|
|
1361
|
+
* import { Data, Effect } from "effect"
|
|
1362
|
+
*
|
|
1363
|
+
* class TodoFetchError extends Data.TaggedError("TodoFetchError")<{ readonly cause: unknown }> {}
|
|
1356
1364
|
*
|
|
1357
1365
|
* const getTodo = (id: number) =>
|
|
1358
1366
|
* Effect.tryPromise({
|
|
1359
1367
|
* try: () => fetch(`https://jsonplaceholder.typicode.com/todos/${id}`),
|
|
1360
1368
|
* // remap the error
|
|
1361
|
-
* catch: (
|
|
1369
|
+
* catch: (cause) => new TodoFetchError({ cause })
|
|
1362
1370
|
* })
|
|
1363
1371
|
*
|
|
1364
|
-
* // ┌─── Effect<Response,
|
|
1372
|
+
* // ┌─── Effect<Response, TodoFetchError, never>
|
|
1365
1373
|
* // ▼
|
|
1366
1374
|
* const program = getTodo(1)
|
|
1367
1375
|
* ```
|
|
@@ -1737,16 +1745,18 @@ export declare const bind: {
|
|
|
1737
1745
|
*
|
|
1738
1746
|
* @example
|
|
1739
1747
|
* ```ts
|
|
1740
|
-
* import { Effect } from "effect"
|
|
1748
|
+
* import { Data, Effect } from "effect"
|
|
1749
|
+
*
|
|
1750
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
1741
1751
|
*
|
|
1742
1752
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
1743
1753
|
*
|
|
1744
1754
|
* const applyDiscount = (
|
|
1745
1755
|
* total: number,
|
|
1746
1756
|
* discountRate: number
|
|
1747
|
-
* ): Effect.Effect<number,
|
|
1757
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
1748
1758
|
* discountRate === 0
|
|
1749
|
-
* ? Effect.fail(new
|
|
1759
|
+
* ? Effect.fail(new DiscountRateError())
|
|
1750
1760
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
1751
1761
|
*
|
|
1752
1762
|
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
@@ -1786,16 +1796,18 @@ export declare const gen: {
|
|
|
1786
1796
|
*
|
|
1787
1797
|
* @example
|
|
1788
1798
|
* ```ts
|
|
1789
|
-
* import { Effect } from "effect"
|
|
1799
|
+
* import { Data, Effect } from "effect"
|
|
1800
|
+
*
|
|
1801
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
1790
1802
|
*
|
|
1791
1803
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
1792
1804
|
*
|
|
1793
1805
|
* const applyDiscount = (
|
|
1794
1806
|
* total: number,
|
|
1795
1807
|
* discountRate: number
|
|
1796
|
-
* ): Effect.Effect<number,
|
|
1808
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
1797
1809
|
* discountRate === 0
|
|
1798
|
-
* ? Effect.fail(new
|
|
1810
|
+
* ? Effect.fail(new DiscountRateError())
|
|
1799
1811
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
1800
1812
|
*
|
|
1801
1813
|
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
@@ -1839,16 +1851,18 @@ export declare const gen: {
|
|
|
1839
1851
|
*
|
|
1840
1852
|
* @example
|
|
1841
1853
|
* ```ts
|
|
1842
|
-
* import { Effect } from "effect"
|
|
1854
|
+
* import { Data, Effect } from "effect"
|
|
1855
|
+
*
|
|
1856
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
1843
1857
|
*
|
|
1844
1858
|
* const addServiceCharge = (amount: number) => amount + 1
|
|
1845
1859
|
*
|
|
1846
1860
|
* const applyDiscount = (
|
|
1847
1861
|
* total: number,
|
|
1848
1862
|
* discountRate: number
|
|
1849
|
-
* ): Effect.Effect<number,
|
|
1863
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
1850
1864
|
* discountRate === 0
|
|
1851
|
-
* ? Effect.fail(new
|
|
1865
|
+
* ? Effect.fail(new DiscountRateError())
|
|
1852
1866
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
1853
1867
|
*
|
|
1854
1868
|
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
@@ -1903,12 +1917,14 @@ export declare namespace gen {
|
|
|
1903
1917
|
* @example
|
|
1904
1918
|
* ```ts
|
|
1905
1919
|
* // Title: Creating a Failed Effect
|
|
1906
|
-
* import { Effect } from "effect"
|
|
1920
|
+
* import { Data, Effect } from "effect"
|
|
1907
1921
|
*
|
|
1908
|
-
*
|
|
1922
|
+
* class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
|
|
1923
|
+
*
|
|
1924
|
+
* // ┌─── Effect<never, OperationFailedError, never>
|
|
1909
1925
|
* // ▼
|
|
1910
1926
|
* const failure = Effect.fail(
|
|
1911
|
-
* new
|
|
1927
|
+
* new OperationFailedError()
|
|
1912
1928
|
* )
|
|
1913
1929
|
* ```
|
|
1914
1930
|
*
|
|
@@ -1924,9 +1940,11 @@ export declare const fail: <E>(error: E) => Effect<never, E>;
|
|
|
1924
1940
|
*
|
|
1925
1941
|
* @example
|
|
1926
1942
|
* ```ts
|
|
1927
|
-
* import { Effect } from "effect"
|
|
1943
|
+
* import { Data, Effect } from "effect"
|
|
1944
|
+
*
|
|
1945
|
+
* class ProgramError extends Data.TaggedError("ProgramError")<{ readonly failedAt: Date }> {}
|
|
1928
1946
|
*
|
|
1929
|
-
* const program = Effect.failSync(() => new
|
|
1947
|
+
* const program = Effect.failSync(() => new ProgramError({ failedAt: new Date() }))
|
|
1930
1948
|
*
|
|
1931
1949
|
* Effect.runPromiseExit(program).then(console.log)
|
|
1932
1950
|
* // Output: { _id: 'Exit', _tag: 'Failure', cause: ... }
|
|
@@ -2073,12 +2091,14 @@ export {
|
|
|
2073
2091
|
*
|
|
2074
2092
|
* @example Custom Error Handling
|
|
2075
2093
|
* ```ts
|
|
2076
|
-
* import { Effect } from "effect"
|
|
2094
|
+
* import { Data, Effect } from "effect"
|
|
2095
|
+
*
|
|
2096
|
+
* class JsonParsingError extends Data.TaggedError("JsonParsingError")<{ readonly cause: unknown }> {}
|
|
2077
2097
|
*
|
|
2078
2098
|
* const parseJSON = (input: string) =>
|
|
2079
2099
|
* Effect.try({
|
|
2080
2100
|
* try: () => JSON.parse(input),
|
|
2081
|
-
* catch: (
|
|
2101
|
+
* catch: (cause) => new JsonParsingError({ cause })
|
|
2082
2102
|
* })
|
|
2083
2103
|
*
|
|
2084
2104
|
* Effect.runPromiseExit(parseJSON("invalid json")).then(console.log)
|
|
@@ -2200,17 +2220,17 @@ export declare const fromOption: <A>(option: Option<A>) => Effect<A, Cause.NoSuc
|
|
|
2200
2220
|
* ```ts
|
|
2201
2221
|
* import { Console, Effect } from "effect"
|
|
2202
2222
|
*
|
|
2203
|
-
* const input: string | null
|
|
2204
|
-
*
|
|
2205
|
-
* const program = Effect.gen(function*() {
|
|
2223
|
+
* const program = Effect.fn(function*(input: string | null) {
|
|
2206
2224
|
* const value = yield* Effect.fromNullishOr(input)
|
|
2207
2225
|
* yield* Console.log(value)
|
|
2208
|
-
* }
|
|
2226
|
+
* },
|
|
2209
2227
|
* Effect.catch(() => Console.log("missing"))
|
|
2210
2228
|
* )
|
|
2211
2229
|
*
|
|
2212
|
-
* Effect.runPromise(program)
|
|
2230
|
+
* Effect.runPromise(program(null))
|
|
2213
2231
|
* // Output: missing
|
|
2232
|
+
* Effect.runPromise(program("hello"))
|
|
2233
|
+
* // Output: hello
|
|
2214
2234
|
* ```
|
|
2215
2235
|
*
|
|
2216
2236
|
* @since 4.0.0
|
|
@@ -2271,15 +2291,17 @@ export declare const fromYieldable: <Self extends Yieldable.Any, A, E, R>(yielda
|
|
|
2271
2291
|
*
|
|
2272
2292
|
* @example
|
|
2273
2293
|
* ```ts
|
|
2274
|
-
* import { Effect, pipe } from "effect"
|
|
2294
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2295
|
+
*
|
|
2296
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2275
2297
|
*
|
|
2276
2298
|
* // Function to apply a discount safely to a transaction amount
|
|
2277
2299
|
* const applyDiscount = (
|
|
2278
2300
|
* total: number,
|
|
2279
2301
|
* discountRate: number
|
|
2280
|
-
* ): Effect.Effect<number,
|
|
2302
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2281
2303
|
* discountRate === 0
|
|
2282
|
-
* ? Effect.fail(new
|
|
2304
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2283
2305
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2284
2306
|
*
|
|
2285
2307
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2333,15 +2355,17 @@ export declare const flatMap: {
|
|
|
2333
2355
|
*
|
|
2334
2356
|
* @example
|
|
2335
2357
|
* ```ts
|
|
2336
|
-
* import { Effect, pipe } from "effect"
|
|
2358
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2359
|
+
*
|
|
2360
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2337
2361
|
*
|
|
2338
2362
|
* // Function to apply a discount safely to a transaction amount
|
|
2339
2363
|
* const applyDiscount = (
|
|
2340
2364
|
* total: number,
|
|
2341
2365
|
* discountRate: number
|
|
2342
|
-
* ): Effect.Effect<number,
|
|
2366
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2343
2367
|
* discountRate === 0
|
|
2344
|
-
* ? Effect.fail(new
|
|
2368
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2345
2369
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2346
2370
|
*
|
|
2347
2371
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2395,15 +2419,17 @@ export declare const flatMap: {
|
|
|
2395
2419
|
*
|
|
2396
2420
|
* @example
|
|
2397
2421
|
* ```ts
|
|
2398
|
-
* import { Effect, pipe } from "effect"
|
|
2422
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2423
|
+
*
|
|
2424
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2399
2425
|
*
|
|
2400
2426
|
* // Function to apply a discount safely to a transaction amount
|
|
2401
2427
|
* const applyDiscount = (
|
|
2402
2428
|
* total: number,
|
|
2403
2429
|
* discountRate: number
|
|
2404
|
-
* ): Effect.Effect<number,
|
|
2430
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2405
2431
|
* discountRate === 0
|
|
2406
|
-
* ? Effect.fail(new
|
|
2432
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2407
2433
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2408
2434
|
*
|
|
2409
2435
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2488,15 +2514,17 @@ export declare const flatten: <A, E, R, E2, R2>(self: Effect<Effect<A, E, R>, E2
|
|
|
2488
2514
|
*
|
|
2489
2515
|
* @example Applying a Discount Based on Fetched Amount
|
|
2490
2516
|
* ```ts
|
|
2491
|
-
* import { Effect, pipe } from "effect"
|
|
2517
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2518
|
+
*
|
|
2519
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2492
2520
|
*
|
|
2493
2521
|
* // Function to apply a discount safely to a transaction amount
|
|
2494
2522
|
* const applyDiscount = (
|
|
2495
2523
|
* total: number,
|
|
2496
2524
|
* discountRate: number
|
|
2497
|
-
* ): Effect.Effect<number,
|
|
2525
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2498
2526
|
* discountRate === 0
|
|
2499
|
-
* ? Effect.fail(new
|
|
2527
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2500
2528
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2501
2529
|
*
|
|
2502
2530
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2569,15 +2597,17 @@ export declare const andThen: {
|
|
|
2569
2597
|
*
|
|
2570
2598
|
* @example Applying a Discount Based on Fetched Amount
|
|
2571
2599
|
* ```ts
|
|
2572
|
-
* import { Effect, pipe } from "effect"
|
|
2600
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2601
|
+
*
|
|
2602
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2573
2603
|
*
|
|
2574
2604
|
* // Function to apply a discount safely to a transaction amount
|
|
2575
2605
|
* const applyDiscount = (
|
|
2576
2606
|
* total: number,
|
|
2577
2607
|
* discountRate: number
|
|
2578
|
-
* ): Effect.Effect<number,
|
|
2608
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2579
2609
|
* discountRate === 0
|
|
2580
|
-
* ? Effect.fail(new
|
|
2610
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2581
2611
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2582
2612
|
*
|
|
2583
2613
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2650,15 +2680,17 @@ export declare const andThen: {
|
|
|
2650
2680
|
*
|
|
2651
2681
|
* @example Applying a Discount Based on Fetched Amount
|
|
2652
2682
|
* ```ts
|
|
2653
|
-
* import { Effect, pipe } from "effect"
|
|
2683
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2684
|
+
*
|
|
2685
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2654
2686
|
*
|
|
2655
2687
|
* // Function to apply a discount safely to a transaction amount
|
|
2656
2688
|
* const applyDiscount = (
|
|
2657
2689
|
* total: number,
|
|
2658
2690
|
* discountRate: number
|
|
2659
|
-
* ): Effect.Effect<number,
|
|
2691
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2660
2692
|
* discountRate === 0
|
|
2661
|
-
* ? Effect.fail(new
|
|
2693
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2662
2694
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2663
2695
|
*
|
|
2664
2696
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2731,15 +2763,17 @@ export declare const andThen: {
|
|
|
2731
2763
|
*
|
|
2732
2764
|
* @example Applying a Discount Based on Fetched Amount
|
|
2733
2765
|
* ```ts
|
|
2734
|
-
* import { Effect, pipe } from "effect"
|
|
2766
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2767
|
+
*
|
|
2768
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2735
2769
|
*
|
|
2736
2770
|
* // Function to apply a discount safely to a transaction amount
|
|
2737
2771
|
* const applyDiscount = (
|
|
2738
2772
|
* total: number,
|
|
2739
2773
|
* discountRate: number
|
|
2740
|
-
* ): Effect.Effect<number,
|
|
2774
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2741
2775
|
* discountRate === 0
|
|
2742
|
-
* ? Effect.fail(new
|
|
2776
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2743
2777
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2744
2778
|
*
|
|
2745
2779
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2812,15 +2846,17 @@ export declare const andThen: {
|
|
|
2812
2846
|
*
|
|
2813
2847
|
* @example Applying a Discount Based on Fetched Amount
|
|
2814
2848
|
* ```ts
|
|
2815
|
-
* import { Effect, pipe } from "effect"
|
|
2849
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2850
|
+
*
|
|
2851
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2816
2852
|
*
|
|
2817
2853
|
* // Function to apply a discount safely to a transaction amount
|
|
2818
2854
|
* const applyDiscount = (
|
|
2819
2855
|
* total: number,
|
|
2820
2856
|
* discountRate: number
|
|
2821
|
-
* ): Effect.Effect<number,
|
|
2857
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2822
2858
|
* discountRate === 0
|
|
2823
|
-
* ? Effect.fail(new
|
|
2859
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2824
2860
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2825
2861
|
*
|
|
2826
2862
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2878,16 +2914,18 @@ export declare const andThen: {
|
|
|
2878
2914
|
* @example
|
|
2879
2915
|
* ```ts
|
|
2880
2916
|
* // Title: Logging a step in a pipeline
|
|
2881
|
-
* import { Effect, pipe } from "effect"
|
|
2917
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2882
2918
|
* import { Console } from "effect"
|
|
2883
2919
|
*
|
|
2920
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2921
|
+
*
|
|
2884
2922
|
* // Function to apply a discount safely to a transaction amount
|
|
2885
2923
|
* const applyDiscount = (
|
|
2886
2924
|
* total: number,
|
|
2887
2925
|
* discountRate: number
|
|
2888
|
-
* ): Effect.Effect<number,
|
|
2926
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2889
2927
|
* discountRate === 0
|
|
2890
|
-
* ? Effect.fail(new
|
|
2928
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2891
2929
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2892
2930
|
*
|
|
2893
2931
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2937,16 +2975,18 @@ export declare const tap: {
|
|
|
2937
2975
|
* @example
|
|
2938
2976
|
* ```ts
|
|
2939
2977
|
* // Title: Logging a step in a pipeline
|
|
2940
|
-
* import { Effect, pipe } from "effect"
|
|
2978
|
+
* import { Data, Effect, pipe } from "effect"
|
|
2941
2979
|
* import { Console } from "effect"
|
|
2942
2980
|
*
|
|
2981
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
2982
|
+
*
|
|
2943
2983
|
* // Function to apply a discount safely to a transaction amount
|
|
2944
2984
|
* const applyDiscount = (
|
|
2945
2985
|
* total: number,
|
|
2946
2986
|
* discountRate: number
|
|
2947
|
-
* ): Effect.Effect<number,
|
|
2987
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
2948
2988
|
* discountRate === 0
|
|
2949
|
-
* ? Effect.fail(new
|
|
2989
|
+
* ? Effect.fail(new DiscountRateError())
|
|
2950
2990
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
2951
2991
|
*
|
|
2952
2992
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -2996,16 +3036,18 @@ export declare const tap: {
|
|
|
2996
3036
|
* @example
|
|
2997
3037
|
* ```ts
|
|
2998
3038
|
* // Title: Logging a step in a pipeline
|
|
2999
|
-
* import { Effect, pipe } from "effect"
|
|
3039
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3000
3040
|
* import { Console } from "effect"
|
|
3001
3041
|
*
|
|
3042
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3043
|
+
*
|
|
3002
3044
|
* // Function to apply a discount safely to a transaction amount
|
|
3003
3045
|
* const applyDiscount = (
|
|
3004
3046
|
* total: number,
|
|
3005
3047
|
* discountRate: number
|
|
3006
|
-
* ): Effect.Effect<number,
|
|
3048
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3007
3049
|
* discountRate === 0
|
|
3008
|
-
* ? Effect.fail(new
|
|
3050
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3009
3051
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3010
3052
|
*
|
|
3011
3053
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3055,16 +3097,18 @@ export declare const tap: {
|
|
|
3055
3097
|
* @example
|
|
3056
3098
|
* ```ts
|
|
3057
3099
|
* // Title: Logging a step in a pipeline
|
|
3058
|
-
* import { Effect, pipe } from "effect"
|
|
3100
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3059
3101
|
* import { Console } from "effect"
|
|
3060
3102
|
*
|
|
3103
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3104
|
+
*
|
|
3061
3105
|
* // Function to apply a discount safely to a transaction amount
|
|
3062
3106
|
* const applyDiscount = (
|
|
3063
3107
|
* total: number,
|
|
3064
3108
|
* discountRate: number
|
|
3065
|
-
* ): Effect.Effect<number,
|
|
3109
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3066
3110
|
* discountRate === 0
|
|
3067
|
-
* ? Effect.fail(new
|
|
3111
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3068
3112
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3069
3113
|
*
|
|
3070
3114
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -3114,16 +3158,18 @@ export declare const tap: {
|
|
|
3114
3158
|
* @example
|
|
3115
3159
|
* ```ts
|
|
3116
3160
|
* // Title: Logging a step in a pipeline
|
|
3117
|
-
* import { Effect, pipe } from "effect"
|
|
3161
|
+
* import { Data, Effect, pipe } from "effect"
|
|
3118
3162
|
* import { Console } from "effect"
|
|
3119
3163
|
*
|
|
3164
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
3165
|
+
*
|
|
3120
3166
|
* // Function to apply a discount safely to a transaction amount
|
|
3121
3167
|
* const applyDiscount = (
|
|
3122
3168
|
* total: number,
|
|
3123
3169
|
* discountRate: number
|
|
3124
|
-
* ): Effect.Effect<number,
|
|
3170
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
3125
3171
|
* discountRate === 0
|
|
3126
|
-
* ? Effect.fail(new
|
|
3172
|
+
* ? Effect.fail(new DiscountRateError())
|
|
3127
3173
|
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
3128
3174
|
*
|
|
3129
3175
|
* // Simulated asynchronous task to fetch a transaction amount from database
|
|
@@ -5278,17 +5324,19 @@ export declare const catchCauseFilter: {
|
|
|
5278
5324
|
*
|
|
5279
5325
|
* @example
|
|
5280
5326
|
* ```ts
|
|
5281
|
-
* import { Effect } from "effect"
|
|
5327
|
+
* import { Data, Effect } from "effect"
|
|
5328
|
+
*
|
|
5329
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5282
5330
|
*
|
|
5283
5331
|
* // ┌─── Effect<number, string, never>
|
|
5284
5332
|
* // ▼
|
|
5285
5333
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5286
5334
|
*
|
|
5287
|
-
* // ┌─── Effect<number,
|
|
5335
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5288
5336
|
* // ▼
|
|
5289
5337
|
* const mapped = Effect.mapError(
|
|
5290
5338
|
* simulatedTask,
|
|
5291
|
-
* (message) => new
|
|
5339
|
+
* (message) => new TaskError({ message })
|
|
5292
5340
|
* )
|
|
5293
5341
|
* ```
|
|
5294
5342
|
*
|
|
@@ -5311,17 +5359,19 @@ export declare const mapError: {
|
|
|
5311
5359
|
*
|
|
5312
5360
|
* @example
|
|
5313
5361
|
* ```ts
|
|
5314
|
-
* import { Effect } from "effect"
|
|
5362
|
+
* import { Data, Effect } from "effect"
|
|
5363
|
+
*
|
|
5364
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5315
5365
|
*
|
|
5316
5366
|
* // ┌─── Effect<number, string, never>
|
|
5317
5367
|
* // ▼
|
|
5318
5368
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5319
5369
|
*
|
|
5320
|
-
* // ┌─── Effect<number,
|
|
5370
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5321
5371
|
* // ▼
|
|
5322
5372
|
* const mapped = Effect.mapError(
|
|
5323
5373
|
* simulatedTask,
|
|
5324
|
-
* (message) => new
|
|
5374
|
+
* (message) => new TaskError({ message })
|
|
5325
5375
|
* )
|
|
5326
5376
|
* ```
|
|
5327
5377
|
*
|
|
@@ -5344,17 +5394,19 @@ export declare const mapError: {
|
|
|
5344
5394
|
*
|
|
5345
5395
|
* @example
|
|
5346
5396
|
* ```ts
|
|
5347
|
-
* import { Effect } from "effect"
|
|
5397
|
+
* import { Data, Effect } from "effect"
|
|
5398
|
+
*
|
|
5399
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5348
5400
|
*
|
|
5349
5401
|
* // ┌─── Effect<number, string, never>
|
|
5350
5402
|
* // ▼
|
|
5351
5403
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5352
5404
|
*
|
|
5353
|
-
* // ┌─── Effect<number,
|
|
5405
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
5354
5406
|
* // ▼
|
|
5355
5407
|
* const mapped = Effect.mapError(
|
|
5356
5408
|
* simulatedTask,
|
|
5357
|
-
* (message) => new
|
|
5409
|
+
* (message) => new TaskError({ message })
|
|
5358
5410
|
* )
|
|
5359
5411
|
* ```
|
|
5360
5412
|
*
|
|
@@ -5375,16 +5427,18 @@ export declare const mapError: {
|
|
|
5375
5427
|
*
|
|
5376
5428
|
* @example
|
|
5377
5429
|
* ```ts
|
|
5378
|
-
* import { Effect } from "effect"
|
|
5430
|
+
* import { Data, Effect } from "effect"
|
|
5431
|
+
*
|
|
5432
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5379
5433
|
*
|
|
5380
5434
|
* // ┌─── Effect<number, string, never>
|
|
5381
5435
|
* // ▼
|
|
5382
5436
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5383
5437
|
*
|
|
5384
|
-
* // ┌─── Effect<boolean,
|
|
5438
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5385
5439
|
* // ▼
|
|
5386
5440
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5387
|
-
* onFailure: (message) => new
|
|
5441
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5388
5442
|
* onSuccess: (n) => n > 0
|
|
5389
5443
|
* })
|
|
5390
5444
|
* ```
|
|
@@ -5408,16 +5462,18 @@ export declare const mapBoth: {
|
|
|
5408
5462
|
*
|
|
5409
5463
|
* @example
|
|
5410
5464
|
* ```ts
|
|
5411
|
-
* import { Effect } from "effect"
|
|
5465
|
+
* import { Data, Effect } from "effect"
|
|
5466
|
+
*
|
|
5467
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5412
5468
|
*
|
|
5413
5469
|
* // ┌─── Effect<number, string, never>
|
|
5414
5470
|
* // ▼
|
|
5415
5471
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5416
5472
|
*
|
|
5417
|
-
* // ┌─── Effect<boolean,
|
|
5473
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5418
5474
|
* // ▼
|
|
5419
5475
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5420
|
-
* onFailure: (message) => new
|
|
5476
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5421
5477
|
* onSuccess: (n) => n > 0
|
|
5422
5478
|
* })
|
|
5423
5479
|
* ```
|
|
@@ -5444,16 +5500,18 @@ export declare const mapBoth: {
|
|
|
5444
5500
|
*
|
|
5445
5501
|
* @example
|
|
5446
5502
|
* ```ts
|
|
5447
|
-
* import { Effect } from "effect"
|
|
5503
|
+
* import { Data, Effect } from "effect"
|
|
5504
|
+
*
|
|
5505
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
5448
5506
|
*
|
|
5449
5507
|
* // ┌─── Effect<number, string, never>
|
|
5450
5508
|
* // ▼
|
|
5451
5509
|
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
5452
5510
|
*
|
|
5453
|
-
* // ┌─── Effect<boolean,
|
|
5511
|
+
* // ┌─── Effect<boolean, TaskError, never>
|
|
5454
5512
|
* // ▼
|
|
5455
5513
|
* const modified = Effect.mapBoth(simulatedTask, {
|
|
5456
|
-
* onFailure: (message) => new
|
|
5514
|
+
* onFailure: (message) => new TaskError({ message }),
|
|
5457
5515
|
* onSuccess: (n) => n > 0
|
|
5458
5516
|
* })
|
|
5459
5517
|
* ```
|
|
@@ -5487,11 +5545,13 @@ export declare const mapBoth: {
|
|
|
5487
5545
|
* @example
|
|
5488
5546
|
* ```ts
|
|
5489
5547
|
* // Title: Propagating an Error as a Defect
|
|
5490
|
-
* import { Effect } from "effect"
|
|
5548
|
+
* import { Data, Effect } from "effect"
|
|
5549
|
+
*
|
|
5550
|
+
* class DivideByZeroError extends Data.TaggedError("DivideByZeroError")<{}> {}
|
|
5491
5551
|
*
|
|
5492
5552
|
* const divide = (a: number, b: number) =>
|
|
5493
5553
|
* b === 0
|
|
5494
|
-
* ? Effect.fail(new
|
|
5554
|
+
* ? Effect.fail(new DivideByZeroError())
|
|
5495
5555
|
* : Effect.succeed(a / b)
|
|
5496
5556
|
*
|
|
5497
5557
|
* // ┌─── Effect<number, never, never>
|
|
@@ -5500,7 +5560,7 @@ export declare const mapBoth: {
|
|
|
5500
5560
|
*
|
|
5501
5561
|
* Effect.runPromise(program).catch(console.error)
|
|
5502
5562
|
* // Output:
|
|
5503
|
-
* // (FiberFailure)
|
|
5563
|
+
* // (FiberFailure) DivideByZeroError
|
|
5504
5564
|
* // ...stack trace...
|
|
5505
5565
|
* ```
|
|
5506
5566
|
*
|
|
@@ -6096,7 +6156,7 @@ export declare const tapDefect: {
|
|
|
6096
6156
|
* attempts++
|
|
6097
6157
|
* yield* Console.log(`Attempt ${attempts}`)
|
|
6098
6158
|
* if (attempts < 3) {
|
|
6099
|
-
* yield* Effect.fail("Not ready")
|
|
6159
|
+
* return yield* Effect.fail("Not ready")
|
|
6100
6160
|
* }
|
|
6101
6161
|
* return "Ready"
|
|
6102
6162
|
* })
|
|
@@ -6205,13 +6265,15 @@ export declare namespace Retry {
|
|
|
6205
6265
|
*
|
|
6206
6266
|
* @example
|
|
6207
6267
|
* ```ts
|
|
6208
|
-
* import { Effect, Schedule } from "effect"
|
|
6268
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6269
|
+
*
|
|
6270
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6209
6271
|
*
|
|
6210
6272
|
* let attempt = 0
|
|
6211
|
-
* const task = Effect.callback<string,
|
|
6273
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6212
6274
|
* attempt++
|
|
6213
6275
|
* if (attempt <= 2) {
|
|
6214
|
-
* resume(Effect.fail(new
|
|
6276
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6215
6277
|
* } else {
|
|
6216
6278
|
* resume(Effect.succeed("Success!"))
|
|
6217
6279
|
* }
|
|
@@ -6254,13 +6316,15 @@ export declare const retry: {
|
|
|
6254
6316
|
*
|
|
6255
6317
|
* @example
|
|
6256
6318
|
* ```ts
|
|
6257
|
-
* import { Effect, Schedule } from "effect"
|
|
6319
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6320
|
+
*
|
|
6321
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6258
6322
|
*
|
|
6259
6323
|
* let attempt = 0
|
|
6260
|
-
* const task = Effect.callback<string,
|
|
6324
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6261
6325
|
* attempt++
|
|
6262
6326
|
* if (attempt <= 2) {
|
|
6263
|
-
* resume(Effect.fail(new
|
|
6327
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6264
6328
|
* } else {
|
|
6265
6329
|
* resume(Effect.succeed("Success!"))
|
|
6266
6330
|
* }
|
|
@@ -6303,13 +6367,15 @@ export declare const retry: {
|
|
|
6303
6367
|
*
|
|
6304
6368
|
* @example
|
|
6305
6369
|
* ```ts
|
|
6306
|
-
* import { Effect, Schedule } from "effect"
|
|
6370
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6371
|
+
*
|
|
6372
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6307
6373
|
*
|
|
6308
6374
|
* let attempt = 0
|
|
6309
|
-
* const task = Effect.callback<string,
|
|
6375
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6310
6376
|
* attempt++
|
|
6311
6377
|
* if (attempt <= 2) {
|
|
6312
|
-
* resume(Effect.fail(new
|
|
6378
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6313
6379
|
* } else {
|
|
6314
6380
|
* resume(Effect.succeed("Success!"))
|
|
6315
6381
|
* }
|
|
@@ -6352,13 +6418,15 @@ export declare const retry: {
|
|
|
6352
6418
|
*
|
|
6353
6419
|
* @example
|
|
6354
6420
|
* ```ts
|
|
6355
|
-
* import { Effect, Schedule } from "effect"
|
|
6421
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6422
|
+
*
|
|
6423
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6356
6424
|
*
|
|
6357
6425
|
* let attempt = 0
|
|
6358
|
-
* const task = Effect.callback<string,
|
|
6426
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6359
6427
|
* attempt++
|
|
6360
6428
|
* if (attempt <= 2) {
|
|
6361
|
-
* resume(Effect.fail(new
|
|
6429
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6362
6430
|
* } else {
|
|
6363
6431
|
* resume(Effect.succeed("Success!"))
|
|
6364
6432
|
* }
|
|
@@ -6401,13 +6469,15 @@ export declare const retry: {
|
|
|
6401
6469
|
*
|
|
6402
6470
|
* @example
|
|
6403
6471
|
* ```ts
|
|
6404
|
-
* import { Effect, Schedule } from "effect"
|
|
6472
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6473
|
+
*
|
|
6474
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6405
6475
|
*
|
|
6406
6476
|
* let attempt = 0
|
|
6407
|
-
* const task = Effect.callback<string,
|
|
6477
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6408
6478
|
* attempt++
|
|
6409
6479
|
* if (attempt <= 2) {
|
|
6410
|
-
* resume(Effect.fail(new
|
|
6480
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6411
6481
|
* } else {
|
|
6412
6482
|
* resume(Effect.succeed("Success!"))
|
|
6413
6483
|
* }
|
|
@@ -6450,13 +6520,15 @@ export declare const retry: {
|
|
|
6450
6520
|
*
|
|
6451
6521
|
* @example
|
|
6452
6522
|
* ```ts
|
|
6453
|
-
* import { Effect, Schedule } from "effect"
|
|
6523
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6524
|
+
*
|
|
6525
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6454
6526
|
*
|
|
6455
6527
|
* let attempt = 0
|
|
6456
|
-
* const task = Effect.callback<string,
|
|
6528
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6457
6529
|
* attempt++
|
|
6458
6530
|
* if (attempt <= 2) {
|
|
6459
|
-
* resume(Effect.fail(new
|
|
6531
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6460
6532
|
* } else {
|
|
6461
6533
|
* resume(Effect.succeed("Success!"))
|
|
6462
6534
|
* }
|
|
@@ -6499,13 +6571,15 @@ export declare const retry: {
|
|
|
6499
6571
|
*
|
|
6500
6572
|
* @example
|
|
6501
6573
|
* ```ts
|
|
6502
|
-
* import { Effect, Schedule } from "effect"
|
|
6574
|
+
* import { Data, Effect, Schedule } from "effect"
|
|
6575
|
+
*
|
|
6576
|
+
* class AttemptError extends Data.TaggedError("AttemptError")<{ readonly attempt: number }> {}
|
|
6503
6577
|
*
|
|
6504
6578
|
* let attempt = 0
|
|
6505
|
-
* const task = Effect.callback<string,
|
|
6579
|
+
* const task = Effect.callback<string, AttemptError>((resume) => {
|
|
6506
6580
|
* attempt++
|
|
6507
6581
|
* if (attempt <= 2) {
|
|
6508
|
-
* resume(Effect.fail(new
|
|
6582
|
+
* resume(Effect.fail(new AttemptError({ attempt })))
|
|
6509
6583
|
* } else {
|
|
6510
6584
|
* resume(Effect.succeed("Success!"))
|
|
6511
6585
|
* }
|
|
@@ -6546,14 +6620,16 @@ export declare const retry: {
|
|
|
6546
6620
|
*
|
|
6547
6621
|
* @example
|
|
6548
6622
|
* ```ts
|
|
6549
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
6623
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
6624
|
+
*
|
|
6625
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
6550
6626
|
*
|
|
6551
6627
|
* let attempt = 0
|
|
6552
6628
|
* const networkRequest = Effect.gen(function*() {
|
|
6553
6629
|
* attempt++
|
|
6554
6630
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
6555
6631
|
* if (attempt < 3) {
|
|
6556
|
-
* return yield* Effect.fail(new
|
|
6632
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
6557
6633
|
* }
|
|
6558
6634
|
* return "Network data"
|
|
6559
6635
|
* })
|
|
@@ -6601,14 +6677,16 @@ export declare const retryOrElse: {
|
|
|
6601
6677
|
*
|
|
6602
6678
|
* @example
|
|
6603
6679
|
* ```ts
|
|
6604
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
6680
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
6681
|
+
*
|
|
6682
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
6605
6683
|
*
|
|
6606
6684
|
* let attempt = 0
|
|
6607
6685
|
* const networkRequest = Effect.gen(function*() {
|
|
6608
6686
|
* attempt++
|
|
6609
6687
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
6610
6688
|
* if (attempt < 3) {
|
|
6611
|
-
* return yield* Effect.fail(new
|
|
6689
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
6612
6690
|
* }
|
|
6613
6691
|
* return "Network data"
|
|
6614
6692
|
* })
|
|
@@ -6656,14 +6734,16 @@ export declare const retryOrElse: {
|
|
|
6656
6734
|
*
|
|
6657
6735
|
* @example
|
|
6658
6736
|
* ```ts
|
|
6659
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
6737
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
6738
|
+
*
|
|
6739
|
+
* class NetworkTimeoutError extends Data.TaggedError("NetworkTimeoutError")<{}> {}
|
|
6660
6740
|
*
|
|
6661
6741
|
* let attempt = 0
|
|
6662
6742
|
* const networkRequest = Effect.gen(function*() {
|
|
6663
6743
|
* attempt++
|
|
6664
6744
|
* yield* Console.log(`Network attempt ${attempt}`)
|
|
6665
6745
|
* if (attempt < 3) {
|
|
6666
|
-
* return yield* Effect.fail(new
|
|
6746
|
+
* return yield* Effect.fail(new NetworkTimeoutError())
|
|
6667
6747
|
* }
|
|
6668
6748
|
* return "Network data"
|
|
6669
6749
|
* })
|
|
@@ -6820,7 +6900,10 @@ export declare const ignoreCause: <Arg extends Effect<any, any, any> | {
|
|
|
6820
6900
|
*
|
|
6821
6901
|
* const fetchUrl = Effect.gen(function*() {
|
|
6822
6902
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
6823
|
-
*
|
|
6903
|
+
* if (endpoint.url === "bad") {
|
|
6904
|
+
* return yield* Effect.fail("Unavailable")
|
|
6905
|
+
* }
|
|
6906
|
+
* return endpoint.url
|
|
6824
6907
|
* })
|
|
6825
6908
|
*
|
|
6826
6909
|
* const plan = ExecutionPlan.make(
|
|
@@ -6851,7 +6934,10 @@ export declare const withExecutionPlan: {
|
|
|
6851
6934
|
*
|
|
6852
6935
|
* const fetchUrl = Effect.gen(function*() {
|
|
6853
6936
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
6854
|
-
*
|
|
6937
|
+
* if (endpoint.url === "bad") {
|
|
6938
|
+
* return yield* Effect.fail("Unavailable")
|
|
6939
|
+
* }
|
|
6940
|
+
* return endpoint.url
|
|
6855
6941
|
* })
|
|
6856
6942
|
*
|
|
6857
6943
|
* const plan = ExecutionPlan.make(
|
|
@@ -6887,7 +6973,10 @@ export declare const withExecutionPlan: {
|
|
|
6887
6973
|
*
|
|
6888
6974
|
* const fetchUrl = Effect.gen(function*() {
|
|
6889
6975
|
* const endpoint = yield* Effect.service(Endpoint)
|
|
6890
|
-
*
|
|
6976
|
+
* if (endpoint.url === "bad") {
|
|
6977
|
+
* return yield* Effect.fail("Unavailable")
|
|
6978
|
+
* }
|
|
6979
|
+
* return endpoint.url
|
|
6891
6980
|
* })
|
|
6892
6981
|
*
|
|
6893
6982
|
* const plan = ExecutionPlan.make(
|
|
@@ -8664,9 +8753,11 @@ export declare const when: {
|
|
|
8664
8753
|
* @example
|
|
8665
8754
|
* ```ts
|
|
8666
8755
|
* // Title: Handling Both Success and Failure Cases
|
|
8667
|
-
* import { Effect } from "effect"
|
|
8756
|
+
* import { Data, Effect } from "effect"
|
|
8757
|
+
*
|
|
8758
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
8668
8759
|
*
|
|
8669
|
-
* const success: Effect.Effect<number,
|
|
8760
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
8670
8761
|
*
|
|
8671
8762
|
* const program1 = Effect.match(success, {
|
|
8672
8763
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -8677,8 +8768,8 @@ export declare const when: {
|
|
|
8677
8768
|
* Effect.runPromise(program1).then(console.log)
|
|
8678
8769
|
* // Output: "success: 42"
|
|
8679
8770
|
*
|
|
8680
|
-
* const failure: Effect.Effect<number,
|
|
8681
|
-
* new
|
|
8771
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
8772
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
8682
8773
|
* )
|
|
8683
8774
|
*
|
|
8684
8775
|
* const program2 = Effect.match(failure, {
|
|
@@ -8716,9 +8807,11 @@ export declare const match: {
|
|
|
8716
8807
|
* @example
|
|
8717
8808
|
* ```ts
|
|
8718
8809
|
* // Title: Handling Both Success and Failure Cases
|
|
8719
|
-
* import { Effect } from "effect"
|
|
8810
|
+
* import { Data, Effect } from "effect"
|
|
8720
8811
|
*
|
|
8721
|
-
*
|
|
8812
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
8813
|
+
*
|
|
8814
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
8722
8815
|
*
|
|
8723
8816
|
* const program1 = Effect.match(success, {
|
|
8724
8817
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -8729,8 +8822,8 @@ export declare const match: {
|
|
|
8729
8822
|
* Effect.runPromise(program1).then(console.log)
|
|
8730
8823
|
* // Output: "success: 42"
|
|
8731
8824
|
*
|
|
8732
|
-
* const failure: Effect.Effect<number,
|
|
8733
|
-
* new
|
|
8825
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
8826
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
8734
8827
|
* )
|
|
8735
8828
|
*
|
|
8736
8829
|
* const program2 = Effect.match(failure, {
|
|
@@ -8771,9 +8864,11 @@ export declare const match: {
|
|
|
8771
8864
|
* @example
|
|
8772
8865
|
* ```ts
|
|
8773
8866
|
* // Title: Handling Both Success and Failure Cases
|
|
8774
|
-
* import { Effect } from "effect"
|
|
8867
|
+
* import { Data, Effect } from "effect"
|
|
8868
|
+
*
|
|
8869
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
8775
8870
|
*
|
|
8776
|
-
* const success: Effect.Effect<number,
|
|
8871
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
8777
8872
|
*
|
|
8778
8873
|
* const program1 = Effect.match(success, {
|
|
8779
8874
|
* onFailure: (error) => `failure: ${error.message}`,
|
|
@@ -8784,8 +8879,8 @@ export declare const match: {
|
|
|
8784
8879
|
* Effect.runPromise(program1).then(console.log)
|
|
8785
8880
|
* // Output: "success: 42"
|
|
8786
8881
|
*
|
|
8787
|
-
* const failure: Effect.Effect<number,
|
|
8788
|
-
* new
|
|
8882
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
8883
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
8789
8884
|
* )
|
|
8790
8885
|
*
|
|
8791
8886
|
* const program2 = Effect.match(failure, {
|
|
@@ -9187,9 +9282,11 @@ export declare const matchCauseEffectEager: {
|
|
|
9187
9282
|
*
|
|
9188
9283
|
* @example
|
|
9189
9284
|
* ```ts
|
|
9190
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
9285
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
9191
9286
|
*
|
|
9192
|
-
*
|
|
9287
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
9288
|
+
*
|
|
9289
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
9193
9290
|
*
|
|
9194
9291
|
* const program = Effect.matchCauseEffect(task, {
|
|
9195
9292
|
* onFailure: (cause) =>
|
|
@@ -9239,9 +9336,11 @@ export declare const matchCauseEffect: {
|
|
|
9239
9336
|
*
|
|
9240
9337
|
* @example
|
|
9241
9338
|
* ```ts
|
|
9242
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
9339
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
9340
|
+
*
|
|
9341
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
9243
9342
|
*
|
|
9244
|
-
* const task = Effect.fail(new
|
|
9343
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
9245
9344
|
*
|
|
9246
9345
|
* const program = Effect.matchCauseEffect(task, {
|
|
9247
9346
|
* onFailure: (cause) =>
|
|
@@ -9294,9 +9393,11 @@ export declare const matchCauseEffect: {
|
|
|
9294
9393
|
*
|
|
9295
9394
|
* @example
|
|
9296
9395
|
* ```ts
|
|
9297
|
-
* import { Cause, Console, Effect, Result } from "effect"
|
|
9396
|
+
* import { Cause, Console, Data, Effect, Result } from "effect"
|
|
9397
|
+
*
|
|
9398
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
9298
9399
|
*
|
|
9299
|
-
* const task = Effect.fail(new
|
|
9400
|
+
* const task = Effect.fail(new TaskError({ message: "Task failed" }))
|
|
9300
9401
|
*
|
|
9301
9402
|
* const program = Effect.matchCauseEffect(task, {
|
|
9302
9403
|
* onFailure: (cause) =>
|
|
@@ -9356,11 +9457,13 @@ export declare const matchCauseEffect: {
|
|
|
9356
9457
|
* @example
|
|
9357
9458
|
* ```ts
|
|
9358
9459
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
9359
|
-
* import { Effect } from "effect"
|
|
9460
|
+
* import { Data, Effect } from "effect"
|
|
9360
9461
|
*
|
|
9361
|
-
*
|
|
9362
|
-
*
|
|
9363
|
-
*
|
|
9462
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9463
|
+
*
|
|
9464
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9465
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9466
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9364
9467
|
* )
|
|
9365
9468
|
*
|
|
9366
9469
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -9416,11 +9519,13 @@ export declare const matchEffect: {
|
|
|
9416
9519
|
* @example
|
|
9417
9520
|
* ```ts
|
|
9418
9521
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
9419
|
-
* import { Effect } from "effect"
|
|
9522
|
+
* import { Data, Effect } from "effect"
|
|
9523
|
+
*
|
|
9524
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9420
9525
|
*
|
|
9421
|
-
* const success: Effect.Effect<number,
|
|
9422
|
-
* const failure: Effect.Effect<number,
|
|
9423
|
-
* new
|
|
9526
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9527
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9528
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9424
9529
|
* )
|
|
9425
9530
|
*
|
|
9426
9531
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -9479,11 +9584,13 @@ export declare const matchEffect: {
|
|
|
9479
9584
|
* @example
|
|
9480
9585
|
* ```ts
|
|
9481
9586
|
* // Title: Handling Both Success and Failure Cases with Side Effects
|
|
9482
|
-
* import { Effect } from "effect"
|
|
9587
|
+
* import { Data, Effect } from "effect"
|
|
9588
|
+
*
|
|
9589
|
+
* class ExampleError extends Data.TaggedError("ExampleError")<{ readonly message: string }> {}
|
|
9483
9590
|
*
|
|
9484
|
-
* const success: Effect.Effect<number,
|
|
9485
|
-
* const failure: Effect.Effect<number,
|
|
9486
|
-
* new
|
|
9591
|
+
* const success: Effect.Effect<number, ExampleError> = Effect.succeed(42)
|
|
9592
|
+
* const failure: Effect.Effect<number, ExampleError> = Effect.fail(
|
|
9593
|
+
* new ExampleError({ message: "Uh oh!" })
|
|
9487
9594
|
* )
|
|
9488
9595
|
*
|
|
9489
9596
|
* const program1 = Effect.matchEffect(success, {
|
|
@@ -9612,7 +9719,7 @@ export declare const isSuccess: <A, E, R>(self: Effect<A, E, R>) => Effect<boole
|
|
|
9612
9719
|
* @since 2.0.0
|
|
9613
9720
|
* @category Environment
|
|
9614
9721
|
*/
|
|
9615
|
-
export declare const services: <R>() => Effect<ServiceMap.ServiceMap<R>, never, R>;
|
|
9722
|
+
export declare const services: <R = never>() => Effect<ServiceMap.ServiceMap<R>, never, R>;
|
|
9616
9723
|
/**
|
|
9617
9724
|
* Transforms the current service map using the provided function.
|
|
9618
9725
|
*
|
|
@@ -9674,7 +9781,7 @@ export declare const servicesWith: <R, A, E, R2>(f: (services: ServiceMap.Servic
|
|
|
9674
9781
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
9675
9782
|
*
|
|
9676
9783
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
9677
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
9784
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
9678
9785
|
* })
|
|
9679
9786
|
*
|
|
9680
9787
|
* const program = Effect.gen(function*() {
|
|
@@ -9708,7 +9815,7 @@ export declare const provide: {
|
|
|
9708
9815
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
9709
9816
|
*
|
|
9710
9817
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
9711
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
9818
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
9712
9819
|
* })
|
|
9713
9820
|
*
|
|
9714
9821
|
* const program = Effect.gen(function*() {
|
|
@@ -9744,7 +9851,7 @@ export declare const provide: {
|
|
|
9744
9851
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
9745
9852
|
*
|
|
9746
9853
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
9747
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
9854
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
9748
9855
|
* })
|
|
9749
9856
|
*
|
|
9750
9857
|
* const program = Effect.gen(function*() {
|
|
@@ -9780,7 +9887,7 @@ export declare const provide: {
|
|
|
9780
9887
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
9781
9888
|
*
|
|
9782
9889
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
9783
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
9890
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
9784
9891
|
* })
|
|
9785
9892
|
*
|
|
9786
9893
|
* const program = Effect.gen(function*() {
|
|
@@ -9814,7 +9921,7 @@ export declare const provide: {
|
|
|
9814
9921
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
9815
9922
|
*
|
|
9816
9923
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
9817
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
9924
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
9818
9925
|
* })
|
|
9819
9926
|
*
|
|
9820
9927
|
* const program = Effect.gen(function*() {
|
|
@@ -9850,7 +9957,7 @@ export declare const provide: {
|
|
|
9850
9957
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
9851
9958
|
*
|
|
9852
9959
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
9853
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
9960
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
9854
9961
|
* })
|
|
9855
9962
|
*
|
|
9856
9963
|
* const program = Effect.gen(function*() {
|
|
@@ -9886,7 +9993,7 @@ export declare const provide: {
|
|
|
9886
9993
|
* const Database = ServiceMap.Service<Database>("Database")
|
|
9887
9994
|
*
|
|
9888
9995
|
* const DatabaseLive = Layer.succeed(Database)({
|
|
9889
|
-
* query: (sql: string) => Effect.succeed(`Result for: ${sql}`)
|
|
9996
|
+
* query: Effect.fn("Database.query")((sql: string) => Effect.succeed(`Result for: ${sql}`))
|
|
9890
9997
|
* })
|
|
9891
9998
|
*
|
|
9892
9999
|
* const program = Effect.gen(function*() {
|
|
@@ -11229,9 +11336,11 @@ export declare const ensuring: {
|
|
|
11229
11336
|
*
|
|
11230
11337
|
* @example
|
|
11231
11338
|
* ```ts
|
|
11232
|
-
* import { Cause, Console, Effect } from "effect"
|
|
11339
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
11340
|
+
*
|
|
11341
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
11233
11342
|
*
|
|
11234
|
-
* const task = Effect.fail(new
|
|
11343
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
11235
11344
|
*
|
|
11236
11345
|
* const program = Effect.onError(
|
|
11237
11346
|
* task,
|
|
@@ -11240,8 +11349,8 @@ export declare const ensuring: {
|
|
|
11240
11349
|
*
|
|
11241
11350
|
* Effect.runPromise(program).catch(console.error)
|
|
11242
11351
|
* // Output:
|
|
11243
|
-
* // Cleanup on error:
|
|
11244
|
-
* //
|
|
11352
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
11353
|
+
* // TaskError: Something went wrong
|
|
11245
11354
|
* ```
|
|
11246
11355
|
*
|
|
11247
11356
|
* @since 2.0.0
|
|
@@ -11254,9 +11363,11 @@ export declare const onError: {
|
|
|
11254
11363
|
*
|
|
11255
11364
|
* @example
|
|
11256
11365
|
* ```ts
|
|
11257
|
-
* import { Cause, Console, Effect } from "effect"
|
|
11366
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
11367
|
+
*
|
|
11368
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
11258
11369
|
*
|
|
11259
|
-
* const task = Effect.fail(new
|
|
11370
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
11260
11371
|
*
|
|
11261
11372
|
* const program = Effect.onError(
|
|
11262
11373
|
* task,
|
|
@@ -11265,8 +11376,8 @@ export declare const onError: {
|
|
|
11265
11376
|
*
|
|
11266
11377
|
* Effect.runPromise(program).catch(console.error)
|
|
11267
11378
|
* // Output:
|
|
11268
|
-
* // Cleanup on error:
|
|
11269
|
-
* //
|
|
11379
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
11380
|
+
* // TaskError: Something went wrong
|
|
11270
11381
|
* ```
|
|
11271
11382
|
*
|
|
11272
11383
|
* @since 2.0.0
|
|
@@ -11279,9 +11390,11 @@ export declare const onError: {
|
|
|
11279
11390
|
*
|
|
11280
11391
|
* @example
|
|
11281
11392
|
* ```ts
|
|
11282
|
-
* import { Cause, Console, Effect } from "effect"
|
|
11393
|
+
* import { Cause, Data, Console, Effect } from "effect"
|
|
11394
|
+
*
|
|
11395
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
11283
11396
|
*
|
|
11284
|
-
* const task = Effect.fail(new
|
|
11397
|
+
* const task = Effect.fail(new TaskError({ message: "Something went wrong" }))
|
|
11285
11398
|
*
|
|
11286
11399
|
* const program = Effect.onError(
|
|
11287
11400
|
* task,
|
|
@@ -11290,8 +11403,8 @@ export declare const onError: {
|
|
|
11290
11403
|
*
|
|
11291
11404
|
* Effect.runPromise(program).catch(console.error)
|
|
11292
11405
|
* // Output:
|
|
11293
|
-
* // Cleanup on error:
|
|
11294
|
-
* //
|
|
11406
|
+
* // Cleanup on error: TaskError: Something went wrong
|
|
11407
|
+
* // TaskError: Something went wrong
|
|
11295
11408
|
* ```
|
|
11296
11409
|
*
|
|
11297
11410
|
* @since 2.0.0
|
|
@@ -12059,8 +12172,8 @@ export declare const cachedInvalidateWithTTL: {
|
|
|
12059
12172
|
* import { Effect } from "effect"
|
|
12060
12173
|
*
|
|
12061
12174
|
* const program = Effect.gen(function*() {
|
|
12062
|
-
* yield* Effect.interrupt
|
|
12063
|
-
* yield* Effect.succeed("This won't execute")
|
|
12175
|
+
* return yield* Effect.interrupt
|
|
12176
|
+
* yield* Effect.succeed("This won't execute and is unreachable")
|
|
12064
12177
|
* })
|
|
12065
12178
|
*
|
|
12066
12179
|
* Effect.runPromise(program).catch(console.error)
|
|
@@ -12829,7 +12942,7 @@ export declare const repeat: {
|
|
|
12829
12942
|
* attempt++
|
|
12830
12943
|
* if (attempt <= 2) {
|
|
12831
12944
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
12832
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
12945
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
12833
12946
|
* }
|
|
12834
12947
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
12835
12948
|
* return "success"
|
|
@@ -12879,7 +12992,7 @@ export declare const repeatOrElse: {
|
|
|
12879
12992
|
* attempt++
|
|
12880
12993
|
* if (attempt <= 2) {
|
|
12881
12994
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
12882
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
12995
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
12883
12996
|
* }
|
|
12884
12997
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
12885
12998
|
* return "success"
|
|
@@ -12929,7 +13042,7 @@ export declare const repeatOrElse: {
|
|
|
12929
13042
|
* attempt++
|
|
12930
13043
|
* if (attempt <= 2) {
|
|
12931
13044
|
* yield* Console.log(`Attempt ${attempt} failed`)
|
|
12932
|
-
* yield* Effect.fail(`Error ${attempt}`)
|
|
13045
|
+
* return yield* Effect.fail(`Error ${attempt}`)
|
|
12933
13046
|
* }
|
|
12934
13047
|
* yield* Console.log(`Attempt ${attempt} succeeded`)
|
|
12935
13048
|
* return "success"
|
|
@@ -14328,7 +14441,7 @@ export declare const withParentSpan: {
|
|
|
14328
14441
|
* )
|
|
14329
14442
|
*
|
|
14330
14443
|
* const program = Effect.gen(function*() {
|
|
14331
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
14444
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
14332
14445
|
* yield* Console.log(name)
|
|
14333
14446
|
* })
|
|
14334
14447
|
* ```
|
|
@@ -14359,7 +14472,7 @@ export declare const request: {
|
|
|
14359
14472
|
* )
|
|
14360
14473
|
*
|
|
14361
14474
|
* const program = Effect.gen(function*() {
|
|
14362
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
14475
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
14363
14476
|
* yield* Console.log(name)
|
|
14364
14477
|
* })
|
|
14365
14478
|
* ```
|
|
@@ -14390,7 +14503,7 @@ export declare const request: {
|
|
|
14390
14503
|
* )
|
|
14391
14504
|
*
|
|
14392
14505
|
* const program = Effect.gen(function*() {
|
|
14393
|
-
* const name = yield* Effect.request(GetUser({ id: 1 }),
|
|
14506
|
+
* const name = yield* Effect.request(GetUser({ id: 1 }), resolver)
|
|
14394
14507
|
* yield* Console.log(name)
|
|
14395
14508
|
* })
|
|
14396
14509
|
* ```
|
|
@@ -16786,18 +16899,20 @@ export declare const trackSuccesses: {
|
|
|
16786
16899
|
*
|
|
16787
16900
|
* @example
|
|
16788
16901
|
* ```ts
|
|
16789
|
-
* import { Effect, Metric } from "effect"
|
|
16902
|
+
* import { Data, Effect, Metric } from "effect"
|
|
16903
|
+
*
|
|
16904
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
16790
16905
|
*
|
|
16791
16906
|
* // Track error types using frequency metric
|
|
16792
16907
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
16793
16908
|
*
|
|
16794
|
-
* const program = Effect.fail(new
|
|
16795
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
16909
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
16910
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
16796
16911
|
* )
|
|
16797
16912
|
*
|
|
16798
16913
|
* Effect.runPromiseExit(program).then(() =>
|
|
16799
16914
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
16800
|
-
* // Output: { occurrences: Map(1) { "
|
|
16915
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
16801
16916
|
* )
|
|
16802
16917
|
* ```
|
|
16803
16918
|
*
|
|
@@ -16832,18 +16947,20 @@ export declare const trackErrors: {
|
|
|
16832
16947
|
*
|
|
16833
16948
|
* @example
|
|
16834
16949
|
* ```ts
|
|
16835
|
-
* import { Effect, Metric } from "effect"
|
|
16950
|
+
* import { Data, Effect, Metric } from "effect"
|
|
16951
|
+
*
|
|
16952
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
16836
16953
|
*
|
|
16837
16954
|
* // Track error types using frequency metric
|
|
16838
16955
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
16839
16956
|
*
|
|
16840
|
-
* const program = Effect.fail(new
|
|
16841
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
16957
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
16958
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
16842
16959
|
* )
|
|
16843
16960
|
*
|
|
16844
16961
|
* Effect.runPromiseExit(program).then(() =>
|
|
16845
16962
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
16846
|
-
* // Output: { occurrences: Map(1) { "
|
|
16963
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
16847
16964
|
* )
|
|
16848
16965
|
* ```
|
|
16849
16966
|
*
|
|
@@ -16878,18 +16995,20 @@ export declare const trackErrors: {
|
|
|
16878
16995
|
*
|
|
16879
16996
|
* @example
|
|
16880
16997
|
* ```ts
|
|
16881
|
-
* import { Effect, Metric } from "effect"
|
|
16998
|
+
* import { Data, Effect, Metric } from "effect"
|
|
16999
|
+
*
|
|
17000
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
16882
17001
|
*
|
|
16883
17002
|
* // Track error types using frequency metric
|
|
16884
17003
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
16885
17004
|
*
|
|
16886
|
-
* const program = Effect.fail(new
|
|
16887
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
17005
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
17006
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
16888
17007
|
* )
|
|
16889
17008
|
*
|
|
16890
17009
|
* Effect.runPromiseExit(program).then(() =>
|
|
16891
17010
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
16892
|
-
* // Output: { occurrences: Map(1) { "
|
|
17011
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
16893
17012
|
* )
|
|
16894
17013
|
* ```
|
|
16895
17014
|
*
|
|
@@ -16924,18 +17043,20 @@ export declare const trackErrors: {
|
|
|
16924
17043
|
*
|
|
16925
17044
|
* @example
|
|
16926
17045
|
* ```ts
|
|
16927
|
-
* import { Effect, Metric } from "effect"
|
|
17046
|
+
* import { Data, Effect, Metric } from "effect"
|
|
17047
|
+
*
|
|
17048
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
16928
17049
|
*
|
|
16929
17050
|
* // Track error types using frequency metric
|
|
16930
17051
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
16931
17052
|
*
|
|
16932
|
-
* const program = Effect.fail(new
|
|
16933
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
17053
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
17054
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
16934
17055
|
* )
|
|
16935
17056
|
*
|
|
16936
17057
|
* Effect.runPromiseExit(program).then(() =>
|
|
16937
17058
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
16938
|
-
* // Output: { occurrences: Map(1) { "
|
|
17059
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
16939
17060
|
* )
|
|
16940
17061
|
* ```
|
|
16941
17062
|
*
|
|
@@ -16970,18 +17091,20 @@ export declare const trackErrors: {
|
|
|
16970
17091
|
*
|
|
16971
17092
|
* @example
|
|
16972
17093
|
* ```ts
|
|
16973
|
-
* import { Effect, Metric } from "effect"
|
|
17094
|
+
* import { Data, Effect, Metric } from "effect"
|
|
17095
|
+
*
|
|
17096
|
+
* class ConnectionFailedError extends Data.TaggedError("ConnectionFailedError")<{}> {}
|
|
16974
17097
|
*
|
|
16975
17098
|
* // Track error types using frequency metric
|
|
16976
17099
|
* const errorTypeFrequency = Metric.frequency("error_types")
|
|
16977
17100
|
*
|
|
16978
|
-
* const program = Effect.fail(new
|
|
16979
|
-
* Effect.trackErrors(errorTypeFrequency, (error:
|
|
17101
|
+
* const program = Effect.fail(new ConnectionFailedError()).pipe(
|
|
17102
|
+
* Effect.trackErrors(errorTypeFrequency, (error: ConnectionFailedError) => error._tag)
|
|
16980
17103
|
* )
|
|
16981
17104
|
*
|
|
16982
17105
|
* Effect.runPromiseExit(program).then(() =>
|
|
16983
17106
|
* Effect.runPromise(Metric.value(errorTypeFrequency)).then(console.log)
|
|
16984
|
-
* // Output: { occurrences: Map(1) { "
|
|
17107
|
+
* // Output: { occurrences: Map(1) { "ConnectionFailedError" => 1 } }
|
|
16985
17108
|
* )
|
|
16986
17109
|
* ```
|
|
16987
17110
|
*
|
|
@@ -18056,18 +18179,20 @@ export declare const satisfiesSuccessType: <A>() => <A2 extends A, E, R>(effect:
|
|
|
18056
18179
|
*
|
|
18057
18180
|
* @example
|
|
18058
18181
|
* ```ts
|
|
18059
|
-
* import { Effect } from "effect"
|
|
18182
|
+
* import { Data, Effect } from "effect"
|
|
18183
|
+
*
|
|
18184
|
+
* class ValidationError extends Data.TaggedError("ValidationError")<{}> {}
|
|
18060
18185
|
*
|
|
18061
|
-
* // Define a constraint that the error type must be
|
|
18062
|
-
* const satisfiesError = Effect.satisfiesErrorType<
|
|
18186
|
+
* // Define a constraint that the error type must be a ValidationError
|
|
18187
|
+
* const satisfiesError = Effect.satisfiesErrorType<ValidationError>()
|
|
18063
18188
|
*
|
|
18064
|
-
* // This works - Effect<number,
|
|
18065
|
-
* const validEffect = satisfiesError(Effect.fail(new
|
|
18189
|
+
* // This works - Effect<number, ValidationError, never> extends the constrained type
|
|
18190
|
+
* const validEffect = satisfiesError(Effect.fail(new ValidationError()))
|
|
18066
18191
|
*
|
|
18067
18192
|
* // This would cause a TypeScript compilation error:
|
|
18068
18193
|
* // const invalidEffect = satisfiesError(Effect.fail("string error"))
|
|
18069
18194
|
* // ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
18070
|
-
* // Type 'string' is not assignable to type '
|
|
18195
|
+
* // Type 'string' is not assignable to type 'ValidationError'
|
|
18071
18196
|
* ```
|
|
18072
18197
|
*
|
|
18073
18198
|
* @since 4.0.0
|