@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/matcher.ts
DELETED
|
@@ -1,652 +0,0 @@
|
|
|
1
|
-
import * as Either from "../Either.js"
|
|
2
|
-
import { dual, identity } from "../Function.js"
|
|
3
|
-
import type {
|
|
4
|
-
Case,
|
|
5
|
-
Matcher,
|
|
6
|
-
MatcherTypeId,
|
|
7
|
-
Not,
|
|
8
|
-
SafeRefinement,
|
|
9
|
-
TypeMatcher,
|
|
10
|
-
Types,
|
|
11
|
-
ValueMatcher,
|
|
12
|
-
When
|
|
13
|
-
} from "../Match.js"
|
|
14
|
-
import * as Option from "../Option.js"
|
|
15
|
-
import { pipeArguments } from "../Pipeable.js"
|
|
16
|
-
import type * as Predicate from "../Predicate.js"
|
|
17
|
-
import type { Unify } from "../Unify.js"
|
|
18
|
-
|
|
19
|
-
/** @internal */
|
|
20
|
-
export const TypeId: MatcherTypeId = Symbol.for(
|
|
21
|
-
"@effect/matcher/Matcher"
|
|
22
|
-
) as MatcherTypeId
|
|
23
|
-
|
|
24
|
-
const TypeMatcherProto: Omit<TypeMatcher<any, any, any, any>, "cases"> = {
|
|
25
|
-
[TypeId]: {
|
|
26
|
-
_input: identity,
|
|
27
|
-
_filters: identity,
|
|
28
|
-
_remaining: identity,
|
|
29
|
-
_result: identity,
|
|
30
|
-
_return: identity
|
|
31
|
-
},
|
|
32
|
-
_tag: "TypeMatcher",
|
|
33
|
-
add<I, R, RA, A>(
|
|
34
|
-
this: TypeMatcher<any, any, any, any>,
|
|
35
|
-
_case: Case
|
|
36
|
-
): TypeMatcher<I, R, RA, A> {
|
|
37
|
-
return makeTypeMatcher([...this.cases, _case])
|
|
38
|
-
},
|
|
39
|
-
pipe() {
|
|
40
|
-
return pipeArguments(this, arguments)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function makeTypeMatcher<I, R, RA, A>(
|
|
45
|
-
cases: ReadonlyArray<Case>
|
|
46
|
-
): TypeMatcher<I, R, RA, A> {
|
|
47
|
-
const matcher = Object.create(TypeMatcherProto)
|
|
48
|
-
matcher.cases = cases
|
|
49
|
-
return matcher
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const ValueMatcherProto: Omit<
|
|
53
|
-
ValueMatcher<any, any, any, any, any>,
|
|
54
|
-
"provided" | "value"
|
|
55
|
-
> = {
|
|
56
|
-
[TypeId]: {
|
|
57
|
-
_input: identity,
|
|
58
|
-
_filters: identity,
|
|
59
|
-
_remaining: identity,
|
|
60
|
-
_result: identity,
|
|
61
|
-
_provided: identity,
|
|
62
|
-
_return: identity
|
|
63
|
-
},
|
|
64
|
-
_tag: "ValueMatcher",
|
|
65
|
-
add<I, R, RA, A, Pr>(
|
|
66
|
-
this: ValueMatcher<any, any, any, any, any>,
|
|
67
|
-
_case: Case
|
|
68
|
-
): ValueMatcher<I, R, RA, A, Pr> {
|
|
69
|
-
if (this.value._tag === "Right") {
|
|
70
|
-
return this
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (_case._tag === "When" && _case.guard(this.provided) === true) {
|
|
74
|
-
return makeValueMatcher(
|
|
75
|
-
this.provided,
|
|
76
|
-
Either.right(_case.evaluate(this.provided))
|
|
77
|
-
)
|
|
78
|
-
} else if (_case._tag === "Not" && _case.guard(this.provided) === false) {
|
|
79
|
-
return makeValueMatcher(
|
|
80
|
-
this.provided,
|
|
81
|
-
Either.right(_case.evaluate(this.provided))
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return this
|
|
86
|
-
},
|
|
87
|
-
pipe() {
|
|
88
|
-
return pipeArguments(this, arguments)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function makeValueMatcher<I, R, RA, A, Pr>(
|
|
93
|
-
provided: Pr,
|
|
94
|
-
value: Either.Either<Pr, RA>
|
|
95
|
-
): ValueMatcher<I, R, RA, A, Pr> {
|
|
96
|
-
const matcher = Object.create(ValueMatcherProto)
|
|
97
|
-
matcher.provided = provided
|
|
98
|
-
matcher.value = value
|
|
99
|
-
return matcher
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const makeWhen = (
|
|
103
|
-
guard: (u: unknown) => boolean,
|
|
104
|
-
evaluate: (input: unknown) => any
|
|
105
|
-
): When => ({
|
|
106
|
-
_tag: "When",
|
|
107
|
-
guard,
|
|
108
|
-
evaluate
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
const makeNot = (
|
|
112
|
-
guard: (u: unknown) => boolean,
|
|
113
|
-
evaluate: (input: unknown) => any
|
|
114
|
-
): Not => ({
|
|
115
|
-
_tag: "Not",
|
|
116
|
-
guard,
|
|
117
|
-
evaluate
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
const makePredicate = (pattern: unknown): Predicate.Predicate<unknown> => {
|
|
121
|
-
if (typeof pattern === "function") {
|
|
122
|
-
return pattern as Predicate.Predicate<unknown>
|
|
123
|
-
} else if (Array.isArray(pattern)) {
|
|
124
|
-
const predicates = pattern.map(makePredicate)
|
|
125
|
-
const len = predicates.length
|
|
126
|
-
|
|
127
|
-
return (u: unknown) => {
|
|
128
|
-
if (!Array.isArray(u)) {
|
|
129
|
-
return false
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
for (let i = 0; i < len; i++) {
|
|
133
|
-
if (predicates[i](u[i]) === false) {
|
|
134
|
-
return false
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return true
|
|
139
|
-
}
|
|
140
|
-
} else if (pattern !== null && typeof pattern === "object") {
|
|
141
|
-
const keysAndPredicates = Object.entries(pattern).map(
|
|
142
|
-
([k, p]) => [k, makePredicate(p)] as const
|
|
143
|
-
)
|
|
144
|
-
const len = keysAndPredicates.length
|
|
145
|
-
|
|
146
|
-
return (u: unknown) => {
|
|
147
|
-
if (typeof u !== "object" || u === null) {
|
|
148
|
-
return false
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
for (let i = 0; i < len; i++) {
|
|
152
|
-
const [key, predicate] = keysAndPredicates[i]
|
|
153
|
-
if (!(key in u) || predicate((u as any)[key]) === false) {
|
|
154
|
-
return false
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return true
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return (u: unknown) => u === pattern
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const makeOrPredicate = (
|
|
166
|
-
patterns: ReadonlyArray<unknown>
|
|
167
|
-
): Predicate.Predicate<unknown> => {
|
|
168
|
-
const predicates = patterns.map(makePredicate)
|
|
169
|
-
const len = predicates.length
|
|
170
|
-
|
|
171
|
-
return (u: unknown) => {
|
|
172
|
-
for (let i = 0; i < len; i++) {
|
|
173
|
-
if (predicates[i](u) === true) {
|
|
174
|
-
return true
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return false
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const makeAndPredicate = (
|
|
183
|
-
patterns: ReadonlyArray<unknown>
|
|
184
|
-
): Predicate.Predicate<unknown> => {
|
|
185
|
-
const predicates = patterns.map(makePredicate)
|
|
186
|
-
const len = predicates.length
|
|
187
|
-
|
|
188
|
-
return (u: unknown) => {
|
|
189
|
-
for (let i = 0; i < len; i++) {
|
|
190
|
-
if (predicates[i](u) === false) {
|
|
191
|
-
return false
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return true
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/** @internal */
|
|
200
|
-
export const type = <I>(): Matcher<
|
|
201
|
-
I,
|
|
202
|
-
Types.Without<never>,
|
|
203
|
-
I,
|
|
204
|
-
never,
|
|
205
|
-
never
|
|
206
|
-
> => makeTypeMatcher([])
|
|
207
|
-
|
|
208
|
-
/** @internal */
|
|
209
|
-
export const value = <const I>(
|
|
210
|
-
i: I
|
|
211
|
-
): Matcher<I, Types.Without<never>, I, never, I> => makeValueMatcher(i, Either.left(i))
|
|
212
|
-
|
|
213
|
-
/** @internal */
|
|
214
|
-
export const valueTags: {
|
|
215
|
-
<
|
|
216
|
-
const I,
|
|
217
|
-
P extends
|
|
218
|
-
& { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, { readonly _tag: Tag }>) => any }
|
|
219
|
-
& { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never }
|
|
220
|
-
>(fields: P): (input: I) => Unify<ReturnType<P[keyof P]>>
|
|
221
|
-
<
|
|
222
|
-
const I,
|
|
223
|
-
P extends
|
|
224
|
-
& { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, { readonly _tag: Tag }>) => any }
|
|
225
|
-
& { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never }
|
|
226
|
-
>(input: I, fields: P): Unify<ReturnType<P[keyof P]>>
|
|
227
|
-
} = dual(
|
|
228
|
-
2,
|
|
229
|
-
<
|
|
230
|
-
const I,
|
|
231
|
-
P extends
|
|
232
|
-
& { readonly [Tag in Types.Tags<"_tag", I> & string]: (_: Extract<I, { readonly _tag: Tag }>) => any }
|
|
233
|
-
& { readonly [Tag in Exclude<keyof P, Types.Tags<"_tag", I>>]: never }
|
|
234
|
-
>(input: I, fields: P): Unify<ReturnType<P[keyof P]>> => {
|
|
235
|
-
const match: any = tagsExhaustive(fields as any)(makeTypeMatcher([]))
|
|
236
|
-
return match(input)
|
|
237
|
-
}
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
/** @internal */
|
|
241
|
-
export const typeTags = <I>() =>
|
|
242
|
-
<
|
|
243
|
-
P extends {
|
|
244
|
-
readonly [Tag in Types.Tags<"_tag", I> & string]: (
|
|
245
|
-
_: Extract<I, { readonly _tag: Tag }>
|
|
246
|
-
) => any
|
|
247
|
-
}
|
|
248
|
-
>(
|
|
249
|
-
fields: P
|
|
250
|
-
) => {
|
|
251
|
-
const match: any = tagsExhaustive(fields as any)(makeTypeMatcher([]))
|
|
252
|
-
return (input: I): Unify<ReturnType<P[keyof P]>> => match(input)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/** @internal */
|
|
256
|
-
export const withReturnType = <Ret>() =>
|
|
257
|
-
<I, F, R, A, Pr, _>(self: Matcher<I, F, R, A, Pr, _>): [Ret] extends [
|
|
258
|
-
[A] extends [never] ? any : A
|
|
259
|
-
] ? Matcher<I, F, R, A, Pr, Ret>
|
|
260
|
-
: "withReturnType constraint does not extend Result type" => self as any
|
|
261
|
-
|
|
262
|
-
/** @internal */
|
|
263
|
-
export const when = <
|
|
264
|
-
R,
|
|
265
|
-
const P extends Types.PatternPrimitive<R> | Types.PatternBase<R>,
|
|
266
|
-
Ret,
|
|
267
|
-
Fn extends (_: Types.WhenMatch<R, P>) => Ret
|
|
268
|
-
>(
|
|
269
|
-
pattern: P,
|
|
270
|
-
f: Fn
|
|
271
|
-
) =>
|
|
272
|
-
<I, F, A, Pr>(
|
|
273
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
274
|
-
): Matcher<
|
|
275
|
-
I,
|
|
276
|
-
Types.AddWithout<F, Types.PForExclude<P>>,
|
|
277
|
-
Types.ApplyFilters<I, Types.AddWithout<F, Types.PForExclude<P>>>,
|
|
278
|
-
A | ReturnType<Fn>,
|
|
279
|
-
Pr,
|
|
280
|
-
Ret
|
|
281
|
-
> => (self as any).add(makeWhen(makePredicate(pattern), f as any))
|
|
282
|
-
|
|
283
|
-
/** @internal */
|
|
284
|
-
export const whenOr = <
|
|
285
|
-
R,
|
|
286
|
-
const P extends ReadonlyArray<
|
|
287
|
-
Types.PatternPrimitive<R> | Types.PatternBase<R>
|
|
288
|
-
>,
|
|
289
|
-
Ret,
|
|
290
|
-
Fn extends (_: Types.WhenMatch<R, P[number]>) => Ret
|
|
291
|
-
>(
|
|
292
|
-
...args: [...patterns: P, f: Fn]
|
|
293
|
-
) =>
|
|
294
|
-
<I, F, A, Pr>(
|
|
295
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
296
|
-
): Matcher<
|
|
297
|
-
I,
|
|
298
|
-
Types.AddWithout<F, Types.PForExclude<P[number]>>,
|
|
299
|
-
Types.ApplyFilters<I, Types.AddWithout<F, Types.PForExclude<P[number]>>>,
|
|
300
|
-
A | ReturnType<Fn>,
|
|
301
|
-
Pr,
|
|
302
|
-
Ret
|
|
303
|
-
> => {
|
|
304
|
-
const onMatch = args[args.length - 1] as any
|
|
305
|
-
const patterns = args.slice(0, -1) as unknown as P
|
|
306
|
-
return (self as any).add(makeWhen(makeOrPredicate(patterns), onMatch))
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** @internal */
|
|
310
|
-
export const whenAnd = <
|
|
311
|
-
R,
|
|
312
|
-
const P extends ReadonlyArray<
|
|
313
|
-
Types.PatternPrimitive<R> | Types.PatternBase<R>
|
|
314
|
-
>,
|
|
315
|
-
Ret,
|
|
316
|
-
Fn extends (_: Types.WhenMatch<R, Types.ArrayToIntersection<P>>) => Ret
|
|
317
|
-
>(
|
|
318
|
-
...args: [...patterns: P, f: Fn]
|
|
319
|
-
) =>
|
|
320
|
-
<I, F, A, Pr>(
|
|
321
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
322
|
-
): Matcher<
|
|
323
|
-
I,
|
|
324
|
-
Types.AddWithout<F, Types.PForExclude<Types.ArrayToIntersection<P>>>,
|
|
325
|
-
Types.ApplyFilters<
|
|
326
|
-
I,
|
|
327
|
-
Types.AddWithout<F, Types.PForExclude<Types.ArrayToIntersection<P>>>
|
|
328
|
-
>,
|
|
329
|
-
A | ReturnType<Fn>,
|
|
330
|
-
Pr
|
|
331
|
-
> => {
|
|
332
|
-
const onMatch = args[args.length - 1] as any
|
|
333
|
-
const patterns = args.slice(0, -1) as unknown as P
|
|
334
|
-
return (self as any).add(makeWhen(makeAndPredicate(patterns), onMatch))
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/** @internal */
|
|
338
|
-
export const discriminator = <D extends string>(field: D) =>
|
|
339
|
-
<
|
|
340
|
-
R,
|
|
341
|
-
P extends Types.Tags<D, R> & string,
|
|
342
|
-
Ret,
|
|
343
|
-
Fn extends (_: Extract<R, Record<D, P>>) => Ret
|
|
344
|
-
>(
|
|
345
|
-
...pattern: [
|
|
346
|
-
first: P,
|
|
347
|
-
...values: Array<P>,
|
|
348
|
-
f: Fn
|
|
349
|
-
]
|
|
350
|
-
) => {
|
|
351
|
-
const f = pattern[pattern.length - 1]
|
|
352
|
-
const values: Array<P> = pattern.slice(0, -1) as any
|
|
353
|
-
const pred = values.length === 1
|
|
354
|
-
? (_: any) => _[field] === values[0]
|
|
355
|
-
: (_: any) => values.includes(_[field])
|
|
356
|
-
|
|
357
|
-
return <I, F, A, Pr>(
|
|
358
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
359
|
-
): Matcher<
|
|
360
|
-
I,
|
|
361
|
-
Types.AddWithout<F, Extract<R, Record<D, P>>>,
|
|
362
|
-
Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, P>>>>,
|
|
363
|
-
A | ReturnType<Fn>,
|
|
364
|
-
Pr,
|
|
365
|
-
Ret
|
|
366
|
-
> => (self as any).add(makeWhen(pred, f as any)) as any
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/** @internal */
|
|
370
|
-
export const discriminatorStartsWith = <D extends string>(field: D) =>
|
|
371
|
-
<
|
|
372
|
-
R,
|
|
373
|
-
P extends string,
|
|
374
|
-
Ret,
|
|
375
|
-
Fn extends (_: Extract<R, Record<D, `${P}${string}`>>) => Ret
|
|
376
|
-
>(
|
|
377
|
-
pattern: P,
|
|
378
|
-
f: Fn
|
|
379
|
-
) => {
|
|
380
|
-
const pred = (_: any) => typeof _[field] === "string" && _[field].startsWith(pattern)
|
|
381
|
-
|
|
382
|
-
return <I, F, A, Pr>(
|
|
383
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
384
|
-
): Matcher<
|
|
385
|
-
I,
|
|
386
|
-
Types.AddWithout<F, Extract<R, Record<D, `${P}${string}`>>>,
|
|
387
|
-
Types.ApplyFilters<
|
|
388
|
-
I,
|
|
389
|
-
Types.AddWithout<F, Extract<R, Record<D, `${P}${string}`>>>
|
|
390
|
-
>,
|
|
391
|
-
A | ReturnType<Fn>,
|
|
392
|
-
Pr,
|
|
393
|
-
Ret
|
|
394
|
-
> => (self as any).add(makeWhen(pred, f as any)) as any
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/** @internal */
|
|
398
|
-
export const discriminators = <D extends string>(field: D) =>
|
|
399
|
-
<
|
|
400
|
-
R,
|
|
401
|
-
Ret,
|
|
402
|
-
P extends
|
|
403
|
-
& {
|
|
404
|
-
readonly [Tag in Types.Tags<D, R> & string]?:
|
|
405
|
-
| ((_: Extract<R, Record<D, Tag>>) => Ret)
|
|
406
|
-
| undefined
|
|
407
|
-
}
|
|
408
|
-
& { readonly [Tag in Exclude<keyof P, Types.Tags<D, R>>]: never }
|
|
409
|
-
>(
|
|
410
|
-
fields: P
|
|
411
|
-
) => {
|
|
412
|
-
const predicate = makeWhen(
|
|
413
|
-
(arg: any) => arg != null && arg[field] in fields,
|
|
414
|
-
(data: any) => (fields as any)[data[field]](data)
|
|
415
|
-
)
|
|
416
|
-
|
|
417
|
-
return <I, F, A, Pr>(
|
|
418
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
419
|
-
): Matcher<
|
|
420
|
-
I,
|
|
421
|
-
Types.AddWithout<F, Extract<R, Record<D, keyof P>>>,
|
|
422
|
-
Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<D, keyof P>>>>,
|
|
423
|
-
A | ReturnType<P[keyof P] & {}>,
|
|
424
|
-
Pr,
|
|
425
|
-
Ret
|
|
426
|
-
> => (self as any).add(predicate)
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/** @internal */
|
|
430
|
-
export const discriminatorsExhaustive: <D extends string>(
|
|
431
|
-
field: D
|
|
432
|
-
) => <
|
|
433
|
-
R,
|
|
434
|
-
Ret,
|
|
435
|
-
P extends
|
|
436
|
-
& {
|
|
437
|
-
readonly [Tag in Types.Tags<D, R> & string]: (
|
|
438
|
-
_: Extract<R, Record<D, Tag>>
|
|
439
|
-
) => Ret
|
|
440
|
-
}
|
|
441
|
-
& { readonly [Tag in Exclude<keyof P, Types.Tags<D, R>>]: never }
|
|
442
|
-
>(
|
|
443
|
-
fields: P
|
|
444
|
-
) => <I, F, A, Pr>(
|
|
445
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
446
|
-
) => [Pr] extends [never] ? (u: I) => Unify<A | ReturnType<P[keyof P]>>
|
|
447
|
-
: Unify<A | ReturnType<P[keyof P]>> = (field: string) => (fields: object) => {
|
|
448
|
-
const addCases = discriminators(field)(fields)
|
|
449
|
-
return (matcher: any) => exhaustive(addCases(matcher))
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/** @internal */
|
|
453
|
-
export const tag: <
|
|
454
|
-
R,
|
|
455
|
-
P extends Types.Tags<"_tag", R> & string,
|
|
456
|
-
Ret,
|
|
457
|
-
Fn extends (_: Extract<R, Record<"_tag", P>>) => Ret
|
|
458
|
-
>(
|
|
459
|
-
...pattern: [
|
|
460
|
-
first: P,
|
|
461
|
-
...values: Array<P>,
|
|
462
|
-
f: Fn
|
|
463
|
-
]
|
|
464
|
-
) => <I, F, A, Pr>(
|
|
465
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
466
|
-
) => Matcher<
|
|
467
|
-
I,
|
|
468
|
-
Types.AddWithout<F, Extract<R, Record<"_tag", P>>>,
|
|
469
|
-
Types.ApplyFilters<I, Types.AddWithout<F, Extract<R, Record<"_tag", P>>>>,
|
|
470
|
-
ReturnType<Fn> | A,
|
|
471
|
-
Pr,
|
|
472
|
-
Ret
|
|
473
|
-
> = discriminator("_tag")
|
|
474
|
-
|
|
475
|
-
/** @internal */
|
|
476
|
-
export const tagStartsWith = discriminatorStartsWith("_tag")
|
|
477
|
-
|
|
478
|
-
/** @internal */
|
|
479
|
-
export const tags = discriminators("_tag")
|
|
480
|
-
|
|
481
|
-
/** @internal */
|
|
482
|
-
export const tagsExhaustive = discriminatorsExhaustive("_tag")
|
|
483
|
-
|
|
484
|
-
/** @internal */
|
|
485
|
-
export const not = <
|
|
486
|
-
R,
|
|
487
|
-
const P extends Types.PatternPrimitive<R> | Types.PatternBase<R>,
|
|
488
|
-
Ret,
|
|
489
|
-
Fn extends (_: Types.NotMatch<R, P>) => Ret
|
|
490
|
-
>(
|
|
491
|
-
pattern: P,
|
|
492
|
-
f: Fn
|
|
493
|
-
) =>
|
|
494
|
-
<I, F, A, Pr>(
|
|
495
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
496
|
-
): Matcher<
|
|
497
|
-
I,
|
|
498
|
-
Types.AddOnly<F, Types.WhenMatch<R, P>>,
|
|
499
|
-
Types.ApplyFilters<I, Types.AddOnly<F, Types.WhenMatch<R, P>>>,
|
|
500
|
-
A | ReturnType<Fn>,
|
|
501
|
-
Pr,
|
|
502
|
-
Ret
|
|
503
|
-
> => (self as any).add(makeNot(makePredicate(pattern), f as any))
|
|
504
|
-
|
|
505
|
-
/** @internal */
|
|
506
|
-
export const nonEmptyString: SafeRefinement<string, never> =
|
|
507
|
-
((u: unknown) => typeof u === "string" && u.length > 0) as any
|
|
508
|
-
|
|
509
|
-
/** @internal */
|
|
510
|
-
export const is: <
|
|
511
|
-
Literals extends ReadonlyArray<string | number | boolean | null | bigint>
|
|
512
|
-
>(
|
|
513
|
-
...literals: Literals
|
|
514
|
-
) => SafeRefinement<Literals[number]> = (...literals): any => {
|
|
515
|
-
const len = literals.length
|
|
516
|
-
return (u: unknown) => {
|
|
517
|
-
for (let i = 0; i < len; i++) {
|
|
518
|
-
if (u === literals[i]) {
|
|
519
|
-
return true
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
return false
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/** @internal */
|
|
527
|
-
export const any: SafeRefinement<unknown, any> = (() => true) as any
|
|
528
|
-
|
|
529
|
-
/** @internal */
|
|
530
|
-
export const defined = <A>(u: A): u is A & {} => (u !== undefined && u !== null) as any
|
|
531
|
-
|
|
532
|
-
/** @internal */
|
|
533
|
-
export const instanceOf = <A extends abstract new(...args: any) => any>(
|
|
534
|
-
constructor: A
|
|
535
|
-
): SafeRefinement<InstanceType<A>, never> => ((u: unknown) => u instanceof constructor) as any
|
|
536
|
-
|
|
537
|
-
/** @internal */
|
|
538
|
-
export const instanceOfUnsafe: <A extends abstract new(...args: any) => any>(
|
|
539
|
-
constructor: A
|
|
540
|
-
) => SafeRefinement<InstanceType<A>, InstanceType<A>> = instanceOf
|
|
541
|
-
|
|
542
|
-
/** @internal */
|
|
543
|
-
export const orElse =
|
|
544
|
-
<RA, Ret, F extends (_: RA) => Ret>(f: F) =>
|
|
545
|
-
<I, R, A, Pr>(self: Matcher<I, R, RA, A, Pr, Ret>): [Pr] extends [never] ? (input: I) => Unify<ReturnType<F> | A>
|
|
546
|
-
: Unify<ReturnType<F> | A> =>
|
|
547
|
-
{
|
|
548
|
-
const result = either(self)
|
|
549
|
-
|
|
550
|
-
if (Either.isEither(result)) {
|
|
551
|
-
// @ts-expect-error
|
|
552
|
-
return result._tag === "Right" ? result.right : f(result.left)
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// @ts-expect-error
|
|
556
|
-
return (input: I) => {
|
|
557
|
-
const a = result(input)
|
|
558
|
-
return a._tag === "Right" ? a.right : f(a.left)
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/** @internal */
|
|
563
|
-
export const orElseAbsurd = <I, R, RA, A, Pr, Ret>(
|
|
564
|
-
self: Matcher<I, R, RA, A, Pr, Ret>
|
|
565
|
-
): [Pr] extends [never] ? (input: I) => Unify<A> : Unify<A> =>
|
|
566
|
-
orElse(() => {
|
|
567
|
-
throw new Error("effect/Match/orElseAbsurd: absurd")
|
|
568
|
-
})(self)
|
|
569
|
-
|
|
570
|
-
/** @internal */
|
|
571
|
-
export const either: <I, F, R, A, Pr, Ret>(
|
|
572
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
573
|
-
) => [Pr] extends [never] ? (input: I) => Either.Either<Unify<A>, R>
|
|
574
|
-
: Either.Either<Unify<A>, R> = (<I, R, RA, A>(self: Matcher<I, R, RA, A, I>) => {
|
|
575
|
-
if (self._tag === "ValueMatcher") {
|
|
576
|
-
return self.value
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
const len = self.cases.length
|
|
580
|
-
if (len === 1) {
|
|
581
|
-
const _case = self.cases[0]
|
|
582
|
-
return (input: I): Either.Either<A, RA> => {
|
|
583
|
-
if (_case._tag === "When" && _case.guard(input) === true) {
|
|
584
|
-
return Either.right(_case.evaluate(input))
|
|
585
|
-
} else if (_case._tag === "Not" && _case.guard(input) === false) {
|
|
586
|
-
return Either.right(_case.evaluate(input))
|
|
587
|
-
}
|
|
588
|
-
return Either.left(input as any)
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
return (input: I): Either.Either<A, RA> => {
|
|
592
|
-
for (let i = 0; i < len; i++) {
|
|
593
|
-
const _case = self.cases[i]
|
|
594
|
-
if (_case._tag === "When" && _case.guard(input) === true) {
|
|
595
|
-
return Either.right(_case.evaluate(input))
|
|
596
|
-
} else if (_case._tag === "Not" && _case.guard(input) === false) {
|
|
597
|
-
return Either.right(_case.evaluate(input))
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
return Either.left(input as any)
|
|
602
|
-
}
|
|
603
|
-
}) as any
|
|
604
|
-
|
|
605
|
-
/** @internal */
|
|
606
|
-
export const option: <I, F, R, A, Pr, Ret>(
|
|
607
|
-
self: Matcher<I, F, R, A, Pr, Ret>
|
|
608
|
-
) => [Pr] extends [never] ? (input: I) => Option.Option<Unify<A>>
|
|
609
|
-
: Option.Option<Unify<A>> = (<I, A>(self: Matcher<I, any, any, A, I>) => {
|
|
610
|
-
const toEither = either(self)
|
|
611
|
-
if (Either.isEither(toEither)) {
|
|
612
|
-
return Either.match(toEither, {
|
|
613
|
-
onLeft: () => Option.none(),
|
|
614
|
-
onRight: Option.some
|
|
615
|
-
})
|
|
616
|
-
}
|
|
617
|
-
return (input: I): Option.Option<A> =>
|
|
618
|
-
Either.match((toEither as any)(input), {
|
|
619
|
-
onLeft: () => Option.none(),
|
|
620
|
-
onRight: Option.some as any
|
|
621
|
-
})
|
|
622
|
-
}) as any
|
|
623
|
-
|
|
624
|
-
const getExhaustiveAbsurdErrorMessage = "effect/Match/exhaustive: absurd"
|
|
625
|
-
|
|
626
|
-
/** @internal */
|
|
627
|
-
export const exhaustive: <I, F, A, Pr, Ret>(
|
|
628
|
-
self: Matcher<I, F, never, A, Pr, Ret>
|
|
629
|
-
) => [Pr] extends [never] ? (u: I) => Unify<A> : Unify<A> = (<I, F, A>(
|
|
630
|
-
self: Matcher<I, F, never, A, I>
|
|
631
|
-
) => {
|
|
632
|
-
const toEither = either(self as any)
|
|
633
|
-
|
|
634
|
-
if (Either.isEither(toEither)) {
|
|
635
|
-
if (toEither._tag === "Right") {
|
|
636
|
-
return toEither.right
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
throw new Error(getExhaustiveAbsurdErrorMessage)
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
return (u: I): A => {
|
|
643
|
-
// @ts-expect-error
|
|
644
|
-
const result = toEither(u)
|
|
645
|
-
|
|
646
|
-
if (result._tag === "Right") {
|
|
647
|
-
return result.right as any
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
throw new Error(getExhaustiveAbsurdErrorMessage)
|
|
651
|
-
}
|
|
652
|
-
}) as any
|