@clayroach/effect 3.19.14-source-capture.6 → 3.19.14-source-capture.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Utils.js +1 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/internal/clock.js +1 -1
- package/dist/cjs/internal/clock.js.map +1 -1
- package/dist/esm/Utils.js +1 -1
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/internal/clock.js +1 -1
- package/dist/esm/internal/clock.js.map +1 -1
- package/package.json +1 -1
- package/src/Arbitrary.ts +0 -1101
- package/src/Array.ts +0 -3589
- package/src/BigDecimal.ts +0 -1349
- package/src/BigInt.ts +0 -643
- package/src/Boolean.ts +0 -287
- package/src/Brand.ts +0 -360
- package/src/Cache.ts +0 -281
- package/src/Cause.ts +0 -1555
- package/src/Channel.ts +0 -2355
- package/src/ChildExecutorDecision.ts +0 -146
- package/src/Chunk.ts +0 -1495
- package/src/Clock.ts +0 -111
- package/src/Config.ts +0 -542
- package/src/ConfigError.ts +0 -270
- package/src/ConfigProvider.ts +0 -333
- package/src/ConfigProviderPathPatch.ts +0 -100
- package/src/Console.ts +0 -226
- package/src/Context.ts +0 -585
- package/src/Cron.ts +0 -706
- package/src/Data.ts +0 -596
- package/src/DateTime.ts +0 -1686
- package/src/DefaultServices.ts +0 -34
- package/src/Deferred.ts +0 -301
- package/src/Differ.ts +0 -450
- package/src/Duration.ts +0 -1000
- package/src/Effect.ts +0 -14839
- package/src/Effectable.ts +0 -107
- package/src/Either.ts +0 -1040
- package/src/Encoding.ts +0 -195
- package/src/Equal.ts +0 -98
- package/src/Equivalence.ts +0 -235
- package/src/ExecutionPlan.ts +0 -308
- package/src/ExecutionStrategy.ts +0 -119
- package/src/Exit.ts +0 -467
- package/src/FastCheck.ts +0 -9
- package/src/Fiber.ts +0 -744
- package/src/FiberHandle.ts +0 -540
- package/src/FiberId.ts +0 -195
- package/src/FiberMap.ts +0 -656
- package/src/FiberRef.ts +0 -431
- package/src/FiberRefs.ts +0 -204
- package/src/FiberRefsPatch.ts +0 -105
- package/src/FiberSet.ts +0 -491
- package/src/FiberStatus.ts +0 -108
- package/src/Function.ts +0 -1222
- package/src/GlobalValue.ts +0 -53
- package/src/Graph.ts +0 -3732
- package/src/GroupBy.ts +0 -103
- package/src/HKT.ts +0 -45
- package/src/Hash.ts +0 -195
- package/src/HashMap.ts +0 -519
- package/src/HashRing.ts +0 -317
- package/src/HashSet.ts +0 -2346
- package/src/Inspectable.ts +0 -287
- package/src/Iterable.ts +0 -1119
- package/src/JSONSchema.ts +0 -1044
- package/src/KeyedPool.ts +0 -167
- package/src/Layer.ts +0 -1251
- package/src/LayerMap.ts +0 -436
- package/src/List.ts +0 -977
- package/src/LogLevel.ts +0 -285
- package/src/LogSpan.ts +0 -25
- package/src/Logger.ts +0 -702
- package/src/Mailbox.ts +0 -268
- package/src/ManagedRuntime.ts +0 -180
- package/src/Match.ts +0 -1477
- package/src/MergeDecision.ts +0 -95
- package/src/MergeState.ts +0 -172
- package/src/MergeStrategy.ts +0 -107
- package/src/Metric.ts +0 -780
- package/src/MetricBoundaries.ts +0 -69
- package/src/MetricHook.ts +0 -151
- package/src/MetricKey.ts +0 -224
- package/src/MetricKeyType.ts +0 -262
- package/src/MetricLabel.ts +0 -47
- package/src/MetricPair.ts +0 -71
- package/src/MetricPolling.ts +0 -148
- package/src/MetricRegistry.ts +0 -48
- package/src/MetricState.ts +0 -257
- package/src/Micro.ts +0 -4405
- package/src/ModuleVersion.ts +0 -18
- package/src/MutableHashMap.ts +0 -411
- package/src/MutableHashSet.ts +0 -706
- package/src/MutableList.ts +0 -297
- package/src/MutableQueue.ts +0 -227
- package/src/MutableRef.ts +0 -202
- package/src/NonEmptyIterable.ts +0 -32
- package/src/Number.ts +0 -1071
- package/src/Option.ts +0 -2170
- package/src/Order.ts +0 -373
- package/src/Ordering.ts +0 -111
- package/src/ParseResult.ts +0 -2031
- package/src/PartitionedSemaphore.ts +0 -200
- package/src/Pipeable.ts +0 -566
- package/src/Pool.ts +0 -204
- package/src/Predicate.ts +0 -1405
- package/src/Pretty.ts +0 -205
- package/src/PrimaryKey.ts +0 -23
- package/src/PubSub.ts +0 -182
- package/src/Queue.ts +0 -644
- package/src/Random.ts +0 -204
- package/src/RateLimiter.ts +0 -138
- package/src/RcMap.ts +0 -141
- package/src/RcRef.ts +0 -122
- package/src/Readable.ts +0 -93
- package/src/Record.ts +0 -1274
- package/src/RedBlackTree.ts +0 -421
- package/src/Redacted.ts +0 -144
- package/src/Ref.ts +0 -180
- package/src/RegExp.ts +0 -38
- package/src/Reloadable.ts +0 -127
- package/src/Request.ts +0 -347
- package/src/RequestBlock.ts +0 -118
- package/src/RequestResolver.ts +0 -366
- package/src/Resource.ts +0 -119
- package/src/Runtime.ts +0 -383
- package/src/RuntimeFlags.ts +0 -368
- package/src/RuntimeFlagsPatch.ts +0 -183
- package/src/STM.ts +0 -2045
- package/src/Schedule.ts +0 -2219
- package/src/ScheduleDecision.ts +0 -62
- package/src/ScheduleInterval.ts +0 -151
- package/src/ScheduleIntervals.ts +0 -122
- package/src/Scheduler.ts +0 -353
- package/src/Schema.ts +0 -10914
- package/src/SchemaAST.ts +0 -3043
- package/src/Scope.ts +0 -204
- package/src/ScopedCache.ts +0 -151
- package/src/ScopedRef.ts +0 -117
- package/src/Secret.ts +0 -88
- package/src/SingleProducerAsyncInput.ts +0 -67
- package/src/Sink.ts +0 -1461
- package/src/SortedMap.ts +0 -287
- package/src/SortedSet.ts +0 -390
- package/src/Stream.ts +0 -6468
- package/src/StreamEmit.ts +0 -136
- package/src/StreamHaltStrategy.ts +0 -123
- package/src/Streamable.ts +0 -45
- package/src/String.ts +0 -778
- package/src/Struct.ts +0 -243
- package/src/Subscribable.ts +0 -100
- package/src/SubscriptionRef.ts +0 -298
- package/src/Supervisor.ts +0 -240
- package/src/Symbol.ts +0 -29
- package/src/SynchronizedRef.ts +0 -270
- package/src/TArray.ts +0 -495
- package/src/TDeferred.ts +0 -100
- package/src/TMap.ts +0 -515
- package/src/TPriorityQueue.ts +0 -223
- package/src/TPubSub.ts +0 -200
- package/src/TQueue.ts +0 -432
- package/src/TRandom.ts +0 -129
- package/src/TReentrantLock.ts +0 -224
- package/src/TRef.ts +0 -178
- package/src/TSemaphore.ts +0 -129
- package/src/TSet.ts +0 -365
- package/src/TSubscriptionRef.ts +0 -192
- package/src/Take.ts +0 -258
- package/src/TestAnnotation.ts +0 -158
- package/src/TestAnnotationMap.ts +0 -119
- package/src/TestAnnotations.ts +0 -117
- package/src/TestClock.ts +0 -556
- package/src/TestConfig.ts +0 -47
- package/src/TestContext.ts +0 -36
- package/src/TestLive.ts +0 -53
- package/src/TestServices.ts +0 -390
- package/src/TestSized.ts +0 -55
- package/src/Tracer.ts +0 -198
- package/src/Trie.ts +0 -840
- package/src/Tuple.ts +0 -305
- package/src/Types.ts +0 -353
- package/src/Unify.ts +0 -113
- package/src/UpstreamPullRequest.ts +0 -117
- package/src/UpstreamPullStrategy.ts +0 -121
- package/src/Utils.ts +0 -809
- package/src/index.ts +0 -1561
- package/src/internal/array.ts +0 -8
- package/src/internal/blockedRequests.ts +0 -520
- package/src/internal/cache.ts +0 -733
- package/src/internal/cause.ts +0 -1050
- package/src/internal/channel/channelExecutor.ts +0 -1200
- package/src/internal/channel/channelState.ts +0 -134
- package/src/internal/channel/childExecutorDecision.ts +0 -96
- package/src/internal/channel/continuation.ts +0 -200
- package/src/internal/channel/mergeDecision.ts +0 -113
- package/src/internal/channel/mergeState.ts +0 -120
- package/src/internal/channel/mergeStrategy.ts +0 -72
- package/src/internal/channel/singleProducerAsyncInput.ts +0 -259
- package/src/internal/channel/subexecutor.ts +0 -229
- package/src/internal/channel/upstreamPullRequest.ts +0 -84
- package/src/internal/channel/upstreamPullStrategy.ts +0 -87
- package/src/internal/channel.ts +0 -2603
- package/src/internal/clock.ts +0 -95
- package/src/internal/completedRequestMap.ts +0 -9
- package/src/internal/concurrency.ts +0 -54
- package/src/internal/config.ts +0 -716
- package/src/internal/configError.ts +0 -304
- package/src/internal/configProvider/pathPatch.ts +0 -97
- package/src/internal/configProvider.ts +0 -799
- package/src/internal/console.ts +0 -153
- package/src/internal/context.ts +0 -337
- package/src/internal/core-effect.ts +0 -2293
- package/src/internal/core-stream.ts +0 -998
- package/src/internal/core.ts +0 -3273
- package/src/internal/data.ts +0 -36
- package/src/internal/dataSource.ts +0 -327
- package/src/internal/dateTime.ts +0 -1277
- package/src/internal/defaultServices/console.ts +0 -100
- package/src/internal/defaultServices.ts +0 -163
- package/src/internal/deferred.ts +0 -46
- package/src/internal/differ/chunkPatch.ts +0 -211
- package/src/internal/differ/contextPatch.ts +0 -232
- package/src/internal/differ/hashMapPatch.ts +0 -220
- package/src/internal/differ/hashSetPatch.ts +0 -176
- package/src/internal/differ/orPatch.ts +0 -311
- package/src/internal/differ/readonlyArrayPatch.ts +0 -210
- package/src/internal/differ.ts +0 -200
- package/src/internal/doNotation.ts +0 -80
- package/src/internal/effect/circular.ts +0 -905
- package/src/internal/effectable.ts +0 -131
- package/src/internal/either.ts +0 -110
- package/src/internal/encoding/base64.ts +0 -286
- package/src/internal/encoding/base64Url.ts +0 -29
- package/src/internal/encoding/common.ts +0 -51
- package/src/internal/encoding/hex.ts +0 -315
- package/src/internal/errors.ts +0 -7
- package/src/internal/executionPlan.ts +0 -114
- package/src/internal/executionStrategy.ts +0 -74
- package/src/internal/fiber.ts +0 -388
- package/src/internal/fiberId.ts +0 -267
- package/src/internal/fiberMessage.ts +0 -82
- package/src/internal/fiberRefs/patch.ts +0 -144
- package/src/internal/fiberRefs.ts +0 -297
- package/src/internal/fiberRuntime.ts +0 -3915
- package/src/internal/fiberScope.ts +0 -71
- package/src/internal/fiberStatus.ts +0 -119
- package/src/internal/groupBy.ts +0 -530
- package/src/internal/hashMap/array.ts +0 -49
- package/src/internal/hashMap/bitwise.ts +0 -32
- package/src/internal/hashMap/config.ts +0 -14
- package/src/internal/hashMap/keySet.ts +0 -8
- package/src/internal/hashMap/node.ts +0 -391
- package/src/internal/hashMap.ts +0 -586
- package/src/internal/hashSet.ts +0 -323
- package/src/internal/keyedPool.ts +0 -244
- package/src/internal/layer/circular.ts +0 -228
- package/src/internal/layer.ts +0 -1487
- package/src/internal/logSpan.ts +0 -20
- package/src/internal/logger-circular.ts +0 -24
- package/src/internal/logger.ts +0 -485
- package/src/internal/mailbox.ts +0 -561
- package/src/internal/managedRuntime/circular.ts +0 -6
- package/src/internal/managedRuntime.ts +0 -134
- package/src/internal/matcher.ts +0 -652
- package/src/internal/metric/boundaries.ts +0 -75
- package/src/internal/metric/hook.ts +0 -483
- package/src/internal/metric/key.ts +0 -167
- package/src/internal/metric/keyType.ts +0 -238
- package/src/internal/metric/label.ts +0 -41
- package/src/internal/metric/pair.ts +0 -48
- package/src/internal/metric/polling.ts +0 -149
- package/src/internal/metric/registry.ts +0 -187
- package/src/internal/metric/state.ts +0 -290
- package/src/internal/metric.ts +0 -577
- package/src/internal/opCodes/cause.ts +0 -35
- package/src/internal/opCodes/channel.ts +0 -83
- package/src/internal/opCodes/channelChildExecutorDecision.ts +0 -17
- package/src/internal/opCodes/channelMergeDecision.ts +0 -11
- package/src/internal/opCodes/channelMergeState.ts +0 -17
- package/src/internal/opCodes/channelMergeStrategy.ts +0 -11
- package/src/internal/opCodes/channelState.ts +0 -23
- package/src/internal/opCodes/channelUpstreamPullRequest.ts +0 -11
- package/src/internal/opCodes/channelUpstreamPullStrategy.ts +0 -11
- package/src/internal/opCodes/config.ts +0 -65
- package/src/internal/opCodes/configError.ts +0 -35
- package/src/internal/opCodes/continuation.ts +0 -11
- package/src/internal/opCodes/deferred.ts +0 -11
- package/src/internal/opCodes/effect.ts +0 -89
- package/src/internal/opCodes/layer.ts +0 -59
- package/src/internal/opCodes/streamHaltStrategy.ts +0 -23
- package/src/internal/option.ts +0 -80
- package/src/internal/pool.ts +0 -432
- package/src/internal/pubsub.ts +0 -1762
- package/src/internal/query.ts +0 -204
- package/src/internal/queue.ts +0 -766
- package/src/internal/random.ts +0 -161
- package/src/internal/rateLimiter.ts +0 -93
- package/src/internal/rcMap.ts +0 -285
- package/src/internal/rcRef.ts +0 -192
- package/src/internal/redBlackTree/iterator.ts +0 -200
- package/src/internal/redBlackTree/node.ts +0 -68
- package/src/internal/redBlackTree.ts +0 -1245
- package/src/internal/redacted.ts +0 -73
- package/src/internal/ref.ts +0 -171
- package/src/internal/reloadable.ts +0 -140
- package/src/internal/request.ts +0 -177
- package/src/internal/resource.ts +0 -76
- package/src/internal/ringBuffer.ts +0 -68
- package/src/internal/runtime.ts +0 -558
- package/src/internal/runtimeFlags.ts +0 -188
- package/src/internal/runtimeFlagsPatch.ts +0 -103
- package/src/internal/schedule/decision.ts +0 -47
- package/src/internal/schedule/interval.ts +0 -101
- package/src/internal/schedule/intervals.ts +0 -180
- package/src/internal/schedule.ts +0 -2199
- package/src/internal/schema/errors.ts +0 -191
- package/src/internal/schema/schemaId.ts +0 -106
- package/src/internal/schema/util.ts +0 -50
- package/src/internal/scopedCache.ts +0 -644
- package/src/internal/scopedRef.ts +0 -118
- package/src/internal/secret.ts +0 -89
- package/src/internal/singleShotGen.ts +0 -35
- package/src/internal/sink.ts +0 -2120
- package/src/internal/stack.ts +0 -10
- package/src/internal/stm/core.ts +0 -817
- package/src/internal/stm/entry.ts +0 -59
- package/src/internal/stm/journal.ts +0 -123
- package/src/internal/stm/opCodes/stm.ts +0 -71
- package/src/internal/stm/opCodes/stmState.ts +0 -17
- package/src/internal/stm/opCodes/strategy.ts +0 -17
- package/src/internal/stm/opCodes/tExit.ts +0 -29
- package/src/internal/stm/opCodes/tryCommit.ts +0 -11
- package/src/internal/stm/stm.ts +0 -1453
- package/src/internal/stm/stmState.ts +0 -136
- package/src/internal/stm/tArray.ts +0 -550
- package/src/internal/stm/tDeferred.ts +0 -81
- package/src/internal/stm/tExit.ts +0 -190
- package/src/internal/stm/tMap.ts +0 -824
- package/src/internal/stm/tPriorityQueue.ts +0 -267
- package/src/internal/stm/tPubSub.ts +0 -551
- package/src/internal/stm/tQueue.ts +0 -393
- package/src/internal/stm/tRandom.ts +0 -140
- package/src/internal/stm/tReentrantLock.ts +0 -352
- package/src/internal/stm/tRef.ts +0 -195
- package/src/internal/stm/tSemaphore.ts +0 -113
- package/src/internal/stm/tSet.ts +0 -259
- package/src/internal/stm/tSubscriptionRef.ts +0 -286
- package/src/internal/stm/tryCommit.ts +0 -34
- package/src/internal/stm/txnId.ts +0 -14
- package/src/internal/stm/versioned.ts +0 -4
- package/src/internal/stream/debounceState.ts +0 -57
- package/src/internal/stream/emit.ts +0 -123
- package/src/internal/stream/haltStrategy.ts +0 -94
- package/src/internal/stream/handoff.ts +0 -187
- package/src/internal/stream/handoffSignal.ts +0 -59
- package/src/internal/stream/pull.ts +0 -34
- package/src/internal/stream/sinkEndReason.ts +0 -30
- package/src/internal/stream/zipAllState.ts +0 -88
- package/src/internal/stream/zipChunksState.ts +0 -56
- package/src/internal/stream.ts +0 -8801
- package/src/internal/string-utils.ts +0 -107
- package/src/internal/subscriptionRef.ts +0 -138
- package/src/internal/supervisor/patch.ts +0 -190
- package/src/internal/supervisor.ts +0 -303
- package/src/internal/synchronizedRef.ts +0 -114
- package/src/internal/take.ts +0 -199
- package/src/internal/testing/sleep.ts +0 -27
- package/src/internal/testing/suspendedWarningData.ts +0 -85
- package/src/internal/testing/warningData.ts +0 -94
- package/src/internal/tracer.ts +0 -293
- package/src/internal/trie.ts +0 -722
- package/src/internal/version.ts +0 -7
package/src/internal/stm/tMap.ts
DELETED
|
@@ -1,824 +0,0 @@
|
|
|
1
|
-
import * as RA from "../../Array.js"
|
|
2
|
-
import * as Chunk from "../../Chunk.js"
|
|
3
|
-
import * as Equal from "../../Equal.js"
|
|
4
|
-
import type { LazyArg } from "../../Function.js"
|
|
5
|
-
import { dual, pipe } from "../../Function.js"
|
|
6
|
-
import * as Hash from "../../Hash.js"
|
|
7
|
-
import * as HashMap from "../../HashMap.js"
|
|
8
|
-
import * as Option from "../../Option.js"
|
|
9
|
-
import { hasProperty } from "../../Predicate.js"
|
|
10
|
-
import * as STM from "../../STM.js"
|
|
11
|
-
import type * as TArray from "../../TArray.js"
|
|
12
|
-
import type * as TMap from "../../TMap.js"
|
|
13
|
-
import type * as TRef from "../../TRef.js"
|
|
14
|
-
import * as core from "./core.js"
|
|
15
|
-
import type * as Journal from "./journal.js"
|
|
16
|
-
import * as stm from "./stm.js"
|
|
17
|
-
import * as tArray from "./tArray.js"
|
|
18
|
-
import * as tRef from "./tRef.js"
|
|
19
|
-
|
|
20
|
-
/** @internal */
|
|
21
|
-
const TMapSymbolKey = "effect/TMap"
|
|
22
|
-
|
|
23
|
-
/** @internal */
|
|
24
|
-
export const TMapTypeId: TMap.TMapTypeId = Symbol.for(
|
|
25
|
-
TMapSymbolKey
|
|
26
|
-
) as TMap.TMapTypeId
|
|
27
|
-
|
|
28
|
-
const tMapVariance = {
|
|
29
|
-
/* c8 ignore next */
|
|
30
|
-
_K: (_: any) => _,
|
|
31
|
-
/* c8 ignore next */
|
|
32
|
-
_V: (_: any) => _
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** @internal */
|
|
36
|
-
class TMapImpl<in out K, in out V> implements TMap.TMap<K, V> {
|
|
37
|
-
readonly [TMapTypeId] = tMapVariance
|
|
38
|
-
constructor(
|
|
39
|
-
readonly tBuckets: TRef.TRef<TArray.TArray<Chunk.Chunk<readonly [K, V]>>>,
|
|
40
|
-
readonly tSize: TRef.TRef<number>
|
|
41
|
-
) {}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const isTMap = (u: unknown) => hasProperty(u, TMapTypeId)
|
|
45
|
-
|
|
46
|
-
/** @internal */
|
|
47
|
-
const InitialCapacity = 16
|
|
48
|
-
const LoadFactor = 0.75
|
|
49
|
-
|
|
50
|
-
/** @internal */
|
|
51
|
-
const nextPowerOfTwo = (size: number): number => {
|
|
52
|
-
const n = -1 >>> Math.clz32(size - 1)
|
|
53
|
-
return n < 0 ? 1 : n + 1
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** @internal */
|
|
57
|
-
const hash = <K>(key: K): number => {
|
|
58
|
-
const h = Hash.hash(key)
|
|
59
|
-
return h ^ (h >>> 16)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** @internal */
|
|
63
|
-
const indexOf = <K>(k: K, capacity: number): number => hash(k) & (capacity - 1)
|
|
64
|
-
|
|
65
|
-
/** @internal */
|
|
66
|
-
const allocate = <K, V>(
|
|
67
|
-
capacity: number,
|
|
68
|
-
data: Chunk.Chunk<readonly [K, V]>
|
|
69
|
-
): STM.STM<TMap.TMap<K, V>> => {
|
|
70
|
-
const buckets = Array.from({ length: capacity }, () => Chunk.empty<readonly [K, V]>())
|
|
71
|
-
const distinct = new Map<K, V>(data)
|
|
72
|
-
let size = 0
|
|
73
|
-
for (const entry of distinct) {
|
|
74
|
-
const index = indexOf(entry[0], capacity)
|
|
75
|
-
buckets[index] = pipe(buckets[index], Chunk.prepend(entry))
|
|
76
|
-
size = size + 1
|
|
77
|
-
}
|
|
78
|
-
return pipe(
|
|
79
|
-
tArray.fromIterable(buckets),
|
|
80
|
-
core.flatMap((buckets) =>
|
|
81
|
-
pipe(
|
|
82
|
-
tRef.make(buckets),
|
|
83
|
-
core.flatMap((tBuckets) =>
|
|
84
|
-
pipe(
|
|
85
|
-
tRef.make(size),
|
|
86
|
-
core.map((tSize) => new TMapImpl(tBuckets, tSize))
|
|
87
|
-
)
|
|
88
|
-
)
|
|
89
|
-
)
|
|
90
|
-
)
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** @internal */
|
|
95
|
-
export const empty = <K, V>(): STM.STM<TMap.TMap<K, V>> => fromIterable<K, V>([])
|
|
96
|
-
|
|
97
|
-
/** @internal */
|
|
98
|
-
export const find = dual<
|
|
99
|
-
<K, V, A>(
|
|
100
|
-
pf: (key: K, value: V) => Option.Option<A>
|
|
101
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<Option.Option<A>>,
|
|
102
|
-
<K, V, A>(
|
|
103
|
-
self: TMap.TMap<K, V>,
|
|
104
|
-
pf: (key: K, value: V) => Option.Option<A>
|
|
105
|
-
) => STM.STM<Option.Option<A>>
|
|
106
|
-
>(2, (self, pf) =>
|
|
107
|
-
findSTM(self, (key, value) => {
|
|
108
|
-
const option = pf(key, value)
|
|
109
|
-
if (Option.isSome(option)) {
|
|
110
|
-
return core.succeed(option.value)
|
|
111
|
-
}
|
|
112
|
-
return core.fail(Option.none())
|
|
113
|
-
}))
|
|
114
|
-
|
|
115
|
-
/** @internal */
|
|
116
|
-
export const findSTM = dual<
|
|
117
|
-
<K, V, A, E, R>(
|
|
118
|
-
f: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
119
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<Option.Option<A>, E, R>,
|
|
120
|
-
<K, V, A, E, R>(
|
|
121
|
-
self: TMap.TMap<K, V>,
|
|
122
|
-
f: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
123
|
-
) => STM.STM<Option.Option<A>, E, R>
|
|
124
|
-
>(2, <K, V, A, E, R>(
|
|
125
|
-
self: TMap.TMap<K, V>,
|
|
126
|
-
f: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
127
|
-
) =>
|
|
128
|
-
reduceSTM(self, Option.none<A>(), (acc, value, key) =>
|
|
129
|
-
Option.isNone(acc) ?
|
|
130
|
-
core.matchSTM(f(key, value), {
|
|
131
|
-
onFailure: Option.match({
|
|
132
|
-
onNone: () => stm.succeedNone,
|
|
133
|
-
onSome: core.fail
|
|
134
|
-
}),
|
|
135
|
-
onSuccess: stm.succeedSome
|
|
136
|
-
}) :
|
|
137
|
-
STM.succeed(acc)))
|
|
138
|
-
|
|
139
|
-
/** @internal */
|
|
140
|
-
export const findAll = dual<
|
|
141
|
-
<K, V, A>(
|
|
142
|
-
pf: (key: K, value: V) => Option.Option<A>
|
|
143
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<Array<A>>,
|
|
144
|
-
<K, V, A>(
|
|
145
|
-
self: TMap.TMap<K, V>,
|
|
146
|
-
pf: (key: K, value: V) => Option.Option<A>
|
|
147
|
-
) => STM.STM<Array<A>>
|
|
148
|
-
>(2, (self, pf) =>
|
|
149
|
-
findAllSTM(self, (key, value) => {
|
|
150
|
-
const option = pf(key, value)
|
|
151
|
-
if (Option.isSome(option)) {
|
|
152
|
-
return core.succeed(option.value)
|
|
153
|
-
}
|
|
154
|
-
return core.fail(Option.none())
|
|
155
|
-
}))
|
|
156
|
-
|
|
157
|
-
/** @internal */
|
|
158
|
-
export const findAllSTM = dual<
|
|
159
|
-
<K, V, A, E, R>(
|
|
160
|
-
pf: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
161
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<Array<A>, E, R>,
|
|
162
|
-
<K, V, A, E, R>(
|
|
163
|
-
self: TMap.TMap<K, V>,
|
|
164
|
-
pf: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
165
|
-
) => STM.STM<Array<A>, E, R>
|
|
166
|
-
>(2, <K, V, A, E, R>(
|
|
167
|
-
self: TMap.TMap<K, V>,
|
|
168
|
-
pf: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
169
|
-
) =>
|
|
170
|
-
core.map(
|
|
171
|
-
reduceSTM(self, Chunk.empty<A>(), (acc, value, key) =>
|
|
172
|
-
core.matchSTM(pf(key, value), {
|
|
173
|
-
onFailure: Option.match({
|
|
174
|
-
onNone: () => core.succeed(acc),
|
|
175
|
-
onSome: core.fail
|
|
176
|
-
}),
|
|
177
|
-
onSuccess: (a) => core.succeed(Chunk.append(acc, a))
|
|
178
|
-
})),
|
|
179
|
-
(a) => Array.from(a)
|
|
180
|
-
))
|
|
181
|
-
|
|
182
|
-
/** @internal */
|
|
183
|
-
export const forEach = dual<
|
|
184
|
-
<K, V, X, E, R>(f: (key: K, value: V) => STM.STM<X, E, R>) => (self: TMap.TMap<K, V>) => STM.STM<void, E, R>,
|
|
185
|
-
<K, V, X, E, R>(self: TMap.TMap<K, V>, f: (key: K, value: V) => STM.STM<X, E, R>) => STM.STM<void, E, R>
|
|
186
|
-
>(2, (self, f) =>
|
|
187
|
-
reduceSTM(
|
|
188
|
-
self,
|
|
189
|
-
void 0 as void,
|
|
190
|
-
(_, value, key) => stm.asVoid(f(key, value))
|
|
191
|
-
))
|
|
192
|
-
|
|
193
|
-
/** @internal */
|
|
194
|
-
export const fromIterable = <K, V>(iterable: Iterable<readonly [K, V]>): STM.STM<TMap.TMap<K, V>> =>
|
|
195
|
-
stm.suspend(() => {
|
|
196
|
-
const data = Chunk.fromIterable(iterable)
|
|
197
|
-
const capacity = data.length < InitialCapacity
|
|
198
|
-
? InitialCapacity
|
|
199
|
-
: nextPowerOfTwo(data.length)
|
|
200
|
-
return allocate(capacity, data)
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
/** @internal */
|
|
204
|
-
export const get = dual<
|
|
205
|
-
<K>(key: K) => <V>(self: TMap.TMap<K, V>) => STM.STM<Option.Option<V>>,
|
|
206
|
-
<K, V>(self: TMap.TMap<K, V>, key: K) => STM.STM<Option.Option<V>>
|
|
207
|
-
>(2, <K, V>(self: TMap.TMap<K, V>, key: K) =>
|
|
208
|
-
core.effect<never, Option.Option<V>>((journal) => {
|
|
209
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
210
|
-
const index = indexOf(key, buckets.chunk.length)
|
|
211
|
-
const bucket = tRef.unsafeGet(buckets.chunk[index], journal)
|
|
212
|
-
return pipe(
|
|
213
|
-
Chunk.findFirst(bucket, (entry) => Equal.equals(entry[0])(key)),
|
|
214
|
-
Option.map((entry) => entry[1])
|
|
215
|
-
)
|
|
216
|
-
}))
|
|
217
|
-
|
|
218
|
-
/** @internal */
|
|
219
|
-
export const getOrElse = dual<
|
|
220
|
-
<K, V>(key: K, fallback: LazyArg<V>) => (self: TMap.TMap<K, V>) => STM.STM<V>,
|
|
221
|
-
<K, V>(self: TMap.TMap<K, V>, key: K, fallback: LazyArg<V>) => STM.STM<V>
|
|
222
|
-
>(3, (self, key, fallback) =>
|
|
223
|
-
core.map(
|
|
224
|
-
get(self, key),
|
|
225
|
-
Option.getOrElse(fallback)
|
|
226
|
-
))
|
|
227
|
-
|
|
228
|
-
/** @internal */
|
|
229
|
-
export const has = dual<
|
|
230
|
-
<K>(key: K) => <V>(self: TMap.TMap<K, V>) => STM.STM<boolean>,
|
|
231
|
-
<K, V>(self: TMap.TMap<K, V>, key: K) => STM.STM<boolean>
|
|
232
|
-
>(2, (self, key) => core.map(get(self, key), Option.isSome))
|
|
233
|
-
|
|
234
|
-
/** @internal */
|
|
235
|
-
export const isEmpty = <K, V>(self: TMap.TMap<K, V>): STM.STM<boolean> =>
|
|
236
|
-
core.map(tRef.get(self.tSize), (size) => size === 0)
|
|
237
|
-
|
|
238
|
-
/** @internal */
|
|
239
|
-
export const keys = <K, V>(self: TMap.TMap<K, V>): STM.STM<Array<K>> =>
|
|
240
|
-
core.map(toReadonlyArray(self), RA.map((entry) => entry[0]))
|
|
241
|
-
|
|
242
|
-
/** @internal */
|
|
243
|
-
export const make = <K, V>(...entries: Array<readonly [K, V]>): STM.STM<TMap.TMap<K, V>> => fromIterable(entries)
|
|
244
|
-
|
|
245
|
-
/** @internal */
|
|
246
|
-
export const merge = dual<
|
|
247
|
-
<K, V>(key: K, value: V, f: (x: V, y: V) => V) => (self: TMap.TMap<K, V>) => STM.STM<V>,
|
|
248
|
-
<K, V>(self: TMap.TMap<K, V>, key: K, value: V, f: (x: V, y: V) => V) => STM.STM<V>
|
|
249
|
-
>(4, (self, key, value, f) =>
|
|
250
|
-
core.flatMap(
|
|
251
|
-
get(self, key),
|
|
252
|
-
Option.match({
|
|
253
|
-
onNone: () => stm.as(set(self, key, value), value),
|
|
254
|
-
onSome: (v0) => {
|
|
255
|
-
const v1 = f(v0, value)
|
|
256
|
-
return stm.as(set(self, key, v1), v1)
|
|
257
|
-
}
|
|
258
|
-
})
|
|
259
|
-
))
|
|
260
|
-
|
|
261
|
-
/** @internal */
|
|
262
|
-
export const reduce = dual<
|
|
263
|
-
<Z, K, V>(zero: Z, f: (acc: Z, value: V, key: K) => Z) => (self: TMap.TMap<K, V>) => STM.STM<Z>,
|
|
264
|
-
<K, V, Z>(self: TMap.TMap<K, V>, zero: Z, f: (acc: Z, value: V, key: K) => Z) => STM.STM<Z>
|
|
265
|
-
>(
|
|
266
|
-
3,
|
|
267
|
-
<K, V, Z>(self: TMap.TMap<K, V>, zero: Z, f: (acc: Z, value: V, key: K) => Z) =>
|
|
268
|
-
core.effect<never, Z>((journal) => {
|
|
269
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
270
|
-
let result = zero
|
|
271
|
-
let index = 0
|
|
272
|
-
while (index < buckets.chunk.length) {
|
|
273
|
-
const bucket = buckets.chunk[index]
|
|
274
|
-
const items = tRef.unsafeGet(bucket, journal)
|
|
275
|
-
result = Chunk.reduce(items, result, (acc, entry) => f(acc, entry[1], entry[0]))
|
|
276
|
-
index = index + 1
|
|
277
|
-
}
|
|
278
|
-
return result
|
|
279
|
-
})
|
|
280
|
-
)
|
|
281
|
-
|
|
282
|
-
/** @internal */
|
|
283
|
-
export const reduceSTM = dual<
|
|
284
|
-
<Z, V, K, R, E>(
|
|
285
|
-
zero: Z,
|
|
286
|
-
f: (acc: Z, value: V, key: K) => STM.STM<Z, E, R>
|
|
287
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<Z, E, R>,
|
|
288
|
-
<Z, V, K, R, E>(
|
|
289
|
-
self: TMap.TMap<K, V>,
|
|
290
|
-
zero: Z,
|
|
291
|
-
f: (acc: Z, value: V, key: K) => STM.STM<Z, E, R>
|
|
292
|
-
) => STM.STM<Z, E, R>
|
|
293
|
-
>(3, (self, zero, f) =>
|
|
294
|
-
core.flatMap(
|
|
295
|
-
toReadonlyArray(self),
|
|
296
|
-
stm.reduce(zero, (acc, entry) => f(acc, entry[1], entry[0]))
|
|
297
|
-
))
|
|
298
|
-
|
|
299
|
-
/** @internal */
|
|
300
|
-
export const remove = dual<
|
|
301
|
-
<K>(key: K) => <V>(self: TMap.TMap<K, V>) => STM.STM<void>,
|
|
302
|
-
<K, V>(self: TMap.TMap<K, V>, key: K) => STM.STM<void>
|
|
303
|
-
>(2, (self, key) =>
|
|
304
|
-
core.effect<never, void>((journal) => {
|
|
305
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
306
|
-
const index = indexOf(key, buckets.chunk.length)
|
|
307
|
-
const bucket = tRef.unsafeGet(buckets.chunk[index], journal)
|
|
308
|
-
const [toRemove, toRetain] = Chunk.partition(bucket, (entry) => Equal.equals(entry[1], key))
|
|
309
|
-
if (Chunk.isNonEmpty(toRemove)) {
|
|
310
|
-
const currentSize = tRef.unsafeGet(self.tSize, journal)
|
|
311
|
-
tRef.unsafeSet(buckets.chunk[index], toRetain, journal)
|
|
312
|
-
tRef.unsafeSet(self.tSize, currentSize - 1, journal)
|
|
313
|
-
}
|
|
314
|
-
}))
|
|
315
|
-
|
|
316
|
-
/** @internal */
|
|
317
|
-
export const removeAll = dual<
|
|
318
|
-
<K>(keys: Iterable<K>) => <V>(self: TMap.TMap<K, V>) => STM.STM<void>,
|
|
319
|
-
<K, V>(self: TMap.TMap<K, V>, keys: Iterable<K>) => STM.STM<void>
|
|
320
|
-
>(2, <K, V>(self: TMap.TMap<K, V>, keys: Iterable<K>) =>
|
|
321
|
-
core.effect<never, void>((journal) => {
|
|
322
|
-
const iterator = keys[Symbol.iterator]()
|
|
323
|
-
let next: IteratorResult<K, any>
|
|
324
|
-
while ((next = iterator.next()) && !next.done) {
|
|
325
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
326
|
-
const index = indexOf(next.value, buckets.chunk.length)
|
|
327
|
-
const bucket = tRef.unsafeGet(buckets.chunk[index], journal)
|
|
328
|
-
const [toRemove, toRetain] = Chunk.partition(bucket, (entry) => Equal.equals(next.value)(entry[0]))
|
|
329
|
-
if (Chunk.isNonEmpty(toRemove)) {
|
|
330
|
-
const currentSize = tRef.unsafeGet(self.tSize, journal)
|
|
331
|
-
tRef.unsafeSet(buckets.chunk[index], toRetain, journal)
|
|
332
|
-
tRef.unsafeSet(self.tSize, currentSize - 1, journal)
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}))
|
|
336
|
-
|
|
337
|
-
/** @internal */
|
|
338
|
-
export const removeIf: {
|
|
339
|
-
<K, V>(
|
|
340
|
-
predicate: (key: K, value: V) => boolean,
|
|
341
|
-
options: {
|
|
342
|
-
readonly discard: true
|
|
343
|
-
}
|
|
344
|
-
): (self: TMap.TMap<K, V>) => STM.STM<void>
|
|
345
|
-
<K, V>(
|
|
346
|
-
predicate: (key: K, value: V) => boolean,
|
|
347
|
-
options?: {
|
|
348
|
-
readonly discard: false
|
|
349
|
-
}
|
|
350
|
-
): (self: TMap.TMap<K, V>) => STM.STM<Array<[K, V]>>
|
|
351
|
-
<K, V>(
|
|
352
|
-
self: TMap.TMap<K, V>,
|
|
353
|
-
predicate: (key: K, value: V) => boolean,
|
|
354
|
-
options: {
|
|
355
|
-
readonly discard: true
|
|
356
|
-
}
|
|
357
|
-
): STM.STM<void>
|
|
358
|
-
<K, V>(
|
|
359
|
-
self: TMap.TMap<K, V>,
|
|
360
|
-
predicate: (key: K, value: V) => boolean,
|
|
361
|
-
options?: {
|
|
362
|
-
readonly discard: false
|
|
363
|
-
}
|
|
364
|
-
): STM.STM<Array<[K, V]>>
|
|
365
|
-
} = dual((args) => isTMap(args[0]), <K, V>(
|
|
366
|
-
self: TMap.TMap<K, V>,
|
|
367
|
-
predicate: (key: K, value: V) => boolean,
|
|
368
|
-
options?: {
|
|
369
|
-
readonly discard: boolean
|
|
370
|
-
}
|
|
371
|
-
) =>
|
|
372
|
-
core.effect((journal) => {
|
|
373
|
-
const discard = options?.discard === true
|
|
374
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
375
|
-
const capacity = buckets.chunk.length
|
|
376
|
-
const removed: Array<[K, V]> = []
|
|
377
|
-
let index = 0
|
|
378
|
-
let newSize = 0
|
|
379
|
-
while (index < capacity) {
|
|
380
|
-
const bucket = tRef.unsafeGet(buckets.chunk[index], journal)
|
|
381
|
-
const iterator = bucket[Symbol.iterator]()
|
|
382
|
-
let next: IteratorResult<readonly [K, V], any>
|
|
383
|
-
let newBucket = Chunk.empty<readonly [K, V]>()
|
|
384
|
-
while ((next = iterator.next()) && !next.done) {
|
|
385
|
-
const [k, v] = next.value
|
|
386
|
-
if (!predicate(k, v)) {
|
|
387
|
-
newBucket = Chunk.prepend(newBucket, next.value)
|
|
388
|
-
newSize = newSize + 1
|
|
389
|
-
} else {
|
|
390
|
-
if (!discard) {
|
|
391
|
-
removed.push([k, v])
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
tRef.unsafeSet(buckets.chunk[index], newBucket, journal)
|
|
396
|
-
index = index + 1
|
|
397
|
-
}
|
|
398
|
-
tRef.unsafeSet(self.tSize, newSize, journal)
|
|
399
|
-
if (!discard) {
|
|
400
|
-
return removed
|
|
401
|
-
}
|
|
402
|
-
}))
|
|
403
|
-
|
|
404
|
-
/** @internal */
|
|
405
|
-
export const retainIf: {
|
|
406
|
-
<K, V>(
|
|
407
|
-
predicate: (key: K, value: V) => boolean,
|
|
408
|
-
options: {
|
|
409
|
-
readonly discard: true
|
|
410
|
-
}
|
|
411
|
-
): (self: TMap.TMap<K, V>) => STM.STM<void>
|
|
412
|
-
<K, V>(
|
|
413
|
-
predicate: (key: K, value: V) => boolean,
|
|
414
|
-
options?: {
|
|
415
|
-
readonly discard: false
|
|
416
|
-
}
|
|
417
|
-
): (self: TMap.TMap<K, V>) => STM.STM<Array<[K, V]>>
|
|
418
|
-
<K, V>(
|
|
419
|
-
self: TMap.TMap<K, V>,
|
|
420
|
-
predicate: (key: K, value: V) => boolean,
|
|
421
|
-
options: {
|
|
422
|
-
readonly discard: true
|
|
423
|
-
}
|
|
424
|
-
): STM.STM<void>
|
|
425
|
-
<K, V>(
|
|
426
|
-
self: TMap.TMap<K, V>,
|
|
427
|
-
predicate: (key: K, value: V) => boolean,
|
|
428
|
-
options?: {
|
|
429
|
-
readonly discard: false
|
|
430
|
-
}
|
|
431
|
-
): STM.STM<Array<[K, V]>>
|
|
432
|
-
} = dual(
|
|
433
|
-
(args) => isTMap(args[0]),
|
|
434
|
-
(self, predicate, options) => removeIf(self, (key, value) => !predicate(key, value), options)
|
|
435
|
-
)
|
|
436
|
-
|
|
437
|
-
/** @internal */
|
|
438
|
-
export const set = dual<
|
|
439
|
-
<K, V>(key: K, value: V) => (self: TMap.TMap<K, V>) => STM.STM<void>,
|
|
440
|
-
<K, V>(self: TMap.TMap<K, V>, key: K, value: V) => STM.STM<void>
|
|
441
|
-
>(3, <K, V>(self: TMap.TMap<K, V>, key: K, value: V) => {
|
|
442
|
-
const resize = (journal: Journal.Journal, buckets: TArray.TArray<Chunk.Chunk<readonly [K, V]>>): void => {
|
|
443
|
-
const capacity = buckets.chunk.length
|
|
444
|
-
const newCapacity = capacity << 1
|
|
445
|
-
const newBuckets = Array.from({ length: newCapacity }, () => Chunk.empty<readonly [K, V]>())
|
|
446
|
-
let index = 0
|
|
447
|
-
while (index < capacity) {
|
|
448
|
-
const pairs = tRef.unsafeGet(buckets.chunk[index], journal)
|
|
449
|
-
const iterator = pairs[Symbol.iterator]()
|
|
450
|
-
let next: IteratorResult<readonly [K, V], any>
|
|
451
|
-
while ((next = iterator.next()) && !next.done) {
|
|
452
|
-
const newIndex = indexOf(next.value[0], newCapacity)
|
|
453
|
-
newBuckets[newIndex] = Chunk.prepend(newBuckets[newIndex], next.value)
|
|
454
|
-
}
|
|
455
|
-
index = index + 1
|
|
456
|
-
}
|
|
457
|
-
// insert new pair
|
|
458
|
-
const newIndex = indexOf(key, newCapacity)
|
|
459
|
-
newBuckets[newIndex] = Chunk.prepend(newBuckets[newIndex], [key, value] as const)
|
|
460
|
-
|
|
461
|
-
const newArray: Array<TRef.TRef<Chunk.Chunk<readonly [K, V]>>> = []
|
|
462
|
-
index = 0
|
|
463
|
-
while (index < newCapacity) {
|
|
464
|
-
newArray[index] = new tRef.TRefImpl(newBuckets[index])
|
|
465
|
-
index = index + 1
|
|
466
|
-
}
|
|
467
|
-
const newTArray: TArray.TArray<Chunk.Chunk<readonly [K, V]>> = new tArray.TArrayImpl(newArray)
|
|
468
|
-
tRef.unsafeSet(self.tBuckets, newTArray, journal)
|
|
469
|
-
}
|
|
470
|
-
return core.effect<never, void>((journal) => {
|
|
471
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
472
|
-
const capacity = buckets.chunk.length
|
|
473
|
-
const index = indexOf(key, capacity)
|
|
474
|
-
const bucket = tRef.unsafeGet(buckets.chunk[index], journal)
|
|
475
|
-
const shouldUpdate = Chunk.some(bucket, (entry) => Equal.equals(key)(entry[0]))
|
|
476
|
-
if (shouldUpdate) {
|
|
477
|
-
const newBucket = Chunk.map(bucket, (entry) =>
|
|
478
|
-
Equal.equals(key)(entry[0]) ?
|
|
479
|
-
[key, value] as const :
|
|
480
|
-
entry)
|
|
481
|
-
tRef.unsafeSet(buckets.chunk[index], newBucket, journal)
|
|
482
|
-
} else {
|
|
483
|
-
const newSize = tRef.unsafeGet(self.tSize, journal) + 1
|
|
484
|
-
tRef.unsafeSet(self.tSize, newSize, journal)
|
|
485
|
-
if (capacity * LoadFactor < newSize) {
|
|
486
|
-
resize(journal, buckets)
|
|
487
|
-
} else {
|
|
488
|
-
const newBucket = Chunk.prepend(bucket, [key, value] as const)
|
|
489
|
-
tRef.unsafeSet(buckets.chunk[index], newBucket, journal)
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
})
|
|
493
|
-
})
|
|
494
|
-
|
|
495
|
-
/** @internal */
|
|
496
|
-
export const setIfAbsent = dual<
|
|
497
|
-
<K, V>(key: K, value: V) => (self: TMap.TMap<K, V>) => STM.STM<void>,
|
|
498
|
-
<K, V>(self: TMap.TMap<K, V>, key: K, value: V) => STM.STM<void>
|
|
499
|
-
>(3, (self, key, value) =>
|
|
500
|
-
core.flatMap(
|
|
501
|
-
get(self, key),
|
|
502
|
-
Option.match({
|
|
503
|
-
onNone: () => set(self, key, value),
|
|
504
|
-
onSome: () => stm.void
|
|
505
|
-
})
|
|
506
|
-
))
|
|
507
|
-
|
|
508
|
-
/** @internal */
|
|
509
|
-
export const size = <K, V>(self: TMap.TMap<K, V>): STM.STM<number> => tRef.get(self.tSize)
|
|
510
|
-
|
|
511
|
-
/** @internal */
|
|
512
|
-
export const takeFirst = dual<
|
|
513
|
-
<K, V, A>(pf: (key: K, value: V) => Option.Option<A>) => (self: TMap.TMap<K, V>) => STM.STM<A>,
|
|
514
|
-
<K, V, A>(self: TMap.TMap<K, V>, pf: (key: K, value: V) => Option.Option<A>) => STM.STM<A>
|
|
515
|
-
>(2, <K, V, A>(self: TMap.TMap<K, V>, pf: (key: K, value: V) => Option.Option<A>) =>
|
|
516
|
-
pipe(
|
|
517
|
-
core.effect<never, Option.Option<A>>((journal) => {
|
|
518
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
519
|
-
const capacity = buckets.chunk.length
|
|
520
|
-
const size = tRef.unsafeGet(self.tSize, journal)
|
|
521
|
-
let result: Option.Option<A> = Option.none()
|
|
522
|
-
let index = 0
|
|
523
|
-
while (index < capacity && Option.isNone(result)) {
|
|
524
|
-
const bucket = tRef.unsafeGet(buckets.chunk[index], journal)
|
|
525
|
-
const recreate = Chunk.some(bucket, (entry) => Option.isSome(pf(entry[0], entry[1])))
|
|
526
|
-
if (recreate) {
|
|
527
|
-
const iterator = bucket[Symbol.iterator]()
|
|
528
|
-
let newBucket = Chunk.empty<readonly [K, V]>()
|
|
529
|
-
let next: IteratorResult<readonly [K, V], any>
|
|
530
|
-
while ((next = iterator.next()) && !next.done && Option.isNone(result)) {
|
|
531
|
-
const option = pf(next.value[0], next.value[1])
|
|
532
|
-
if (Option.isSome(option) && Option.isNone(result)) {
|
|
533
|
-
result = option
|
|
534
|
-
} else {
|
|
535
|
-
newBucket = Chunk.prepend(newBucket, next.value)
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
tRef.unsafeSet(buckets.chunk[index], newBucket, journal)
|
|
539
|
-
}
|
|
540
|
-
index = index + 1
|
|
541
|
-
}
|
|
542
|
-
if (Option.isSome(result)) {
|
|
543
|
-
tRef.unsafeSet(self.tSize, size - 1, journal)
|
|
544
|
-
}
|
|
545
|
-
return result
|
|
546
|
-
}),
|
|
547
|
-
stm.collect((option) =>
|
|
548
|
-
Option.isSome(option) ?
|
|
549
|
-
Option.some(option.value) :
|
|
550
|
-
Option.none<A>()
|
|
551
|
-
)
|
|
552
|
-
))
|
|
553
|
-
|
|
554
|
-
/** @internal */
|
|
555
|
-
export const takeFirstSTM = dual<
|
|
556
|
-
<K, V, A, E, R>(
|
|
557
|
-
pf: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
558
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<A, E, R>,
|
|
559
|
-
<K, V, A, E, R>(self: TMap.TMap<K, V>, pf: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>) => STM.STM<A, E, R>
|
|
560
|
-
>(2, (self, pf) =>
|
|
561
|
-
pipe(
|
|
562
|
-
findSTM(self, (key, value) => core.map(pf(key, value), (a) => [key, a] as const)),
|
|
563
|
-
stm.collect((option) => Option.isSome(option) ? Option.some(option.value) : Option.none()),
|
|
564
|
-
core.flatMap((entry) => stm.as(remove(self, entry[0]), entry[1]))
|
|
565
|
-
))
|
|
566
|
-
|
|
567
|
-
/** @internal */
|
|
568
|
-
export const takeSome = dual<
|
|
569
|
-
<K, V, A>(
|
|
570
|
-
pf: (key: K, value: V) => Option.Option<A>
|
|
571
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<RA.NonEmptyArray<A>>,
|
|
572
|
-
<K, V, A>(
|
|
573
|
-
self: TMap.TMap<K, V>,
|
|
574
|
-
pf: (key: K, value: V) => Option.Option<A>
|
|
575
|
-
) => STM.STM<RA.NonEmptyArray<A>>
|
|
576
|
-
>(2, <K, V, A>(self: TMap.TMap<K, V>, pf: (key: K, value: V) => Option.Option<A>) =>
|
|
577
|
-
pipe(
|
|
578
|
-
core.effect<never, Option.Option<RA.NonEmptyArray<A>>>((journal) => {
|
|
579
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
580
|
-
const capacity = buckets.chunk.length
|
|
581
|
-
const builder: Array<A> = []
|
|
582
|
-
let newSize = 0
|
|
583
|
-
let index = 0
|
|
584
|
-
while (index < capacity) {
|
|
585
|
-
const bucket = tRef.unsafeGet(buckets.chunk[index], journal)
|
|
586
|
-
const recreate = Chunk.some(bucket, (entry) => Option.isSome(pf(entry[0], entry[1])))
|
|
587
|
-
if (recreate) {
|
|
588
|
-
const iterator = bucket[Symbol.iterator]()
|
|
589
|
-
let newBucket = Chunk.empty<readonly [K, V]>()
|
|
590
|
-
let next: IteratorResult<readonly [K, V], any>
|
|
591
|
-
while ((next = iterator.next()) && !next.done) {
|
|
592
|
-
const option = pf(next.value[0], next.value[1])
|
|
593
|
-
if (Option.isSome(option)) {
|
|
594
|
-
builder.push(option.value)
|
|
595
|
-
} else {
|
|
596
|
-
newBucket = Chunk.prepend(newBucket, next.value)
|
|
597
|
-
newSize = newSize + 1
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
tRef.unsafeSet(buckets.chunk[index], newBucket, journal)
|
|
601
|
-
} else {
|
|
602
|
-
newSize = newSize + bucket.length
|
|
603
|
-
}
|
|
604
|
-
index = index + 1
|
|
605
|
-
}
|
|
606
|
-
tRef.unsafeSet(self.tSize, newSize, journal)
|
|
607
|
-
if (builder.length > 0) {
|
|
608
|
-
return Option.some(builder as RA.NonEmptyArray<A>)
|
|
609
|
-
}
|
|
610
|
-
return Option.none()
|
|
611
|
-
}),
|
|
612
|
-
stm.collect((option) =>
|
|
613
|
-
Option.isSome(option) ?
|
|
614
|
-
Option.some(option.value) :
|
|
615
|
-
Option.none<RA.NonEmptyArray<A>>()
|
|
616
|
-
)
|
|
617
|
-
))
|
|
618
|
-
|
|
619
|
-
/** @internal */
|
|
620
|
-
export const takeSomeSTM = dual<
|
|
621
|
-
<K, V, A, E, R>(
|
|
622
|
-
pf: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
623
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<RA.NonEmptyArray<A>, E, R>,
|
|
624
|
-
<K, V, A, E, R>(
|
|
625
|
-
self: TMap.TMap<K, V>,
|
|
626
|
-
pf: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
627
|
-
) => STM.STM<RA.NonEmptyArray<A>, E, R>
|
|
628
|
-
>(2, <K, V, A, E, R>(
|
|
629
|
-
self: TMap.TMap<K, V>,
|
|
630
|
-
pf: (key: K, value: V) => STM.STM<A, Option.Option<E>, R>
|
|
631
|
-
) =>
|
|
632
|
-
pipe(
|
|
633
|
-
findAllSTM(
|
|
634
|
-
self,
|
|
635
|
-
(key, value) => core.map(pf(key, value), (a) => [key, a] as const)
|
|
636
|
-
),
|
|
637
|
-
core.map((chunk) =>
|
|
638
|
-
RA.isNonEmptyArray(chunk) ?
|
|
639
|
-
Option.some(chunk) :
|
|
640
|
-
Option.none()
|
|
641
|
-
),
|
|
642
|
-
stm.collect((option) =>
|
|
643
|
-
Option.isSome(option) ?
|
|
644
|
-
Option.some(option.value) :
|
|
645
|
-
Option.none()
|
|
646
|
-
),
|
|
647
|
-
core.flatMap((entries) =>
|
|
648
|
-
stm.as(
|
|
649
|
-
removeAll(self, entries.map((entry) => entry[0])),
|
|
650
|
-
RA.map(entries, (entry) => entry[1]) as RA.NonEmptyArray<A>
|
|
651
|
-
)
|
|
652
|
-
)
|
|
653
|
-
))
|
|
654
|
-
|
|
655
|
-
const toReadonlyArray = <K, V>(self: TMap.TMap<K, V>): STM.STM<ReadonlyArray<readonly [K, V]>> =>
|
|
656
|
-
core.effect<never, Array<readonly [K, V]>>((journal) => {
|
|
657
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
658
|
-
const capacity = buckets.chunk.length
|
|
659
|
-
const builder: Array<readonly [K, V]> = []
|
|
660
|
-
let index = 0
|
|
661
|
-
while (index < capacity) {
|
|
662
|
-
const bucket = buckets.chunk[index]
|
|
663
|
-
for (const entry of tRef.unsafeGet(bucket, journal)) {
|
|
664
|
-
builder.push(entry)
|
|
665
|
-
}
|
|
666
|
-
index = index + 1
|
|
667
|
-
}
|
|
668
|
-
return builder
|
|
669
|
-
})
|
|
670
|
-
|
|
671
|
-
/** @internal */
|
|
672
|
-
export const toChunk = <K, V>(self: TMap.TMap<K, V>): STM.STM<Chunk.Chunk<[K, V]>> =>
|
|
673
|
-
reduce(
|
|
674
|
-
self,
|
|
675
|
-
Chunk.empty<[K, V]>(),
|
|
676
|
-
(acc, value, key) => Chunk.append(acc, [key, value])
|
|
677
|
-
)
|
|
678
|
-
|
|
679
|
-
/** @internal */
|
|
680
|
-
export const toHashMap = <K, V>(self: TMap.TMap<K, V>): STM.STM<HashMap.HashMap<K, V>> =>
|
|
681
|
-
reduce(
|
|
682
|
-
self,
|
|
683
|
-
HashMap.empty<K, V>(),
|
|
684
|
-
(acc, value, key) => pipe(acc, HashMap.set(key, value))
|
|
685
|
-
)
|
|
686
|
-
|
|
687
|
-
/** @internal */
|
|
688
|
-
export const toArray = <K, V>(self: TMap.TMap<K, V>): STM.STM<Array<[K, V]>> =>
|
|
689
|
-
reduce(
|
|
690
|
-
self,
|
|
691
|
-
[] as Array<[K, V]>,
|
|
692
|
-
(acc, value, key) => {
|
|
693
|
-
acc.unshift([key, value])
|
|
694
|
-
return acc
|
|
695
|
-
}
|
|
696
|
-
)
|
|
697
|
-
|
|
698
|
-
/** @internal */
|
|
699
|
-
export const toMap = <K, V>(self: TMap.TMap<K, V>): STM.STM<Map<K, V>> =>
|
|
700
|
-
reduce(
|
|
701
|
-
self,
|
|
702
|
-
new Map<K, V>(),
|
|
703
|
-
(acc, value, key) => acc.set(key, value)
|
|
704
|
-
)
|
|
705
|
-
|
|
706
|
-
/** @internal */
|
|
707
|
-
export const transform = dual<
|
|
708
|
-
<K, V>(f: (key: K, value: V) => readonly [K, V]) => (self: TMap.TMap<K, V>) => STM.STM<void>,
|
|
709
|
-
<K, V>(self: TMap.TMap<K, V>, f: (key: K, value: V) => readonly [K, V]) => STM.STM<void>
|
|
710
|
-
>(
|
|
711
|
-
2,
|
|
712
|
-
<K, V>(self: TMap.TMap<K, V>, f: (key: K, value: V) => readonly [K, V]) =>
|
|
713
|
-
core.effect<never, void>((journal) => {
|
|
714
|
-
const buckets = pipe(self.tBuckets, tRef.unsafeGet(journal))
|
|
715
|
-
const capacity = buckets.chunk.length
|
|
716
|
-
const newBuckets = Array.from({ length: capacity }, () => Chunk.empty<readonly [K, V]>())
|
|
717
|
-
let newSize = 0
|
|
718
|
-
let index = 0
|
|
719
|
-
while (index < capacity) {
|
|
720
|
-
const bucket = buckets.chunk[index]
|
|
721
|
-
const pairs = tRef.unsafeGet(bucket, journal)
|
|
722
|
-
const iterator = pairs[Symbol.iterator]()
|
|
723
|
-
let next: IteratorResult<readonly [K, V], any>
|
|
724
|
-
while ((next = iterator.next()) && !next.done) {
|
|
725
|
-
const newPair = f(next.value[0], next.value[1])
|
|
726
|
-
const index = indexOf(newPair[0], capacity)
|
|
727
|
-
const newBucket = newBuckets[index]
|
|
728
|
-
if (!Chunk.some(newBucket, (entry) => Equal.equals(entry[0], newPair[0]))) {
|
|
729
|
-
newBuckets[index] = Chunk.prepend(newBucket, newPair)
|
|
730
|
-
newSize = newSize + 1
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
index = index + 1
|
|
734
|
-
}
|
|
735
|
-
index = 0
|
|
736
|
-
while (index < capacity) {
|
|
737
|
-
tRef.unsafeSet(buckets.chunk[index], newBuckets[index], journal)
|
|
738
|
-
index = index + 1
|
|
739
|
-
}
|
|
740
|
-
tRef.unsafeSet(self.tSize, newSize, journal)
|
|
741
|
-
})
|
|
742
|
-
)
|
|
743
|
-
|
|
744
|
-
/** @internal */
|
|
745
|
-
export const transformSTM = dual<
|
|
746
|
-
<K, V, R, E>(
|
|
747
|
-
f: (key: K, value: V) => STM.STM<readonly [K, V], E, R>
|
|
748
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<void, E, R>,
|
|
749
|
-
<K, V, R, E>(self: TMap.TMap<K, V>, f: (key: K, value: V) => STM.STM<readonly [K, V], E, R>) => STM.STM<void, E, R>
|
|
750
|
-
>(
|
|
751
|
-
2,
|
|
752
|
-
<K, V, R, E>(self: TMap.TMap<K, V>, f: (key: K, value: V) => STM.STM<readonly [K, V], E, R>) =>
|
|
753
|
-
pipe(
|
|
754
|
-
core.flatMap(
|
|
755
|
-
toReadonlyArray(self),
|
|
756
|
-
stm.forEach((entry) => f(entry[0], entry[1]))
|
|
757
|
-
),
|
|
758
|
-
core.flatMap((newData) =>
|
|
759
|
-
core.effect<never, void>((journal) => {
|
|
760
|
-
const buckets = tRef.unsafeGet(self.tBuckets, journal)
|
|
761
|
-
const capacity = buckets.chunk.length
|
|
762
|
-
const newBuckets = Array.from({ length: capacity }, () => Chunk.empty<readonly [K, V]>())
|
|
763
|
-
const iterator = newData[Symbol.iterator]()
|
|
764
|
-
let newSize = 0
|
|
765
|
-
let next: IteratorResult<readonly [K, V], any>
|
|
766
|
-
while ((next = iterator.next()) && !next.done) {
|
|
767
|
-
const index = indexOf(next.value[0], capacity)
|
|
768
|
-
const newBucket = newBuckets[index]
|
|
769
|
-
if (!Chunk.some(newBucket, (entry) => Equal.equals(entry[0])(next.value[0]))) {
|
|
770
|
-
newBuckets[index] = Chunk.prepend(newBucket, next.value)
|
|
771
|
-
newSize = newSize + 1
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
let index = 0
|
|
775
|
-
while (index < capacity) {
|
|
776
|
-
tRef.unsafeSet(buckets.chunk[index], newBuckets[index], journal)
|
|
777
|
-
index = index + 1
|
|
778
|
-
}
|
|
779
|
-
tRef.unsafeSet(self.tSize, newSize, journal)
|
|
780
|
-
})
|
|
781
|
-
)
|
|
782
|
-
)
|
|
783
|
-
)
|
|
784
|
-
|
|
785
|
-
/** @internal */
|
|
786
|
-
export const transformValues = dual<
|
|
787
|
-
<V>(f: (value: V) => V) => <K>(self: TMap.TMap<K, V>) => STM.STM<void>,
|
|
788
|
-
<K, V>(self: TMap.TMap<K, V>, f: (value: V) => V) => STM.STM<void>
|
|
789
|
-
>(2, (self, f) => transform(self, (key, value) => [key, f(value)]))
|
|
790
|
-
|
|
791
|
-
/** @internal */
|
|
792
|
-
export const transformValuesSTM = dual<
|
|
793
|
-
<V, R, E>(f: (value: V) => STM.STM<V, E, R>) => <K>(self: TMap.TMap<K, V>) => STM.STM<void, E, R>,
|
|
794
|
-
<K, V, R, E>(self: TMap.TMap<K, V>, f: (value: V) => STM.STM<V, E, R>) => STM.STM<void, E, R>
|
|
795
|
-
>(2, (self, f) =>
|
|
796
|
-
transformSTM(
|
|
797
|
-
self,
|
|
798
|
-
(key, value) => core.map(f(value), (value) => [key, value])
|
|
799
|
-
))
|
|
800
|
-
|
|
801
|
-
/** @internal */
|
|
802
|
-
export const updateWith = dual<
|
|
803
|
-
<K, V>(
|
|
804
|
-
key: K,
|
|
805
|
-
f: (value: Option.Option<V>) => Option.Option<V>
|
|
806
|
-
) => (self: TMap.TMap<K, V>) => STM.STM<Option.Option<V>>,
|
|
807
|
-
<K, V>(
|
|
808
|
-
self: TMap.TMap<K, V>,
|
|
809
|
-
key: K,
|
|
810
|
-
f: (value: Option.Option<V>) => Option.Option<V>
|
|
811
|
-
) => STM.STM<Option.Option<V>>
|
|
812
|
-
>(3, (self, key, f) =>
|
|
813
|
-
core.flatMap(get(self, key), (option) =>
|
|
814
|
-
Option.match(
|
|
815
|
-
f(option),
|
|
816
|
-
{
|
|
817
|
-
onNone: () => stm.as(remove(self, key), Option.none()),
|
|
818
|
-
onSome: (value) => stm.as(set(self, key, value), Option.some(value))
|
|
819
|
-
}
|
|
820
|
-
)))
|
|
821
|
-
|
|
822
|
-
/** @internal */
|
|
823
|
-
export const values = <K, V>(self: TMap.TMap<K, V>): STM.STM<Array<V>> =>
|
|
824
|
-
core.map(toReadonlyArray(self), RA.map((entry) => entry[1]))
|