effect 4.0.0-rc.118 → 4.0.1
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/README.md +17 -4
- package/dist/Array.d.ts +25 -25
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +16 -16
- package/dist/Array.js.map +1 -1
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +20 -16
- package/dist/Cache.js.map +1 -1
- package/dist/Cause.d.ts.map +1 -1
- package/dist/Cause.js +1 -1
- package/dist/Cause.js.map +1 -1
- package/dist/Chunk.d.ts +26 -26
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +15 -15
- package/dist/Chunk.js.map +1 -1
- package/dist/Effect.d.ts +167 -39
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +16 -10
- package/dist/Effect.js.map +1 -1
- package/dist/HashRing.d.ts.map +1 -1
- package/dist/HashRing.js +13 -5
- package/dist/HashRing.js.map +1 -1
- package/dist/MutableHashMap.d.ts.map +1 -1
- package/dist/MutableHashMap.js +4 -22
- package/dist/MutableHashMap.js.map +1 -1
- package/dist/Option.d.ts +17 -17
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +6 -6
- package/dist/Option.js.map +1 -1
- package/dist/Pool.d.ts +9 -5
- package/dist/Pool.d.ts.map +1 -1
- package/dist/Pool.js +34 -41
- package/dist/Pool.js.map +1 -1
- package/dist/Queue.d.ts +19 -2
- package/dist/Queue.d.ts.map +1 -1
- package/dist/Queue.js +9 -4
- package/dist/Queue.js.map +1 -1
- package/dist/RcMap.d.ts.map +1 -1
- package/dist/RcMap.js +16 -1
- package/dist/RcMap.js.map +1 -1
- package/dist/Record.d.ts +14 -14
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +10 -10
- package/dist/Record.js.map +1 -1
- package/dist/Schema.d.ts +37 -21
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +29 -10
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +116 -97
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +3 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +3 -1
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/ScopedCache.d.ts.map +1 -1
- package/dist/ScopedCache.js +24 -16
- package/dist/ScopedCache.js.map +1 -1
- package/dist/Stream.d.ts +45 -6
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +55 -44
- package/dist/Stream.js.map +1 -1
- package/dist/ai/LanguageModel.d.ts +8 -0
- package/dist/ai/LanguageModel.d.ts.map +1 -1
- package/dist/ai/LanguageModel.js +13 -2
- package/dist/ai/LanguageModel.js.map +1 -1
- package/dist/ai/McpSchema.d.ts +402 -402
- package/dist/ai/McpSchema.d.ts.map +1 -1
- package/dist/ai/McpSchema.js +1 -1
- package/dist/ai/McpSchema.js.map +1 -1
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +11 -3
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/Response.d.ts.map +1 -1
- package/dist/ai/Response.js +22 -12
- package/dist/ai/Response.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js +1 -0
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js +1 -0
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js +1 -0
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js +1 -0
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpSchema/v2024_11_05.js +3 -1
- package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
- package/dist/cluster/ClusterWorkflowEngine.js +16 -3
- package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/cluster/MessageStorage.d.ts +32 -8
- package/dist/cluster/MessageStorage.d.ts.map +1 -1
- package/dist/cluster/MessageStorage.js +2 -1
- package/dist/cluster/MessageStorage.js.map +1 -1
- package/dist/cluster/Sharding.d.ts +5 -2
- package/dist/cluster/Sharding.d.ts.map +1 -1
- package/dist/cluster/Sharding.js +15 -8
- package/dist/cluster/Sharding.js.map +1 -1
- package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/cluster/SqlMessageStorage.js +36 -16
- package/dist/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/cluster/SqlRunnerStorage.js +30 -44
- package/dist/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/cluster/internal/entityManager.js +63 -62
- package/dist/cluster/internal/entityManager.js.map +1 -1
- package/dist/cluster/internal/interruptors.js +8 -0
- package/dist/cluster/internal/interruptors.js.map +1 -1
- package/dist/cluster/internal/resourceMap.js +39 -14
- package/dist/cluster/internal/resourceMap.js.map +1 -1
- package/dist/cluster/internal/resourceRef.js +168 -87
- package/dist/cluster/internal/resourceRef.js.map +1 -1
- package/dist/http/HttpEffect.d.ts +1 -0
- package/dist/http/HttpEffect.d.ts.map +1 -1
- package/dist/http/HttpEffect.js +29 -22
- package/dist/http/HttpEffect.js.map +1 -1
- package/dist/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/http/HttpMiddleware.js +3 -2
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/HttpStaticServer.d.ts.map +1 -1
- package/dist/http/HttpStaticServer.js +14 -0
- package/dist/http/HttpStaticServer.js.map +1 -1
- package/dist/http/HttpTraceContext.d.ts +1 -1
- package/dist/http/HttpTraceContext.d.ts.map +1 -1
- package/dist/http/HttpTraceContext.js +4 -4
- package/dist/http/HttpTraceContext.js.map +1 -1
- package/dist/http-api/HttpApiError.d.ts +1 -0
- package/dist/http-api/HttpApiError.d.ts.map +1 -1
- package/dist/http-api/HttpApiError.js +1 -0
- package/dist/http-api/HttpApiError.js.map +1 -1
- package/dist/internal/core.js +43 -2
- package/dist/internal/core.js.map +1 -1
- package/dist/internal/dateTime.js +1 -1
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +138 -165
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/rcRef.js +59 -23
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/internal/schema/annotations.js +1 -7
- package/dist/internal/schema/annotations.js.map +1 -1
- package/dist/internal/schema/codegen.js +56 -28
- package/dist/internal/schema/codegen.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js +11 -8
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/toCodeDocument.js +10 -30
- package/dist/internal/schema/toCodeDocument.js.map +1 -1
- package/dist/internal/schema/toCodec.js +1 -15
- package/dist/internal/schema/toCodec.js.map +1 -1
- package/dist/internal/schema/toEquivalence.js +4 -3
- package/dist/internal/schema/toEquivalence.js.map +1 -1
- package/dist/internal/schema/toFormatter.js +4 -4
- package/dist/internal/schema/toFormatter.js.map +1 -1
- package/dist/reactivity/Atom.d.ts.map +1 -1
- package/dist/reactivity/Atom.js +6 -2
- package/dist/reactivity/Atom.js.map +1 -1
- package/dist/reactivity/AtomRpc.d.ts +3 -3
- package/dist/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/rpc/Rpc.d.ts +2 -2
- package/dist/rpc/Rpc.d.ts.map +1 -1
- package/dist/rpc/RpcClient.d.ts +7 -7
- package/dist/rpc/RpcClient.d.ts.map +1 -1
- package/dist/rpc/RpcClient.js +21 -16
- package/dist/rpc/RpcClient.js.map +1 -1
- package/dist/rpc/RpcMessage.d.ts +1 -1
- package/dist/rpc/RpcMessage.d.ts.map +1 -1
- package/dist/rpc/RpcServer.d.ts.map +1 -1
- package/dist/rpc/RpcServer.js +2 -2
- package/dist/rpc/RpcServer.js.map +1 -1
- package/dist/rpc/Utils.d.ts +2 -3
- package/dist/rpc/Utils.d.ts.map +1 -1
- package/dist/rpc/Utils.js +3 -4
- package/dist/rpc/Utils.js.map +1 -1
- package/dist/schema/SchemaCompiler/runtime.js +6 -1
- package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +234 -6
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +244 -25
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.js.map +1 -1
- package/dist/workflow/DurableDeferred.js +1 -1
- package/dist/workflow/DurableDeferred.js.map +1 -1
- package/dist/workflow/Workflow.js +1 -1
- package/dist/workflow/Workflow.js.map +1 -1
- package/dist/workflow/WorkflowEngine.d.ts +2 -0
- package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
- package/dist/workflow/WorkflowEngine.js +1 -0
- package/dist/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +31 -31
- package/src/Cache.ts +22 -16
- package/src/Cause.ts +1 -1
- package/src/Chunk.ts +29 -29
- package/src/Effect.ts +170 -39
- package/src/HashRing.ts +14 -5
- package/src/MutableHashMap.ts +4 -24
- package/src/Option.ts +19 -19
- package/src/Pool.ts +28 -36
- package/src/Queue.ts +26 -6
- package/src/RcMap.ts +26 -2
- package/src/Record.ts +20 -20
- package/src/Schema.ts +48 -24
- package/src/SchemaAST.ts +135 -115
- package/src/SchemaRepresentation.ts +3 -1
- package/src/ScopedCache.ts +27 -16
- package/src/Stream.ts +158 -88
- package/src/ai/LanguageModel.ts +27 -2
- package/src/ai/McpSchema.ts +3 -3
- package/src/ai/McpServer.ts +12 -3
- package/src/ai/Response.ts +27 -12
- package/src/ai/internal/mcpProtocol/v2024_11_05.ts +1 -0
- package/src/ai/internal/mcpProtocol/v2025_03_26.ts +1 -0
- package/src/ai/internal/mcpProtocol/v2025_06_18.ts +1 -0
- package/src/ai/internal/mcpProtocol/v2025_11_25.ts +1 -0
- package/src/ai/internal/mcpSchema/v2024_11_05.ts +4 -2
- package/src/cluster/ClusterWorkflowEngine.ts +26 -5
- package/src/cluster/MessageStorage.ts +22 -5
- package/src/cluster/Sharding.ts +32 -28
- package/src/cluster/SqlMessageStorage.ts +45 -21
- package/src/cluster/SqlRunnerStorage.ts +85 -113
- package/src/cluster/internal/entityManager.ts +68 -80
- package/src/cluster/internal/interruptors.ts +13 -0
- package/src/cluster/internal/resourceMap.ts +55 -17
- package/src/cluster/internal/resourceRef.ts +189 -96
- package/src/http/HttpEffect.ts +15 -9
- package/src/http/HttpMiddleware.ts +8 -2
- package/src/http/HttpStaticServer.ts +16 -0
- package/src/http/HttpTraceContext.ts +8 -4
- package/src/http-api/HttpApiError.ts +1 -0
- package/src/internal/core.ts +56 -2
- package/src/internal/dateTime.ts +3 -1
- package/src/internal/effect.ts +146 -173
- package/src/internal/rcRef.ts +83 -33
- package/src/internal/schema/annotations.ts +0 -9
- package/src/internal/schema/codegen.ts +90 -43
- package/src/internal/schema/fromJsonSchemaDocument.ts +5 -3
- package/src/internal/schema/toCodeDocument.ts +10 -47
- package/src/internal/schema/toCodec.ts +3 -16
- package/src/internal/schema/toEquivalence.ts +4 -5
- package/src/internal/schema/toFormatter.ts +4 -6
- package/src/reactivity/Atom.ts +6 -2
- package/src/reactivity/AtomRpc.ts +5 -5
- package/src/rpc/Rpc.ts +2 -2
- package/src/rpc/RpcClient.ts +35 -32
- package/src/rpc/RpcMessage.ts +1 -1
- package/src/rpc/RpcServer.ts +2 -1
- package/src/rpc/Utils.ts +4 -10
- package/src/schema/SchemaCompiler/runtime.ts +17 -1
- package/src/testing/TestSchema.ts +315 -63
- package/src/testing/index.ts +1 -0
- package/src/workflow/DurableDeferred.ts +1 -1
- package/src/workflow/Workflow.ts +1 -1
- package/src/workflow/WorkflowEngine.ts +4 -0
package/src/Effect.ts
CHANGED
|
@@ -503,13 +503,13 @@ export const all: <
|
|
|
503
503
|
) => All.Return<Arg, O> = internal.all
|
|
504
504
|
|
|
505
505
|
/**
|
|
506
|
-
* Applies an effectful function to each element and partitions
|
|
507
|
-
*
|
|
506
|
+
* Applies an effectful function to each element and partitions successes and
|
|
507
|
+
* failures.
|
|
508
508
|
*
|
|
509
509
|
* **Details**
|
|
510
510
|
*
|
|
511
|
-
* The returned tuple is `[
|
|
512
|
-
*
|
|
511
|
+
* The returned tuple is `[passes, fails]`, where `passes` contains all
|
|
512
|
+
* successes and `fails` contains all failures.
|
|
513
513
|
*
|
|
514
514
|
* This function runs every effect and never fails. Use `concurrency` to control
|
|
515
515
|
* parallelism.
|
|
@@ -523,7 +523,7 @@ export const all: <
|
|
|
523
523
|
* n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
|
|
524
524
|
* )
|
|
525
525
|
*
|
|
526
|
-
* await Effect.runPromise(program) // => [['0 is even', '2 is even']
|
|
526
|
+
* await Effect.runPromise(program) // => [[1, 3], ['0 is even', '2 is even']]
|
|
527
527
|
* ```
|
|
528
528
|
*
|
|
529
529
|
* @category collecting
|
|
@@ -531,13 +531,13 @@ export const all: <
|
|
|
531
531
|
*/
|
|
532
532
|
export const partition: {
|
|
533
533
|
/**
|
|
534
|
-
* Applies an effectful function to each element and partitions
|
|
535
|
-
*
|
|
534
|
+
* Applies an effectful function to each element and partitions successes and
|
|
535
|
+
* failures.
|
|
536
536
|
*
|
|
537
537
|
* **Details**
|
|
538
538
|
*
|
|
539
|
-
* The returned tuple is `[
|
|
540
|
-
*
|
|
539
|
+
* The returned tuple is `[passes, fails]`, where `passes` contains all
|
|
540
|
+
* successes and `fails` contains all failures.
|
|
541
541
|
*
|
|
542
542
|
* This function runs every effect and never fails. Use `concurrency` to control
|
|
543
543
|
* parallelism.
|
|
@@ -551,7 +551,7 @@ export const partition: {
|
|
|
551
551
|
* n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
|
|
552
552
|
* )
|
|
553
553
|
*
|
|
554
|
-
* await Effect.runPromise(program) // => [['0 is even', '2 is even']
|
|
554
|
+
* await Effect.runPromise(program) // => [[1, 3], ['0 is even', '2 is even']]
|
|
555
555
|
* ```
|
|
556
556
|
*
|
|
557
557
|
* @category collecting
|
|
@@ -560,15 +560,15 @@ export const partition: {
|
|
|
560
560
|
<A, B, E, R>(
|
|
561
561
|
f: (a: A, i: number) => Effect<B, E, R>,
|
|
562
562
|
options?: { readonly concurrency?: Concurrency | undefined }
|
|
563
|
-
): (elements: Iterable<A>) => Effect<[
|
|
563
|
+
): (elements: Iterable<A>) => Effect<[passes: Array<B>, fails: Array<E>], never, R>
|
|
564
564
|
/**
|
|
565
|
-
* Applies an effectful function to each element and partitions
|
|
566
|
-
*
|
|
565
|
+
* Applies an effectful function to each element and partitions successes and
|
|
566
|
+
* failures.
|
|
567
567
|
*
|
|
568
568
|
* **Details**
|
|
569
569
|
*
|
|
570
|
-
* The returned tuple is `[
|
|
571
|
-
*
|
|
570
|
+
* The returned tuple is `[passes, fails]`, where `passes` contains all
|
|
571
|
+
* successes and `fails` contains all failures.
|
|
572
572
|
*
|
|
573
573
|
* This function runs every effect and never fails. Use `concurrency` to control
|
|
574
574
|
* parallelism.
|
|
@@ -582,7 +582,7 @@ export const partition: {
|
|
|
582
582
|
* n % 2 === 0 ? Effect.fail(`${n} is even`) : Effect.succeed(n)
|
|
583
583
|
* )
|
|
584
584
|
*
|
|
585
|
-
* await Effect.runPromise(program) // => [['0 is even', '2 is even']
|
|
585
|
+
* await Effect.runPromise(program) // => [[1, 3], ['0 is even', '2 is even']]
|
|
586
586
|
* ```
|
|
587
587
|
*
|
|
588
588
|
* @category collecting
|
|
@@ -592,7 +592,7 @@ export const partition: {
|
|
|
592
592
|
elements: Iterable<A>,
|
|
593
593
|
f: (a: A, i: number) => Effect<B, E, R>,
|
|
594
594
|
options?: { readonly concurrency?: Concurrency | undefined }
|
|
595
|
-
): Effect<[
|
|
595
|
+
): Effect<[passes: Array<B>, fails: Array<E>], never, R>
|
|
596
596
|
} = internal.partition
|
|
597
597
|
|
|
598
598
|
/**
|
|
@@ -13909,6 +13909,11 @@ export const onExitFilter: {
|
|
|
13909
13909
|
* evaluations of the same effect will return the cached result without
|
|
13910
13910
|
* re-executing the logic.
|
|
13911
13911
|
*
|
|
13912
|
+
* Concurrent callers share the pending computation, which is interrupted only
|
|
13913
|
+
* once every caller waiting on it has been interrupted. Interrupted
|
|
13914
|
+
* computations are never cached, so the next evaluation starts a fresh
|
|
13915
|
+
* computation.
|
|
13916
|
+
*
|
|
13912
13917
|
* **Example** (Memoizing an effect until invalidated)
|
|
13913
13918
|
*
|
|
13914
13919
|
* ```ts import.meta.vitest
|
|
@@ -13970,11 +13975,12 @@ export const cached: <A, E, R>(self: Effect<A, E, R>) => Effect<Effect<A, E, R>>
|
|
|
13970
13975
|
* `Duration.Input`. The function runs once after each fresh computation,
|
|
13971
13976
|
* including failures, so successes and failures can have different TTLs. It
|
|
13972
13977
|
* does not run when the cache is created or when a cached result is reused.
|
|
13973
|
-
*
|
|
13974
|
-
* returned duration.
|
|
13978
|
+
* Interrupted computations are never cached and do not call the function.
|
|
13975
13979
|
*
|
|
13976
13980
|
* The TTL starts when the computation completes. Concurrent callers share the
|
|
13977
|
-
* pending computation
|
|
13981
|
+
* pending computation, which is interrupted only once every caller waiting on
|
|
13982
|
+
* it has been interrupted. The next evaluation then starts a fresh
|
|
13983
|
+
* computation. A zero TTL expires immediately, and an infinite TTL
|
|
13978
13984
|
* keeps the result indefinitely.
|
|
13979
13985
|
*
|
|
13980
13986
|
* **Example** (Memoizing an effect with TTL)
|
|
@@ -14054,11 +14060,12 @@ export const cachedWithTTL: {
|
|
|
14054
14060
|
* `Duration.Input`. The function runs once after each fresh computation,
|
|
14055
14061
|
* including failures, so successes and failures can have different TTLs. It
|
|
14056
14062
|
* does not run when the cache is created or when a cached result is reused.
|
|
14057
|
-
*
|
|
14058
|
-
* returned duration.
|
|
14063
|
+
* Interrupted computations are never cached and do not call the function.
|
|
14059
14064
|
*
|
|
14060
14065
|
* The TTL starts when the computation completes. Concurrent callers share the
|
|
14061
|
-
* pending computation
|
|
14066
|
+
* pending computation, which is interrupted only once every caller waiting on
|
|
14067
|
+
* it has been interrupted. The next evaluation then starts a fresh
|
|
14068
|
+
* computation. A zero TTL expires immediately, and an infinite TTL
|
|
14062
14069
|
* keeps the result indefinitely.
|
|
14063
14070
|
*
|
|
14064
14071
|
* **Example** (Memoizing an effect with TTL)
|
|
@@ -14138,11 +14145,12 @@ export const cachedWithTTL: {
|
|
|
14138
14145
|
* `Duration.Input`. The function runs once after each fresh computation,
|
|
14139
14146
|
* including failures, so successes and failures can have different TTLs. It
|
|
14140
14147
|
* does not run when the cache is created or when a cached result is reused.
|
|
14141
|
-
*
|
|
14142
|
-
* returned duration.
|
|
14148
|
+
* Interrupted computations are never cached and do not call the function.
|
|
14143
14149
|
*
|
|
14144
14150
|
* The TTL starts when the computation completes. Concurrent callers share the
|
|
14145
|
-
* pending computation
|
|
14151
|
+
* pending computation, which is interrupted only once every caller waiting on
|
|
14152
|
+
* it has been interrupted. The next evaluation then starts a fresh
|
|
14153
|
+
* computation. A zero TTL expires immediately, and an infinite TTL
|
|
14146
14154
|
* keeps the result indefinitely.
|
|
14147
14155
|
*
|
|
14148
14156
|
* **Example** (Memoizing an effect with TTL)
|
|
@@ -14222,11 +14230,12 @@ export const cachedWithTTL: {
|
|
|
14222
14230
|
* `Duration.Input`. The function runs once after each fresh computation,
|
|
14223
14231
|
* including failures, so successes and failures can have different TTLs. It
|
|
14224
14232
|
* does not run when the cache is created or when a cached result is reused.
|
|
14225
|
-
*
|
|
14226
|
-
* returned duration.
|
|
14233
|
+
* Interrupted computations are never cached and do not call the function.
|
|
14227
14234
|
*
|
|
14228
14235
|
* The TTL starts when the computation completes. Concurrent callers share the
|
|
14229
|
-
* pending computation
|
|
14236
|
+
* pending computation, which is interrupted only once every caller waiting on
|
|
14237
|
+
* it has been interrupted. The next evaluation then starts a fresh
|
|
14238
|
+
* computation. A zero TTL expires immediately, and an infinite TTL
|
|
14230
14239
|
* keeps the result indefinitely.
|
|
14231
14240
|
*
|
|
14232
14241
|
* **Example** (Memoizing an effect with TTL)
|
|
@@ -14306,11 +14315,12 @@ export const cachedWithTTL: {
|
|
|
14306
14315
|
* `Duration.Input`. The function runs once after each fresh computation,
|
|
14307
14316
|
* including failures, so successes and failures can have different TTLs. It
|
|
14308
14317
|
* does not run when the cache is created or when a cached result is reused.
|
|
14309
|
-
*
|
|
14310
|
-
* returned duration.
|
|
14318
|
+
* Interrupted computations are never cached and do not call the function.
|
|
14311
14319
|
*
|
|
14312
14320
|
* The TTL starts when the computation completes. Concurrent callers share the
|
|
14313
|
-
* pending computation
|
|
14321
|
+
* pending computation, which is interrupted only once every caller waiting on
|
|
14322
|
+
* it has been interrupted. The next evaluation then starts a fresh
|
|
14323
|
+
* computation. A zero TTL expires immediately, and an infinite TTL
|
|
14314
14324
|
* keeps the result indefinitely.
|
|
14315
14325
|
*
|
|
14316
14326
|
* **Example** (Memoizing an effect with TTL)
|
|
@@ -14371,8 +14381,8 @@ export const cachedWithTTL: {
|
|
|
14371
14381
|
} = internal.cachedWithTTL
|
|
14372
14382
|
|
|
14373
14383
|
/**
|
|
14374
|
-
* Creates a cached effect result for a
|
|
14375
|
-
* invalidation before expiration.
|
|
14384
|
+
* Creates a cached effect result for a fixed duration or a duration computed
|
|
14385
|
+
* from its `Exit` and allows manual invalidation before expiration.
|
|
14376
14386
|
*
|
|
14377
14387
|
* **When to use**
|
|
14378
14388
|
*
|
|
@@ -14430,8 +14440,67 @@ export const cachedWithTTL: {
|
|
|
14430
14440
|
*/
|
|
14431
14441
|
export const cachedInvalidateWithTTL: {
|
|
14432
14442
|
/**
|
|
14433
|
-
* Creates a cached effect result for a
|
|
14434
|
-
* invalidation before expiration.
|
|
14443
|
+
* Creates a cached effect result for a fixed duration or a duration computed
|
|
14444
|
+
* from its `Exit` and allows manual invalidation before expiration.
|
|
14445
|
+
*
|
|
14446
|
+
* **When to use**
|
|
14447
|
+
*
|
|
14448
|
+
* Use when an effect result should be cached for a bounded time and callers
|
|
14449
|
+
* also need a manual invalidation effect to force recomputation before
|
|
14450
|
+
* expiration.
|
|
14451
|
+
*
|
|
14452
|
+
* **Details**
|
|
14453
|
+
*
|
|
14454
|
+
* This function behaves similarly to {@link cachedWithTTL} by caching the
|
|
14455
|
+
* result of an effect for a specified period of time. However, it introduces an
|
|
14456
|
+
* additional feature: it provides an effect that allows you to manually
|
|
14457
|
+
* invalidate the cached result before it naturally expires.
|
|
14458
|
+
*
|
|
14459
|
+
* This gives you more control over the cache, allowing you to refresh the
|
|
14460
|
+
* result when needed, even if the original cache has not yet expired.
|
|
14461
|
+
*
|
|
14462
|
+
* Once the cache is invalidated, the next time the effect is evaluated, the
|
|
14463
|
+
* result will be recomputed, and the cache will be refreshed.
|
|
14464
|
+
*
|
|
14465
|
+
* **Example** (Memoizing with TTL and invalidation)
|
|
14466
|
+
*
|
|
14467
|
+
* ```ts import.meta.vitest
|
|
14468
|
+
* import { Effect } from "effect"
|
|
14469
|
+
* const output: Array<unknown> = []
|
|
14470
|
+
* const record = (value: unknown) => Effect.sync(() => { output.push(value) })
|
|
14471
|
+
*
|
|
14472
|
+
* let i = 1
|
|
14473
|
+
* const expensiveTask = Effect.sync(() => {
|
|
14474
|
+
* void output.push("expensive task...")
|
|
14475
|
+
* return `result ${i++}`
|
|
14476
|
+
* })
|
|
14477
|
+
*
|
|
14478
|
+
* const program = Effect.gen(function*() {
|
|
14479
|
+
* const [cached, invalidate] = yield* Effect.cachedInvalidateWithTTL(
|
|
14480
|
+
* expensiveTask,
|
|
14481
|
+
* "1 hour"
|
|
14482
|
+
* )
|
|
14483
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
14484
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
14485
|
+
* yield* invalidate
|
|
14486
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
14487
|
+
* })
|
|
14488
|
+
*
|
|
14489
|
+
* Effect.runSync(program)
|
|
14490
|
+
* output // => ["expensive task...", "result 1", "result 1", "expensive task...", "result 2"]
|
|
14491
|
+
* ```
|
|
14492
|
+
*
|
|
14493
|
+
* @see {@link cached} for a similar function that caches the result
|
|
14494
|
+
* indefinitely.
|
|
14495
|
+
* @see {@link cachedWithTTL} for a similar function that caches the result for
|
|
14496
|
+
* a specified duration but does not include an effect for manual invalidation.
|
|
14497
|
+
* @category caching
|
|
14498
|
+
* @since 2.0.0
|
|
14499
|
+
*/
|
|
14500
|
+
<A, E>(timeToLive: (exit: Exit.Exit<A, E>) => Duration.Input): <R>(self: Effect<A, E, R>) => Effect<[Effect<A, E, R>, Effect<void>]>
|
|
14501
|
+
/**
|
|
14502
|
+
* Creates a cached effect result for a fixed duration or a duration computed
|
|
14503
|
+
* from its `Exit` and allows manual invalidation before expiration.
|
|
14435
14504
|
*
|
|
14436
14505
|
* **When to use**
|
|
14437
14506
|
*
|
|
@@ -14489,8 +14558,67 @@ export const cachedInvalidateWithTTL: {
|
|
|
14489
14558
|
*/
|
|
14490
14559
|
(timeToLive: Duration.Input): <A, E, R>(self: Effect<A, E, R>) => Effect<[Effect<A, E, R>, Effect<void>]>
|
|
14491
14560
|
/**
|
|
14492
|
-
* Creates a cached effect result for a
|
|
14493
|
-
* invalidation before expiration.
|
|
14561
|
+
* Creates a cached effect result for a fixed duration or a duration computed
|
|
14562
|
+
* from its `Exit` and allows manual invalidation before expiration.
|
|
14563
|
+
*
|
|
14564
|
+
* **When to use**
|
|
14565
|
+
*
|
|
14566
|
+
* Use when an effect result should be cached for a bounded time and callers
|
|
14567
|
+
* also need a manual invalidation effect to force recomputation before
|
|
14568
|
+
* expiration.
|
|
14569
|
+
*
|
|
14570
|
+
* **Details**
|
|
14571
|
+
*
|
|
14572
|
+
* This function behaves similarly to {@link cachedWithTTL} by caching the
|
|
14573
|
+
* result of an effect for a specified period of time. However, it introduces an
|
|
14574
|
+
* additional feature: it provides an effect that allows you to manually
|
|
14575
|
+
* invalidate the cached result before it naturally expires.
|
|
14576
|
+
*
|
|
14577
|
+
* This gives you more control over the cache, allowing you to refresh the
|
|
14578
|
+
* result when needed, even if the original cache has not yet expired.
|
|
14579
|
+
*
|
|
14580
|
+
* Once the cache is invalidated, the next time the effect is evaluated, the
|
|
14581
|
+
* result will be recomputed, and the cache will be refreshed.
|
|
14582
|
+
*
|
|
14583
|
+
* **Example** (Memoizing with TTL and invalidation)
|
|
14584
|
+
*
|
|
14585
|
+
* ```ts import.meta.vitest
|
|
14586
|
+
* import { Effect } from "effect"
|
|
14587
|
+
* const output: Array<unknown> = []
|
|
14588
|
+
* const record = (value: unknown) => Effect.sync(() => { output.push(value) })
|
|
14589
|
+
*
|
|
14590
|
+
* let i = 1
|
|
14591
|
+
* const expensiveTask = Effect.sync(() => {
|
|
14592
|
+
* void output.push("expensive task...")
|
|
14593
|
+
* return `result ${i++}`
|
|
14594
|
+
* })
|
|
14595
|
+
*
|
|
14596
|
+
* const program = Effect.gen(function*() {
|
|
14597
|
+
* const [cached, invalidate] = yield* Effect.cachedInvalidateWithTTL(
|
|
14598
|
+
* expensiveTask,
|
|
14599
|
+
* "1 hour"
|
|
14600
|
+
* )
|
|
14601
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
14602
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
14603
|
+
* yield* invalidate
|
|
14604
|
+
* yield* cached.pipe(Effect.andThen(record))
|
|
14605
|
+
* })
|
|
14606
|
+
*
|
|
14607
|
+
* Effect.runSync(program)
|
|
14608
|
+
* output // => ["expensive task...", "result 1", "result 1", "expensive task...", "result 2"]
|
|
14609
|
+
* ```
|
|
14610
|
+
*
|
|
14611
|
+
* @see {@link cached} for a similar function that caches the result
|
|
14612
|
+
* indefinitely.
|
|
14613
|
+
* @see {@link cachedWithTTL} for a similar function that caches the result for
|
|
14614
|
+
* a specified duration but does not include an effect for manual invalidation.
|
|
14615
|
+
* @category caching
|
|
14616
|
+
* @since 2.0.0
|
|
14617
|
+
*/
|
|
14618
|
+
<A, E>(timeToLive: Duration.Input | ((exit: Exit.Exit<A, E>) => Duration.Input)): <R>(self: Effect<A, E, R>) => Effect<[Effect<A, E, R>, Effect<void>]>
|
|
14619
|
+
/**
|
|
14620
|
+
* Creates a cached effect result for a fixed duration or a duration computed
|
|
14621
|
+
* from its `Exit` and allows manual invalidation before expiration.
|
|
14494
14622
|
*
|
|
14495
14623
|
* **When to use**
|
|
14496
14624
|
*
|
|
@@ -14546,7 +14674,10 @@ export const cachedInvalidateWithTTL: {
|
|
|
14546
14674
|
* @category caching
|
|
14547
14675
|
* @since 2.0.0
|
|
14548
14676
|
*/
|
|
14549
|
-
<A, E, R>(
|
|
14677
|
+
<A, E, R>(
|
|
14678
|
+
self: Effect<A, E, R>,
|
|
14679
|
+
timeToLive: Duration.Input | ((exit: Exit.Exit<A, E>) => Duration.Input)
|
|
14680
|
+
): Effect<[Effect<A, E, R>, Effect<void>]>
|
|
14550
14681
|
} = internal.cachedInvalidateWithTTL
|
|
14551
14682
|
|
|
14552
14683
|
// -----------------------------------------------------------------------------
|
package/src/HashRing.ts
CHANGED
|
@@ -179,12 +179,9 @@ export const addMany: {
|
|
|
179
179
|
if (entry[1] === weight) continue
|
|
180
180
|
toRemove ??= new Set()
|
|
181
181
|
toRemove.add(key)
|
|
182
|
-
self.totalWeightCache -= entry[1]
|
|
183
|
-
self.totalWeightCache += weight
|
|
184
182
|
entry[1] = weight
|
|
185
183
|
} else {
|
|
186
184
|
self.nodes.set(key, [node, weight])
|
|
187
|
-
self.totalWeightCache += weight
|
|
188
185
|
}
|
|
189
186
|
keys.push(key)
|
|
190
187
|
}
|
|
@@ -192,6 +189,7 @@ export const addMany: {
|
|
|
192
189
|
self.ring = self.ring.filter(([, n]) => !toRemove.has(n))
|
|
193
190
|
}
|
|
194
191
|
addNodesToRing(self, keys, Math.round(weight * self.baseWeight))
|
|
192
|
+
updateTotalWeight(self)
|
|
195
193
|
return self
|
|
196
194
|
}
|
|
197
195
|
)
|
|
@@ -206,7 +204,18 @@ function addNodesToRing<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>, keys
|
|
|
206
204
|
])
|
|
207
205
|
}
|
|
208
206
|
}
|
|
209
|
-
|
|
207
|
+
// Break hash ties by node key to avoid insertion-order dependence.
|
|
208
|
+
self.ring.sort((a, b) => a[0] - b[0] || (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0))
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Sum in key order to avoid history-dependent floating-point rounding.
|
|
212
|
+
function updateTotalWeight<A extends PrimaryKey.PrimaryKey>(self: HashRing<A>) {
|
|
213
|
+
const keys = Array.from(self.nodes.keys()).sort()
|
|
214
|
+
let total = 0
|
|
215
|
+
for (let i = 0; i < keys.length; i++) {
|
|
216
|
+
total += self.nodes.get(keys[i])![1]
|
|
217
|
+
}
|
|
218
|
+
self.totalWeightCache = total
|
|
210
219
|
}
|
|
211
220
|
|
|
212
221
|
/**
|
|
@@ -380,7 +389,7 @@ export const remove: {
|
|
|
380
389
|
if (entry) {
|
|
381
390
|
self.nodes.delete(key)
|
|
382
391
|
self.ring = self.ring.filter(([, n]) => n !== key)
|
|
383
|
-
self
|
|
392
|
+
updateTotalWeight(self)
|
|
384
393
|
}
|
|
385
394
|
return self
|
|
386
395
|
})
|
package/src/MutableHashMap.ts
CHANGED
|
@@ -397,10 +397,6 @@ export const get: {
|
|
|
397
397
|
} else if (isSimpleKey(key)) {
|
|
398
398
|
return Option.none()
|
|
399
399
|
}
|
|
400
|
-
const refKey = referentialKeysCache.get(key)
|
|
401
|
-
if (refKey !== undefined && self.backing.has(refKey)) {
|
|
402
|
-
return Option.some(self.backing.get(refKey)!)
|
|
403
|
-
}
|
|
404
400
|
const hash = Hash.hash(key)
|
|
405
401
|
const bucket = self.buckets.get(hash)
|
|
406
402
|
if (bucket === undefined) {
|
|
@@ -409,7 +405,6 @@ export const get: {
|
|
|
409
405
|
return getFromBucket(self, bucket, key)
|
|
410
406
|
})
|
|
411
407
|
|
|
412
|
-
const referentialKeysCache = new WeakMap<any, any>()
|
|
413
408
|
const isSimpleKey = (u: unknown): boolean => typeof u !== "object" && typeof u !== "function"
|
|
414
409
|
|
|
415
410
|
/**
|
|
@@ -483,7 +478,6 @@ const getFromBucket = <K, V>(
|
|
|
483
478
|
for (let i = 0, len = bucket.length; i < len; i++) {
|
|
484
479
|
if (Equal.equals(key, bucket[i])) {
|
|
485
480
|
const refKey = bucket[i]
|
|
486
|
-
referentialKeysCache.set(key, refKey)
|
|
487
481
|
return Option.some(self.backing.get(refKey)!)
|
|
488
482
|
}
|
|
489
483
|
}
|
|
@@ -839,12 +833,6 @@ export const set: {
|
|
|
839
833
|
self.backing.set(key, value)
|
|
840
834
|
return self
|
|
841
835
|
}
|
|
842
|
-
let refKey = referentialKeysCache.get(key)
|
|
843
|
-
if (refKey !== undefined && self.backing.has(refKey)) {
|
|
844
|
-
self.backing.set(refKey, value)
|
|
845
|
-
return self
|
|
846
|
-
}
|
|
847
|
-
|
|
848
836
|
const hash = Hash.hash(key)
|
|
849
837
|
const bucket = self.buckets.get(hash)
|
|
850
838
|
if (bucket === undefined) {
|
|
@@ -853,7 +841,7 @@ export const set: {
|
|
|
853
841
|
return self
|
|
854
842
|
}
|
|
855
843
|
|
|
856
|
-
refKey = getRefKey(bucket, key)
|
|
844
|
+
let refKey = getRefKey(bucket, key)
|
|
857
845
|
if (refKey === undefined) {
|
|
858
846
|
bucket.push(key)
|
|
859
847
|
refKey = key
|
|
@@ -868,7 +856,6 @@ const getRefKey = <K>(
|
|
|
868
856
|
) => {
|
|
869
857
|
for (let i = 0, len = bucket.length; i < len; i++) {
|
|
870
858
|
if (Equal.equals(key, bucket[i])) {
|
|
871
|
-
referentialKeysCache.set(key, bucket[i])
|
|
872
859
|
return bucket[i]
|
|
873
860
|
}
|
|
874
861
|
}
|
|
@@ -1083,19 +1070,13 @@ export const modify: {
|
|
|
1083
1070
|
}
|
|
1084
1071
|
return self
|
|
1085
1072
|
}
|
|
1086
|
-
let refKey = referentialKeysCache.get(key)
|
|
1087
|
-
if (refKey !== undefined && self.backing.has(refKey)) {
|
|
1088
|
-
self.backing.set(refKey, f(self.backing.get(refKey)!))
|
|
1089
|
-
return self
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
1073
|
const hash = Hash.hash(key)
|
|
1093
1074
|
const bucket = self.buckets.get(hash)
|
|
1094
1075
|
if (bucket === undefined) {
|
|
1095
1076
|
return self
|
|
1096
1077
|
}
|
|
1097
1078
|
|
|
1098
|
-
refKey = getRefKey(bucket, key)
|
|
1079
|
+
const refKey = getRefKey(bucket, key)
|
|
1099
1080
|
if (refKey === undefined) {
|
|
1100
1081
|
return self
|
|
1101
1082
|
}
|
|
@@ -1607,15 +1588,14 @@ export const remove: {
|
|
|
1607
1588
|
return self
|
|
1608
1589
|
}
|
|
1609
1590
|
|
|
1610
|
-
const
|
|
1611
|
-
const hash = Hash.hash(key)
|
|
1591
|
+
const hash = Hash.hash(key_)
|
|
1612
1592
|
const bucket = self.buckets.get(hash)
|
|
1613
1593
|
if (bucket === undefined) {
|
|
1614
1594
|
return self
|
|
1615
1595
|
}
|
|
1616
1596
|
for (let i = 0, len = bucket.length; i < len; i++) {
|
|
1617
1597
|
const bkey = bucket[i]
|
|
1618
|
-
if (bkey ===
|
|
1598
|
+
if (bkey === key_ || Equal.equals(key_, bkey)) {
|
|
1619
1599
|
self.backing.delete(bkey)
|
|
1620
1600
|
bucket.splice(i, 1)
|
|
1621
1601
|
break
|
package/src/Option.ts
CHANGED
|
@@ -3185,14 +3185,14 @@ export const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [se
|
|
|
3185
3185
|
*
|
|
3186
3186
|
* **When to use**
|
|
3187
3187
|
*
|
|
3188
|
-
* Use when you need to split an optional value into
|
|
3188
|
+
* Use when you need to split an optional value into success and failure
|
|
3189
3189
|
* channels using a `Result`-returning function.
|
|
3190
3190
|
*
|
|
3191
3191
|
* **Details**
|
|
3192
3192
|
*
|
|
3193
3193
|
* - `None` → `[None, None]`
|
|
3194
|
-
* - `Some` where `f` returns `
|
|
3195
|
-
* - `Some` where `f` returns `
|
|
3194
|
+
* - `Some` where `f` returns `Ok` → `[Some(value), None]`
|
|
3195
|
+
* - `Some` where `f` returns `Err` → `[None, Some(error)]`
|
|
3196
3196
|
*
|
|
3197
3197
|
* **Example** (Partitioning by Result)
|
|
3198
3198
|
*
|
|
@@ -3204,8 +3204,8 @@ export const toArray = <A>(self: Option<A>): Array<A> => isNone(self) ? [] : [se
|
|
|
3204
3204
|
* return isNaN(n) ? Result.fail("Not a number") : Result.succeed(n)
|
|
3205
3205
|
* }
|
|
3206
3206
|
*
|
|
3207
|
-
* Option.partitionMap(Option.some("42"), parseNumber) // => [Option.
|
|
3208
|
-
* Option.partitionMap(Option.some("abc"), parseNumber) // => [Option.some("Not a number")
|
|
3207
|
+
* Option.partitionMap(Option.some("42"), parseNumber) // => [Option.some(42), Option.none()]
|
|
3208
|
+
* Option.partitionMap(Option.some("abc"), parseNumber) // => [Option.none(), Option.some("Not a number")]
|
|
3209
3209
|
* Option.partitionMap(Option.none(), parseNumber) // => [Option.none(), Option.none()]
|
|
3210
3210
|
* ```
|
|
3211
3211
|
*
|
|
@@ -3220,14 +3220,14 @@ export const partitionMap: {
|
|
|
3220
3220
|
*
|
|
3221
3221
|
* **When to use**
|
|
3222
3222
|
*
|
|
3223
|
-
* Use when you need to split an optional value into
|
|
3223
|
+
* Use when you need to split an optional value into success and failure
|
|
3224
3224
|
* channels using a `Result`-returning function.
|
|
3225
3225
|
*
|
|
3226
3226
|
* **Details**
|
|
3227
3227
|
*
|
|
3228
3228
|
* - `None` → `[None, None]`
|
|
3229
|
-
* - `Some` where `f` returns `
|
|
3230
|
-
* - `Some` where `f` returns `
|
|
3229
|
+
* - `Some` where `f` returns `Ok` → `[Some(value), None]`
|
|
3230
|
+
* - `Some` where `f` returns `Err` → `[None, Some(error)]`
|
|
3231
3231
|
*
|
|
3232
3232
|
* **Example** (Partitioning by Result)
|
|
3233
3233
|
*
|
|
@@ -3239,8 +3239,8 @@ export const partitionMap: {
|
|
|
3239
3239
|
* return isNaN(n) ? Result.fail("Not a number") : Result.succeed(n)
|
|
3240
3240
|
* }
|
|
3241
3241
|
*
|
|
3242
|
-
* Option.partitionMap(Option.some("42"), parseNumber) // => [Option.
|
|
3243
|
-
* Option.partitionMap(Option.some("abc"), parseNumber) // => [Option.some("Not a number")
|
|
3242
|
+
* Option.partitionMap(Option.some("42"), parseNumber) // => [Option.some(42), Option.none()]
|
|
3243
|
+
* Option.partitionMap(Option.some("abc"), parseNumber) // => [Option.none(), Option.some("Not a number")]
|
|
3244
3244
|
* Option.partitionMap(Option.none(), parseNumber) // => [Option.none(), Option.none()]
|
|
3245
3245
|
* ```
|
|
3246
3246
|
*
|
|
@@ -3249,20 +3249,20 @@ export const partitionMap: {
|
|
|
3249
3249
|
* @category filtering
|
|
3250
3250
|
* @since 2.0.0
|
|
3251
3251
|
*/
|
|
3252
|
-
<A, B, C>(f: (a: A) => Result<C, B>): (self: Option<A>) => [
|
|
3252
|
+
<A, B, C>(f: (a: A) => Result<C, B>): (self: Option<A>) => [passes: Option<C>, fails: Option<B>]
|
|
3253
3253
|
/**
|
|
3254
3254
|
* Splits an `Option` into two `Option`s using a function that returns a `Result`.
|
|
3255
3255
|
*
|
|
3256
3256
|
* **When to use**
|
|
3257
3257
|
*
|
|
3258
|
-
* Use when you need to split an optional value into
|
|
3258
|
+
* Use when you need to split an optional value into success and failure
|
|
3259
3259
|
* channels using a `Result`-returning function.
|
|
3260
3260
|
*
|
|
3261
3261
|
* **Details**
|
|
3262
3262
|
*
|
|
3263
3263
|
* - `None` → `[None, None]`
|
|
3264
|
-
* - `Some` where `f` returns `
|
|
3265
|
-
* - `Some` where `f` returns `
|
|
3264
|
+
* - `Some` where `f` returns `Ok` → `[Some(value), None]`
|
|
3265
|
+
* - `Some` where `f` returns `Err` → `[None, Some(error)]`
|
|
3266
3266
|
*
|
|
3267
3267
|
* **Example** (Partitioning by Result)
|
|
3268
3268
|
*
|
|
@@ -3274,8 +3274,8 @@ export const partitionMap: {
|
|
|
3274
3274
|
* return isNaN(n) ? Result.fail("Not a number") : Result.succeed(n)
|
|
3275
3275
|
* }
|
|
3276
3276
|
*
|
|
3277
|
-
* Option.partitionMap(Option.some("42"), parseNumber) // => [Option.
|
|
3278
|
-
* Option.partitionMap(Option.some("abc"), parseNumber) // => [Option.some("Not a number")
|
|
3277
|
+
* Option.partitionMap(Option.some("42"), parseNumber) // => [Option.some(42), Option.none()]
|
|
3278
|
+
* Option.partitionMap(Option.some("abc"), parseNumber) // => [Option.none(), Option.some("Not a number")]
|
|
3279
3279
|
* Option.partitionMap(Option.none(), parseNumber) // => [Option.none(), Option.none()]
|
|
3280
3280
|
* ```
|
|
3281
3281
|
*
|
|
@@ -3284,16 +3284,16 @@ export const partitionMap: {
|
|
|
3284
3284
|
* @category filtering
|
|
3285
3285
|
* @since 2.0.0
|
|
3286
3286
|
*/
|
|
3287
|
-
<A, B, C>(self: Option<A>, f: (a: A) => Result<C, B>): [
|
|
3287
|
+
<A, B, C>(self: Option<A>, f: (a: A) => Result<C, B>): [passes: Option<C>, fails: Option<B>]
|
|
3288
3288
|
} = dual(2, <A, B, C>(
|
|
3289
3289
|
self: Option<A>,
|
|
3290
3290
|
f: (a: A) => Result<C, B>
|
|
3291
|
-
): [
|
|
3291
|
+
): [passes: Option<C>, fails: Option<B>] => {
|
|
3292
3292
|
if (isNone(self)) {
|
|
3293
3293
|
return [none(), none()]
|
|
3294
3294
|
}
|
|
3295
3295
|
const e = f(self.value)
|
|
3296
|
-
return result.isFailure(e) ? [some(e.failure)
|
|
3296
|
+
return result.isFailure(e) ? [none(), some(e.failure)] : [some(e.success), none()]
|
|
3297
3297
|
})
|
|
3298
3298
|
|
|
3299
3299
|
/**
|