@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/Chunk.ts
DELETED
|
@@ -1,1495 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 2.0.0
|
|
3
|
-
*/
|
|
4
|
-
import * as RA from "./Array.js"
|
|
5
|
-
import type { NonEmptyReadonlyArray } from "./Array.js"
|
|
6
|
-
import type { Either } from "./Either.js"
|
|
7
|
-
import * as Equal from "./Equal.js"
|
|
8
|
-
import * as Equivalence from "./Equivalence.js"
|
|
9
|
-
import { dual, identity, pipe } from "./Function.js"
|
|
10
|
-
import * as Hash from "./Hash.js"
|
|
11
|
-
import type { TypeLambda } from "./HKT.js"
|
|
12
|
-
import { format, type Inspectable, NodeInspectSymbol, toJSON } from "./Inspectable.js"
|
|
13
|
-
import type { NonEmptyIterable } from "./NonEmptyIterable.js"
|
|
14
|
-
import type { Option } from "./Option.js"
|
|
15
|
-
import * as O from "./Option.js"
|
|
16
|
-
import * as Order from "./Order.js"
|
|
17
|
-
import type { Pipeable } from "./Pipeable.js"
|
|
18
|
-
import { pipeArguments } from "./Pipeable.js"
|
|
19
|
-
import { hasProperty, type Predicate, type Refinement } from "./Predicate.js"
|
|
20
|
-
import type { Covariant, NoInfer } from "./Types.js"
|
|
21
|
-
|
|
22
|
-
const TypeId: unique symbol = Symbol.for("effect/Chunk") as TypeId
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @category symbol
|
|
26
|
-
* @since 2.0.0
|
|
27
|
-
*/
|
|
28
|
-
export type TypeId = typeof TypeId
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @category models
|
|
32
|
-
* @since 2.0.0
|
|
33
|
-
*/
|
|
34
|
-
export interface Chunk<out A> extends Iterable<A>, Equal.Equal, Pipeable, Inspectable {
|
|
35
|
-
readonly [TypeId]: {
|
|
36
|
-
readonly _A: Covariant<A>
|
|
37
|
-
}
|
|
38
|
-
readonly length: number
|
|
39
|
-
/** @internal */
|
|
40
|
-
right: Chunk<A>
|
|
41
|
-
/** @internal */
|
|
42
|
-
left: Chunk<A>
|
|
43
|
-
/** @internal */
|
|
44
|
-
backing: Backing<A>
|
|
45
|
-
/** @internal */
|
|
46
|
-
depth: number
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @category model
|
|
51
|
-
* @since 2.0.0
|
|
52
|
-
*/
|
|
53
|
-
export interface NonEmptyChunk<out A> extends Chunk<A>, NonEmptyIterable<A> {}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @category type lambdas
|
|
57
|
-
* @since 2.0.0
|
|
58
|
-
*/
|
|
59
|
-
export interface ChunkTypeLambda extends TypeLambda {
|
|
60
|
-
readonly type: Chunk<this["Target"]>
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
type Backing<A> =
|
|
64
|
-
| IArray<A>
|
|
65
|
-
| IConcat<A>
|
|
66
|
-
| ISingleton<A>
|
|
67
|
-
| IEmpty
|
|
68
|
-
| ISlice<A>
|
|
69
|
-
|
|
70
|
-
interface IArray<A> {
|
|
71
|
-
readonly _tag: "IArray"
|
|
72
|
-
readonly array: ReadonlyArray<A>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
interface IConcat<A> {
|
|
76
|
-
readonly _tag: "IConcat"
|
|
77
|
-
readonly left: Chunk<A>
|
|
78
|
-
readonly right: Chunk<A>
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
interface ISingleton<A> {
|
|
82
|
-
readonly _tag: "ISingleton"
|
|
83
|
-
readonly a: A
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
interface IEmpty {
|
|
87
|
-
readonly _tag: "IEmpty"
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
interface ISlice<A> {
|
|
91
|
-
readonly _tag: "ISlice"
|
|
92
|
-
readonly chunk: Chunk<A>
|
|
93
|
-
readonly offset: number
|
|
94
|
-
readonly length: number
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function copy<A>(
|
|
98
|
-
src: ReadonlyArray<A>,
|
|
99
|
-
srcPos: number,
|
|
100
|
-
dest: Array<A>,
|
|
101
|
-
destPos: number,
|
|
102
|
-
len: number
|
|
103
|
-
) {
|
|
104
|
-
for (let i = srcPos; i < Math.min(src.length, srcPos + len); i++) {
|
|
105
|
-
dest[destPos + i - srcPos] = src[i]!
|
|
106
|
-
}
|
|
107
|
-
return dest
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const emptyArray: ReadonlyArray<never> = []
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Compares the two chunks of equal length using the specified function
|
|
114
|
-
*
|
|
115
|
-
* @category equivalence
|
|
116
|
-
* @since 2.0.0
|
|
117
|
-
*/
|
|
118
|
-
export const getEquivalence = <A>(isEquivalent: Equivalence.Equivalence<A>): Equivalence.Equivalence<Chunk<A>> =>
|
|
119
|
-
Equivalence.make((self, that) =>
|
|
120
|
-
self.length === that.length && toReadonlyArray(self).every((value, i) => isEquivalent(value, unsafeGet(that, i)))
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
const _equivalence = getEquivalence(Equal.equals)
|
|
124
|
-
|
|
125
|
-
const ChunkProto: Omit<Chunk<unknown>, "backing" | "depth" | "left" | "length" | "right"> = {
|
|
126
|
-
[TypeId]: {
|
|
127
|
-
_A: (_: never) => _
|
|
128
|
-
},
|
|
129
|
-
toString<A>(this: Chunk<A>) {
|
|
130
|
-
return format(this.toJSON())
|
|
131
|
-
},
|
|
132
|
-
toJSON<A>(this: Chunk<A>) {
|
|
133
|
-
return {
|
|
134
|
-
_id: "Chunk",
|
|
135
|
-
values: toReadonlyArray(this).map(toJSON)
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
[NodeInspectSymbol]<A>(this: Chunk<A>) {
|
|
139
|
-
return this.toJSON()
|
|
140
|
-
},
|
|
141
|
-
[Equal.symbol]<A>(this: Chunk<A>, that: unknown): boolean {
|
|
142
|
-
return isChunk(that) && _equivalence(this, that)
|
|
143
|
-
},
|
|
144
|
-
[Hash.symbol]<A>(this: Chunk<A>): number {
|
|
145
|
-
return Hash.cached(this, Hash.array(toReadonlyArray(this)))
|
|
146
|
-
},
|
|
147
|
-
[Symbol.iterator]<A>(this: Chunk<A>): Iterator<A> {
|
|
148
|
-
switch (this.backing._tag) {
|
|
149
|
-
case "IArray": {
|
|
150
|
-
return this.backing.array[Symbol.iterator]()
|
|
151
|
-
}
|
|
152
|
-
case "IEmpty": {
|
|
153
|
-
return emptyArray[Symbol.iterator]()
|
|
154
|
-
}
|
|
155
|
-
default: {
|
|
156
|
-
return toReadonlyArray(this)[Symbol.iterator]()
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
pipe<A>(this: Chunk<A>) {
|
|
161
|
-
return pipeArguments(this, arguments)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const makeChunk = <A>(backing: Backing<A>): Chunk<A> => {
|
|
166
|
-
const chunk = Object.create(ChunkProto)
|
|
167
|
-
chunk.backing = backing
|
|
168
|
-
switch (backing._tag) {
|
|
169
|
-
case "IEmpty": {
|
|
170
|
-
chunk.length = 0
|
|
171
|
-
chunk.depth = 0
|
|
172
|
-
chunk.left = chunk
|
|
173
|
-
chunk.right = chunk
|
|
174
|
-
break
|
|
175
|
-
}
|
|
176
|
-
case "IConcat": {
|
|
177
|
-
chunk.length = backing.left.length + backing.right.length
|
|
178
|
-
chunk.depth = 1 + Math.max(backing.left.depth, backing.right.depth)
|
|
179
|
-
chunk.left = backing.left
|
|
180
|
-
chunk.right = backing.right
|
|
181
|
-
break
|
|
182
|
-
}
|
|
183
|
-
case "IArray": {
|
|
184
|
-
chunk.length = backing.array.length
|
|
185
|
-
chunk.depth = 0
|
|
186
|
-
chunk.left = _empty
|
|
187
|
-
chunk.right = _empty
|
|
188
|
-
break
|
|
189
|
-
}
|
|
190
|
-
case "ISingleton": {
|
|
191
|
-
chunk.length = 1
|
|
192
|
-
chunk.depth = 0
|
|
193
|
-
chunk.left = _empty
|
|
194
|
-
chunk.right = _empty
|
|
195
|
-
break
|
|
196
|
-
}
|
|
197
|
-
case "ISlice": {
|
|
198
|
-
chunk.length = backing.length
|
|
199
|
-
chunk.depth = backing.chunk.depth + 1
|
|
200
|
-
chunk.left = _empty
|
|
201
|
-
chunk.right = _empty
|
|
202
|
-
break
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return chunk
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Checks if `u` is a `Chunk<unknown>`
|
|
210
|
-
*
|
|
211
|
-
* @category constructors
|
|
212
|
-
* @since 2.0.0
|
|
213
|
-
*/
|
|
214
|
-
export const isChunk: {
|
|
215
|
-
<A>(u: Iterable<A>): u is Chunk<A>
|
|
216
|
-
(u: unknown): u is Chunk<unknown>
|
|
217
|
-
} = (u: unknown): u is Chunk<unknown> => hasProperty(u, TypeId)
|
|
218
|
-
|
|
219
|
-
const _empty = makeChunk<never>({ _tag: "IEmpty" })
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* @category constructors
|
|
223
|
-
* @since 2.0.0
|
|
224
|
-
*/
|
|
225
|
-
export const empty: <A = never>() => Chunk<A> = () => _empty
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Builds a `NonEmptyChunk` from an non-empty collection of elements.
|
|
229
|
-
*
|
|
230
|
-
* @category constructors
|
|
231
|
-
* @since 2.0.0
|
|
232
|
-
*/
|
|
233
|
-
export const make = <As extends readonly [any, ...ReadonlyArray<any>]>(...as: As): NonEmptyChunk<As[number]> =>
|
|
234
|
-
unsafeFromNonEmptyArray(as)
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Builds a `NonEmptyChunk` from a single element.
|
|
238
|
-
*
|
|
239
|
-
* @category constructors
|
|
240
|
-
* @since 2.0.0
|
|
241
|
-
*/
|
|
242
|
-
export const of = <A>(a: A): NonEmptyChunk<A> => makeChunk({ _tag: "ISingleton", a }) as any
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Creates a new `Chunk` from an iterable collection of values.
|
|
246
|
-
*
|
|
247
|
-
* @category constructors
|
|
248
|
-
* @since 2.0.0
|
|
249
|
-
*/
|
|
250
|
-
export const fromIterable = <A>(self: Iterable<A>): Chunk<A> =>
|
|
251
|
-
isChunk(self) ? self : unsafeFromArray(RA.fromIterable(self))
|
|
252
|
-
|
|
253
|
-
const copyToArray = <A>(self: Chunk<A>, array: Array<any>, initial: number): void => {
|
|
254
|
-
switch (self.backing._tag) {
|
|
255
|
-
case "IArray": {
|
|
256
|
-
copy(self.backing.array, 0, array, initial, self.length)
|
|
257
|
-
break
|
|
258
|
-
}
|
|
259
|
-
case "IConcat": {
|
|
260
|
-
copyToArray(self.left, array, initial)
|
|
261
|
-
copyToArray(self.right, array, initial + self.left.length)
|
|
262
|
-
break
|
|
263
|
-
}
|
|
264
|
-
case "ISingleton": {
|
|
265
|
-
array[initial] = self.backing.a
|
|
266
|
-
break
|
|
267
|
-
}
|
|
268
|
-
case "ISlice": {
|
|
269
|
-
let i = 0
|
|
270
|
-
let j = initial
|
|
271
|
-
while (i < self.length) {
|
|
272
|
-
array[j] = unsafeGet(self, i)
|
|
273
|
-
i += 1
|
|
274
|
-
j += 1
|
|
275
|
-
}
|
|
276
|
-
break
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const toArray_ = <A>(self: Chunk<A>): Array<A> => toReadonlyArray(self).slice()
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Converts a `Chunk` into an `Array`. If the provided `Chunk` is non-empty
|
|
285
|
-
* (`NonEmptyChunk`), the function will return a `NonEmptyArray`, ensuring the
|
|
286
|
-
* non-empty property is preserved.
|
|
287
|
-
*
|
|
288
|
-
* @category conversions
|
|
289
|
-
* @since 2.0.0
|
|
290
|
-
*/
|
|
291
|
-
export const toArray: <S extends Chunk<any>>(
|
|
292
|
-
self: S
|
|
293
|
-
) => S extends NonEmptyChunk<any> ? RA.NonEmptyArray<Chunk.Infer<S>> : Array<Chunk.Infer<S>> = toArray_ as any
|
|
294
|
-
|
|
295
|
-
const toReadonlyArray_ = <A>(self: Chunk<A>): ReadonlyArray<A> => {
|
|
296
|
-
switch (self.backing._tag) {
|
|
297
|
-
case "IEmpty": {
|
|
298
|
-
return emptyArray
|
|
299
|
-
}
|
|
300
|
-
case "IArray": {
|
|
301
|
-
return self.backing.array
|
|
302
|
-
}
|
|
303
|
-
default: {
|
|
304
|
-
const arr = new Array<A>(self.length)
|
|
305
|
-
copyToArray(self, arr, 0)
|
|
306
|
-
self.backing = {
|
|
307
|
-
_tag: "IArray",
|
|
308
|
-
array: arr
|
|
309
|
-
}
|
|
310
|
-
self.left = _empty
|
|
311
|
-
self.right = _empty
|
|
312
|
-
self.depth = 0
|
|
313
|
-
return arr
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Converts a `Chunk` into a `ReadonlyArray`. If the provided `Chunk` is
|
|
320
|
-
* non-empty (`NonEmptyChunk`), the function will return a
|
|
321
|
-
* `NonEmptyReadonlyArray`, ensuring the non-empty property is preserved.
|
|
322
|
-
*
|
|
323
|
-
* @category conversions
|
|
324
|
-
* @since 2.0.0
|
|
325
|
-
*/
|
|
326
|
-
export const toReadonlyArray: <S extends Chunk<any>>(
|
|
327
|
-
self: S
|
|
328
|
-
) => S extends NonEmptyChunk<any> ? RA.NonEmptyReadonlyArray<Chunk.Infer<S>> : ReadonlyArray<Chunk.Infer<S>> =
|
|
329
|
-
toReadonlyArray_ as any
|
|
330
|
-
|
|
331
|
-
const reverseChunk = <A>(self: Chunk<A>): Chunk<A> => {
|
|
332
|
-
switch (self.backing._tag) {
|
|
333
|
-
case "IEmpty":
|
|
334
|
-
case "ISingleton":
|
|
335
|
-
return self
|
|
336
|
-
case "IArray": {
|
|
337
|
-
return makeChunk({ _tag: "IArray", array: RA.reverse(self.backing.array) })
|
|
338
|
-
}
|
|
339
|
-
case "IConcat": {
|
|
340
|
-
return makeChunk({ _tag: "IConcat", left: reverse(self.backing.right), right: reverse(self.backing.left) })
|
|
341
|
-
}
|
|
342
|
-
case "ISlice":
|
|
343
|
-
return unsafeFromArray(RA.reverse(toReadonlyArray(self)))
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Reverses the order of elements in a `Chunk`.
|
|
349
|
-
* Importantly, if the input chunk is a `NonEmptyChunk`, the reversed chunk will also be a `NonEmptyChunk`.
|
|
350
|
-
*
|
|
351
|
-
* **Example**
|
|
352
|
-
*
|
|
353
|
-
* ```ts
|
|
354
|
-
* import { Chunk } from "effect"
|
|
355
|
-
*
|
|
356
|
-
* const chunk = Chunk.make(1, 2, 3)
|
|
357
|
-
* const result = Chunk.reverse(chunk)
|
|
358
|
-
*
|
|
359
|
-
* console.log(result)
|
|
360
|
-
* // { _id: 'Chunk', values: [ 3, 2, 1 ] }
|
|
361
|
-
* ```
|
|
362
|
-
*
|
|
363
|
-
* @since 2.0.0
|
|
364
|
-
* @category elements
|
|
365
|
-
*/
|
|
366
|
-
export const reverse: <S extends Chunk<any>>(self: S) => Chunk.With<S, Chunk.Infer<S>> = reverseChunk as any
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* This function provides a safe way to read a value at a particular index from a `Chunk`.
|
|
370
|
-
*
|
|
371
|
-
* @category elements
|
|
372
|
-
* @since 2.0.0
|
|
373
|
-
*/
|
|
374
|
-
export const get: {
|
|
375
|
-
(index: number): <A>(self: Chunk<A>) => Option<A>
|
|
376
|
-
<A>(self: Chunk<A>, index: number): Option<A>
|
|
377
|
-
} = dual(
|
|
378
|
-
2,
|
|
379
|
-
<A>(self: Chunk<A>, index: number): Option<A> =>
|
|
380
|
-
index < 0 || index >= self.length ? O.none() : O.some(unsafeGet(self, index))
|
|
381
|
-
)
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* Wraps an array into a chunk without copying, unsafe on mutable arrays
|
|
385
|
-
*
|
|
386
|
-
* @since 2.0.0
|
|
387
|
-
* @category unsafe
|
|
388
|
-
*/
|
|
389
|
-
export const unsafeFromArray = <A>(self: ReadonlyArray<A>): Chunk<A> =>
|
|
390
|
-
self.length === 0 ? empty() : self.length === 1 ? of(self[0]) : makeChunk({ _tag: "IArray", array: self })
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Wraps an array into a chunk without copying, unsafe on mutable arrays
|
|
394
|
-
*
|
|
395
|
-
* @since 2.0.0
|
|
396
|
-
* @category unsafe
|
|
397
|
-
*/
|
|
398
|
-
export const unsafeFromNonEmptyArray = <A>(self: NonEmptyReadonlyArray<A>): NonEmptyChunk<A> =>
|
|
399
|
-
unsafeFromArray(self) as any
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Gets an element unsafely, will throw on out of bounds
|
|
403
|
-
*
|
|
404
|
-
* @since 2.0.0
|
|
405
|
-
* @category unsafe
|
|
406
|
-
*/
|
|
407
|
-
export const unsafeGet: {
|
|
408
|
-
(index: number): <A>(self: Chunk<A>) => A
|
|
409
|
-
<A>(self: Chunk<A>, index: number): A
|
|
410
|
-
} = dual(2, <A>(self: Chunk<A>, index: number): A => {
|
|
411
|
-
switch (self.backing._tag) {
|
|
412
|
-
case "IEmpty": {
|
|
413
|
-
throw new Error(`Index out of bounds`)
|
|
414
|
-
}
|
|
415
|
-
case "ISingleton": {
|
|
416
|
-
if (index !== 0) {
|
|
417
|
-
throw new Error(`Index out of bounds`)
|
|
418
|
-
}
|
|
419
|
-
return self.backing.a
|
|
420
|
-
}
|
|
421
|
-
case "IArray": {
|
|
422
|
-
if (index >= self.length || index < 0) {
|
|
423
|
-
throw new Error(`Index out of bounds`)
|
|
424
|
-
}
|
|
425
|
-
return self.backing.array[index]!
|
|
426
|
-
}
|
|
427
|
-
case "IConcat": {
|
|
428
|
-
return index < self.left.length
|
|
429
|
-
? unsafeGet(self.left, index)
|
|
430
|
-
: unsafeGet(self.right, index - self.left.length)
|
|
431
|
-
}
|
|
432
|
-
case "ISlice": {
|
|
433
|
-
return unsafeGet(self.backing.chunk, index + self.backing.offset)
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Appends the specified element to the end of the `Chunk`.
|
|
440
|
-
*
|
|
441
|
-
* @category concatenating
|
|
442
|
-
* @since 2.0.0
|
|
443
|
-
*/
|
|
444
|
-
export const append: {
|
|
445
|
-
<A2>(a: A2): <A>(self: Chunk<A>) => NonEmptyChunk<A2 | A>
|
|
446
|
-
<A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2>
|
|
447
|
-
} = dual(2, <A, A2>(self: Chunk<A>, a: A2): NonEmptyChunk<A | A2> => appendAll(self, of(a)))
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Prepend an element to the front of a `Chunk`, creating a new `NonEmptyChunk`.
|
|
451
|
-
*
|
|
452
|
-
* @category concatenating
|
|
453
|
-
* @since 2.0.0
|
|
454
|
-
*/
|
|
455
|
-
export const prepend: {
|
|
456
|
-
<B>(elem: B): <A>(self: Chunk<A>) => NonEmptyChunk<B | A>
|
|
457
|
-
<A, B>(self: Chunk<A>, elem: B): NonEmptyChunk<A | B>
|
|
458
|
-
} = dual(2, <A, B>(self: Chunk<A>, elem: B): NonEmptyChunk<A | B> => appendAll(of(elem), self))
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Takes the first up to `n` elements from the chunk
|
|
462
|
-
*
|
|
463
|
-
* @since 2.0.0
|
|
464
|
-
*/
|
|
465
|
-
export const take: {
|
|
466
|
-
(n: number): <A>(self: Chunk<A>) => Chunk<A>
|
|
467
|
-
<A>(self: Chunk<A>, n: number): Chunk<A>
|
|
468
|
-
} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => {
|
|
469
|
-
if (n <= 0) {
|
|
470
|
-
return _empty
|
|
471
|
-
} else if (n >= self.length) {
|
|
472
|
-
return self
|
|
473
|
-
} else {
|
|
474
|
-
switch (self.backing._tag) {
|
|
475
|
-
case "ISlice": {
|
|
476
|
-
return makeChunk({
|
|
477
|
-
_tag: "ISlice",
|
|
478
|
-
chunk: self.backing.chunk,
|
|
479
|
-
length: n,
|
|
480
|
-
offset: self.backing.offset
|
|
481
|
-
})
|
|
482
|
-
}
|
|
483
|
-
case "IConcat": {
|
|
484
|
-
if (n > self.left.length) {
|
|
485
|
-
return makeChunk({
|
|
486
|
-
_tag: "IConcat",
|
|
487
|
-
left: self.left,
|
|
488
|
-
right: take(self.right, n - self.left.length)
|
|
489
|
-
})
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return take(self.left, n)
|
|
493
|
-
}
|
|
494
|
-
default: {
|
|
495
|
-
return makeChunk({
|
|
496
|
-
_tag: "ISlice",
|
|
497
|
-
chunk: self,
|
|
498
|
-
offset: 0,
|
|
499
|
-
length: n
|
|
500
|
-
})
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
})
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Drops the first up to `n` elements from the chunk
|
|
508
|
-
*
|
|
509
|
-
* @since 2.0.0
|
|
510
|
-
*/
|
|
511
|
-
export const drop: {
|
|
512
|
-
(n: number): <A>(self: Chunk<A>) => Chunk<A>
|
|
513
|
-
<A>(self: Chunk<A>, n: number): Chunk<A>
|
|
514
|
-
} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => {
|
|
515
|
-
if (n <= 0) {
|
|
516
|
-
return self
|
|
517
|
-
} else if (n >= self.length) {
|
|
518
|
-
return _empty
|
|
519
|
-
} else {
|
|
520
|
-
switch (self.backing._tag) {
|
|
521
|
-
case "ISlice": {
|
|
522
|
-
return makeChunk({
|
|
523
|
-
_tag: "ISlice",
|
|
524
|
-
chunk: self.backing.chunk,
|
|
525
|
-
offset: self.backing.offset + n,
|
|
526
|
-
length: self.backing.length - n
|
|
527
|
-
})
|
|
528
|
-
}
|
|
529
|
-
case "IConcat": {
|
|
530
|
-
if (n > self.left.length) {
|
|
531
|
-
return drop(self.right, n - self.left.length)
|
|
532
|
-
}
|
|
533
|
-
return makeChunk({
|
|
534
|
-
_tag: "IConcat",
|
|
535
|
-
left: drop(self.left, n),
|
|
536
|
-
right: self.right
|
|
537
|
-
})
|
|
538
|
-
}
|
|
539
|
-
default: {
|
|
540
|
-
return makeChunk({
|
|
541
|
-
_tag: "ISlice",
|
|
542
|
-
chunk: self,
|
|
543
|
-
offset: n,
|
|
544
|
-
length: self.length - n
|
|
545
|
-
})
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
})
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* Drops the last `n` elements.
|
|
553
|
-
*
|
|
554
|
-
* @since 2.0.0
|
|
555
|
-
*/
|
|
556
|
-
export const dropRight: {
|
|
557
|
-
(n: number): <A>(self: Chunk<A>) => Chunk<A>
|
|
558
|
-
<A>(self: Chunk<A>, n: number): Chunk<A>
|
|
559
|
-
} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => take(self, Math.max(0, self.length - n)))
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* Drops all elements so long as the predicate returns true.
|
|
563
|
-
*
|
|
564
|
-
* @since 2.0.0
|
|
565
|
-
*/
|
|
566
|
-
export const dropWhile: {
|
|
567
|
-
<A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>
|
|
568
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>
|
|
569
|
-
} = dual(2, <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A> => {
|
|
570
|
-
const arr = toReadonlyArray(self)
|
|
571
|
-
const len = arr.length
|
|
572
|
-
let i = 0
|
|
573
|
-
while (i < len && predicate(arr[i]!)) {
|
|
574
|
-
i++
|
|
575
|
-
}
|
|
576
|
-
return drop(self, i)
|
|
577
|
-
})
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Prepends the specified prefix chunk to the beginning of the specified chunk.
|
|
581
|
-
* If either chunk is non-empty, the result is also a non-empty chunk.
|
|
582
|
-
*
|
|
583
|
-
* **Example**
|
|
584
|
-
*
|
|
585
|
-
* ```ts
|
|
586
|
-
* import { Chunk } from "effect"
|
|
587
|
-
*
|
|
588
|
-
* const result = Chunk.make(1, 2).pipe(Chunk.prependAll(Chunk.make("a", "b")), Chunk.toArray)
|
|
589
|
-
*
|
|
590
|
-
* console.log(result)
|
|
591
|
-
* // [ "a", "b", 1, 2 ]
|
|
592
|
-
* ```
|
|
593
|
-
*
|
|
594
|
-
* @category concatenating
|
|
595
|
-
* @since 2.0.0
|
|
596
|
-
*/
|
|
597
|
-
export const prependAll: {
|
|
598
|
-
<S extends Chunk<any>, T extends Chunk<any>>(
|
|
599
|
-
that: T
|
|
600
|
-
): (self: S) => Chunk.OrNonEmpty<S, T, Chunk.Infer<S> | Chunk.Infer<T>>
|
|
601
|
-
<A, B>(self: Chunk<A>, that: NonEmptyChunk<B>): NonEmptyChunk<A | B>
|
|
602
|
-
<A, B>(self: NonEmptyChunk<A>, that: Chunk<B>): NonEmptyChunk<A | B>
|
|
603
|
-
<A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>
|
|
604
|
-
} = dual(2, <A, B>(self: NonEmptyChunk<A>, that: Chunk<B>): Chunk<A | B> => appendAll(that, self))
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* Concatenates two chunks, combining their elements.
|
|
608
|
-
* If either chunk is non-empty, the result is also a non-empty chunk.
|
|
609
|
-
*
|
|
610
|
-
* **Example**
|
|
611
|
-
*
|
|
612
|
-
* ```ts
|
|
613
|
-
* import { Chunk } from "effect"
|
|
614
|
-
*
|
|
615
|
-
* const result = Chunk.make(1, 2).pipe(Chunk.appendAll(Chunk.make("a", "b")), Chunk.toArray)
|
|
616
|
-
*
|
|
617
|
-
* console.log(result)
|
|
618
|
-
* // [ 1, 2, "a", "b" ]
|
|
619
|
-
* ```
|
|
620
|
-
*
|
|
621
|
-
* @category concatenating
|
|
622
|
-
* @since 2.0.0
|
|
623
|
-
*/
|
|
624
|
-
export const appendAll: {
|
|
625
|
-
<S extends Chunk<any>, T extends Chunk<any>>(
|
|
626
|
-
that: T
|
|
627
|
-
): (self: S) => Chunk.OrNonEmpty<S, T, Chunk.Infer<S> | Chunk.Infer<T>>
|
|
628
|
-
<A, B>(self: Chunk<A>, that: NonEmptyChunk<B>): NonEmptyChunk<A | B>
|
|
629
|
-
<A, B>(self: NonEmptyChunk<A>, that: Chunk<B>): NonEmptyChunk<A | B>
|
|
630
|
-
<A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>
|
|
631
|
-
} = dual(2, <A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B> => {
|
|
632
|
-
if (self.backing._tag === "IEmpty") {
|
|
633
|
-
return that
|
|
634
|
-
}
|
|
635
|
-
if (that.backing._tag === "IEmpty") {
|
|
636
|
-
return self
|
|
637
|
-
}
|
|
638
|
-
const diff = that.depth - self.depth
|
|
639
|
-
if (Math.abs(diff) <= 1) {
|
|
640
|
-
return makeChunk<A | B>({ _tag: "IConcat", left: self, right: that })
|
|
641
|
-
} else if (diff < -1) {
|
|
642
|
-
if (self.left.depth >= self.right.depth) {
|
|
643
|
-
const nr = appendAll(self.right, that)
|
|
644
|
-
return makeChunk({ _tag: "IConcat", left: self.left, right: nr })
|
|
645
|
-
} else {
|
|
646
|
-
const nrr = appendAll(self.right.right, that)
|
|
647
|
-
if (nrr.depth === self.depth - 3) {
|
|
648
|
-
const nr = makeChunk({ _tag: "IConcat", left: self.right.left, right: nrr })
|
|
649
|
-
return makeChunk({ _tag: "IConcat", left: self.left, right: nr })
|
|
650
|
-
} else {
|
|
651
|
-
const nl = makeChunk({ _tag: "IConcat", left: self.left, right: self.right.left })
|
|
652
|
-
return makeChunk({ _tag: "IConcat", left: nl, right: nrr })
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
} else {
|
|
656
|
-
if (that.right.depth >= that.left.depth) {
|
|
657
|
-
const nl = appendAll(self, that.left)
|
|
658
|
-
return makeChunk({ _tag: "IConcat", left: nl, right: that.right })
|
|
659
|
-
} else {
|
|
660
|
-
const nll = appendAll(self, that.left.left)
|
|
661
|
-
if (nll.depth === that.depth - 3) {
|
|
662
|
-
const nl = makeChunk({ _tag: "IConcat", left: nll, right: that.left.right })
|
|
663
|
-
return makeChunk({ _tag: "IConcat", left: nl, right: that.right })
|
|
664
|
-
} else {
|
|
665
|
-
const nr = makeChunk({ _tag: "IConcat", left: that.left.right, right: that.right })
|
|
666
|
-
return makeChunk({ _tag: "IConcat", left: nll, right: nr })
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
})
|
|
671
|
-
|
|
672
|
-
/**
|
|
673
|
-
* Returns a filtered and mapped subset of the elements.
|
|
674
|
-
*
|
|
675
|
-
* @since 2.0.0
|
|
676
|
-
* @category filtering
|
|
677
|
-
*/
|
|
678
|
-
export const filterMap: {
|
|
679
|
-
<A, B>(f: (a: A, i: number) => Option<B>): (self: Chunk<A>) => Chunk<B>
|
|
680
|
-
<A, B>(self: Chunk<A>, f: (a: A, i: number) => Option<B>): Chunk<B>
|
|
681
|
-
} = dual(
|
|
682
|
-
2,
|
|
683
|
-
<A, B>(self: Chunk<A>, f: (a: A, i: number) => Option<B>): Chunk<B> => unsafeFromArray(RA.filterMap(self, f))
|
|
684
|
-
)
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* Returns a filtered and mapped subset of the elements.
|
|
688
|
-
*
|
|
689
|
-
* @since 2.0.0
|
|
690
|
-
* @category filtering
|
|
691
|
-
*/
|
|
692
|
-
export const filter: {
|
|
693
|
-
<A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Chunk<B>
|
|
694
|
-
<A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>
|
|
695
|
-
<A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Chunk<B>
|
|
696
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>
|
|
697
|
-
} = dual(
|
|
698
|
-
2,
|
|
699
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A> => unsafeFromArray(RA.filter(self, predicate))
|
|
700
|
-
)
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Transforms all elements of the chunk for as long as the specified function returns some value
|
|
704
|
-
*
|
|
705
|
-
* @since 2.0.0
|
|
706
|
-
* @category filtering
|
|
707
|
-
*/
|
|
708
|
-
export const filterMapWhile: {
|
|
709
|
-
<A, B>(f: (a: A) => Option<B>): (self: Chunk<A>) => Chunk<B>
|
|
710
|
-
<A, B>(self: Chunk<A>, f: (a: A) => Option<B>): Chunk<B>
|
|
711
|
-
} = dual(2, <A, B>(self: Chunk<A>, f: (a: A) => Option<B>) => unsafeFromArray(RA.filterMapWhile(self, f)))
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Filter out optional values
|
|
715
|
-
*
|
|
716
|
-
* @since 2.0.0
|
|
717
|
-
* @category filtering
|
|
718
|
-
*/
|
|
719
|
-
export const compact = <A>(self: Chunk<Option<A>>): Chunk<A> => filterMap(self, identity)
|
|
720
|
-
|
|
721
|
-
/**
|
|
722
|
-
* Applies a function to each element in a chunk and returns a new chunk containing the concatenated mapped elements.
|
|
723
|
-
*
|
|
724
|
-
* @since 2.0.0
|
|
725
|
-
* @category sequencing
|
|
726
|
-
*/
|
|
727
|
-
export const flatMap: {
|
|
728
|
-
<S extends Chunk<any>, T extends Chunk<any>>(
|
|
729
|
-
f: (a: Chunk.Infer<S>, i: number) => T
|
|
730
|
-
): (self: S) => Chunk.AndNonEmpty<S, T, Chunk.Infer<T>>
|
|
731
|
-
<A, B>(self: NonEmptyChunk<A>, f: (a: A, i: number) => NonEmptyChunk<B>): NonEmptyChunk<B>
|
|
732
|
-
<A, B>(self: Chunk<A>, f: (a: A, i: number) => Chunk<B>): Chunk<B>
|
|
733
|
-
} = dual(2, <A, B>(self: Chunk<A>, f: (a: A, i: number) => Chunk<B>) => {
|
|
734
|
-
if (self.backing._tag === "ISingleton") {
|
|
735
|
-
return f(self.backing.a, 0)
|
|
736
|
-
}
|
|
737
|
-
let out: Chunk<B> = _empty
|
|
738
|
-
let i = 0
|
|
739
|
-
for (const k of self) {
|
|
740
|
-
out = appendAll(out, f(k, i++))
|
|
741
|
-
}
|
|
742
|
-
return out
|
|
743
|
-
})
|
|
744
|
-
|
|
745
|
-
/**
|
|
746
|
-
* Iterates over each element of a `Chunk` and applies a function to it.
|
|
747
|
-
*
|
|
748
|
-
* **Details**
|
|
749
|
-
*
|
|
750
|
-
* This function processes every element of the given `Chunk`, calling the
|
|
751
|
-
* provided function `f` on each element. It does not return a new value;
|
|
752
|
-
* instead, it is primarily used for side effects, such as logging or
|
|
753
|
-
* accumulating data in an external variable.
|
|
754
|
-
*
|
|
755
|
-
* @since 2.0.0
|
|
756
|
-
* @category combinators
|
|
757
|
-
*/
|
|
758
|
-
export const forEach: {
|
|
759
|
-
<A, B>(f: (a: A, index: number) => B): (self: Chunk<A>) => void
|
|
760
|
-
<A, B>(self: Chunk<A>, f: (a: A, index: number) => B): void
|
|
761
|
-
} = dual(2, <A, B>(self: Chunk<A>, f: (a: A) => B): void => toReadonlyArray(self).forEach(f))
|
|
762
|
-
|
|
763
|
-
/**
|
|
764
|
-
* Flattens a chunk of chunks into a single chunk by concatenating all chunks.
|
|
765
|
-
*
|
|
766
|
-
* @since 2.0.0
|
|
767
|
-
* @category sequencing
|
|
768
|
-
*/
|
|
769
|
-
export const flatten: <S extends Chunk<Chunk<any>>>(self: S) => Chunk.Flatten<S> = flatMap(identity) as any
|
|
770
|
-
|
|
771
|
-
/**
|
|
772
|
-
* Groups elements in chunks of up to `n` elements.
|
|
773
|
-
*
|
|
774
|
-
* @since 2.0.0
|
|
775
|
-
* @category elements
|
|
776
|
-
*/
|
|
777
|
-
export const chunksOf: {
|
|
778
|
-
(n: number): <A>(self: Chunk<A>) => Chunk<Chunk<A>>
|
|
779
|
-
<A>(self: Chunk<A>, n: number): Chunk<Chunk<A>>
|
|
780
|
-
} = dual(2, <A>(self: Chunk<A>, n: number) => {
|
|
781
|
-
const gr: Array<Chunk<A>> = []
|
|
782
|
-
let current: Array<A> = []
|
|
783
|
-
toReadonlyArray(self).forEach((a) => {
|
|
784
|
-
current.push(a)
|
|
785
|
-
if (current.length >= n) {
|
|
786
|
-
gr.push(unsafeFromArray(current))
|
|
787
|
-
current = []
|
|
788
|
-
}
|
|
789
|
-
})
|
|
790
|
-
if (current.length > 0) {
|
|
791
|
-
gr.push(unsafeFromArray(current))
|
|
792
|
-
}
|
|
793
|
-
return unsafeFromArray(gr)
|
|
794
|
-
})
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Creates a Chunk of unique values that are included in all given Chunks.
|
|
798
|
-
*
|
|
799
|
-
* The order and references of result values are determined by the Chunk.
|
|
800
|
-
*
|
|
801
|
-
* @since 2.0.0
|
|
802
|
-
* @category elements
|
|
803
|
-
*/
|
|
804
|
-
export const intersection: {
|
|
805
|
-
<A>(that: Chunk<A>): <B>(self: Chunk<B>) => Chunk<A & B>
|
|
806
|
-
<A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A & B>
|
|
807
|
-
} = dual(
|
|
808
|
-
2,
|
|
809
|
-
<A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A & B> =>
|
|
810
|
-
unsafeFromArray(RA.intersection(toReadonlyArray(self), toReadonlyArray(that)))
|
|
811
|
-
)
|
|
812
|
-
|
|
813
|
-
/**
|
|
814
|
-
* Determines if the chunk is empty.
|
|
815
|
-
*
|
|
816
|
-
* @since 2.0.0
|
|
817
|
-
* @category elements
|
|
818
|
-
*/
|
|
819
|
-
export const isEmpty = <A>(self: Chunk<A>): boolean => self.length === 0
|
|
820
|
-
|
|
821
|
-
/**
|
|
822
|
-
* Determines if the chunk is not empty.
|
|
823
|
-
*
|
|
824
|
-
* @since 2.0.0
|
|
825
|
-
* @category elements
|
|
826
|
-
*/
|
|
827
|
-
export const isNonEmpty = <A>(self: Chunk<A>): self is NonEmptyChunk<A> => self.length > 0
|
|
828
|
-
|
|
829
|
-
/**
|
|
830
|
-
* Returns the first element of this chunk if it exists.
|
|
831
|
-
*
|
|
832
|
-
* @since 2.0.0
|
|
833
|
-
* @category elements
|
|
834
|
-
*/
|
|
835
|
-
export const head: <A>(self: Chunk<A>) => Option<A> = get(0)
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* Returns the first element of this chunk.
|
|
839
|
-
*
|
|
840
|
-
* It will throw an error if the chunk is empty.
|
|
841
|
-
*
|
|
842
|
-
* @since 2.0.0
|
|
843
|
-
* @category unsafe
|
|
844
|
-
*/
|
|
845
|
-
export const unsafeHead = <A>(self: Chunk<A>): A => unsafeGet(self, 0)
|
|
846
|
-
|
|
847
|
-
/**
|
|
848
|
-
* Returns the first element of this non empty chunk.
|
|
849
|
-
*
|
|
850
|
-
* @since 2.0.0
|
|
851
|
-
* @category elements
|
|
852
|
-
*/
|
|
853
|
-
export const headNonEmpty: <A>(self: NonEmptyChunk<A>) => A = unsafeHead
|
|
854
|
-
|
|
855
|
-
/**
|
|
856
|
-
* Returns the last element of this chunk if it exists.
|
|
857
|
-
*
|
|
858
|
-
* @since 2.0.0
|
|
859
|
-
* @category elements
|
|
860
|
-
*/
|
|
861
|
-
export const last = <A>(self: Chunk<A>): Option<A> => get(self, self.length - 1)
|
|
862
|
-
|
|
863
|
-
/**
|
|
864
|
-
* Returns the last element of this chunk.
|
|
865
|
-
*
|
|
866
|
-
* It will throw an error if the chunk is empty.
|
|
867
|
-
*
|
|
868
|
-
* @since 2.0.0
|
|
869
|
-
* @category unsafe
|
|
870
|
-
*/
|
|
871
|
-
export const unsafeLast = <A>(self: Chunk<A>): A => unsafeGet(self, self.length - 1)
|
|
872
|
-
|
|
873
|
-
/**
|
|
874
|
-
* Returns the last element of this non empty chunk.
|
|
875
|
-
*
|
|
876
|
-
* @since 3.4.0
|
|
877
|
-
* @category elements
|
|
878
|
-
*/
|
|
879
|
-
export const lastNonEmpty: <A>(self: NonEmptyChunk<A>) => A = unsafeLast
|
|
880
|
-
|
|
881
|
-
/**
|
|
882
|
-
* @since 2.0.0
|
|
883
|
-
*/
|
|
884
|
-
export declare namespace Chunk {
|
|
885
|
-
/**
|
|
886
|
-
* @since 2.0.0
|
|
887
|
-
*/
|
|
888
|
-
export type Infer<S extends Chunk<any>> = S extends Chunk<infer A> ? A : never
|
|
889
|
-
|
|
890
|
-
/**
|
|
891
|
-
* @since 2.0.0
|
|
892
|
-
*/
|
|
893
|
-
export type With<S extends Chunk<any>, A> = S extends NonEmptyChunk<any> ? NonEmptyChunk<A> : Chunk<A>
|
|
894
|
-
|
|
895
|
-
/**
|
|
896
|
-
* @since 2.0.0
|
|
897
|
-
*/
|
|
898
|
-
export type OrNonEmpty<S extends Chunk<any>, T extends Chunk<any>, A> = S extends NonEmptyChunk<any> ?
|
|
899
|
-
NonEmptyChunk<A>
|
|
900
|
-
: T extends NonEmptyChunk<any> ? NonEmptyChunk<A>
|
|
901
|
-
: Chunk<A>
|
|
902
|
-
|
|
903
|
-
/**
|
|
904
|
-
* @since 2.0.0
|
|
905
|
-
*/
|
|
906
|
-
export type AndNonEmpty<S extends Chunk<any>, T extends Chunk<any>, A> = S extends NonEmptyChunk<any> ?
|
|
907
|
-
T extends NonEmptyChunk<any> ? NonEmptyChunk<A>
|
|
908
|
-
: Chunk<A> :
|
|
909
|
-
Chunk<A>
|
|
910
|
-
|
|
911
|
-
/**
|
|
912
|
-
* @since 2.0.0
|
|
913
|
-
*/
|
|
914
|
-
export type Flatten<T extends Chunk<Chunk<any>>> = T extends NonEmptyChunk<NonEmptyChunk<infer A>> ? NonEmptyChunk<A>
|
|
915
|
-
: T extends Chunk<Chunk<infer A>> ? Chunk<A>
|
|
916
|
-
: never
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
/**
|
|
920
|
-
* Transforms the elements of a chunk using the specified mapping function.
|
|
921
|
-
* If the input chunk is non-empty, the resulting chunk will also be non-empty.
|
|
922
|
-
*
|
|
923
|
-
* **Example**
|
|
924
|
-
*
|
|
925
|
-
* ```ts
|
|
926
|
-
* import { Chunk } from "effect"
|
|
927
|
-
*
|
|
928
|
-
* const result = Chunk.map(Chunk.make(1, 2), (n) => n + 1)
|
|
929
|
-
*
|
|
930
|
-
* console.log(result)
|
|
931
|
-
* // { _id: 'Chunk', values: [ 2, 3 ] }
|
|
932
|
-
* ```
|
|
933
|
-
*
|
|
934
|
-
* @since 2.0.0
|
|
935
|
-
* @category mapping
|
|
936
|
-
*/
|
|
937
|
-
export const map: {
|
|
938
|
-
<S extends Chunk<any>, B>(f: (a: Chunk.Infer<S>, i: number) => B): (self: S) => Chunk.With<S, B>
|
|
939
|
-
<A, B>(self: NonEmptyChunk<A>, f: (a: A, i: number) => B): NonEmptyChunk<B>
|
|
940
|
-
<A, B>(self: Chunk<A>, f: (a: A, i: number) => B): Chunk<B>
|
|
941
|
-
} = dual(2, <A, B>(self: Chunk<A>, f: (a: A, i: number) => B): Chunk<B> =>
|
|
942
|
-
self.backing._tag === "ISingleton" ?
|
|
943
|
-
of(f(self.backing.a, 0)) :
|
|
944
|
-
unsafeFromArray(pipe(toReadonlyArray(self), RA.map((a, i) => f(a, i)))))
|
|
945
|
-
|
|
946
|
-
/**
|
|
947
|
-
* Statefully maps over the chunk, producing new elements of type `B`.
|
|
948
|
-
*
|
|
949
|
-
* @since 2.0.0
|
|
950
|
-
* @category folding
|
|
951
|
-
*/
|
|
952
|
-
export const mapAccum: {
|
|
953
|
-
<S, A, B>(s: S, f: (s: S, a: A) => readonly [S, B]): (self: Chunk<A>) => [S, Chunk<B>]
|
|
954
|
-
<S, A, B>(self: Chunk<A>, s: S, f: (s: S, a: A) => readonly [S, B]): [S, Chunk<B>]
|
|
955
|
-
} = dual(3, <S, A, B>(self: Chunk<A>, s: S, f: (s: S, a: A) => readonly [S, B]): [S, Chunk<B>] => {
|
|
956
|
-
const [s1, as] = RA.mapAccum(self, s, f)
|
|
957
|
-
return [s1, unsafeFromArray(as)]
|
|
958
|
-
})
|
|
959
|
-
|
|
960
|
-
/**
|
|
961
|
-
* Separate elements based on a predicate that also exposes the index of the element.
|
|
962
|
-
*
|
|
963
|
-
* @category filtering
|
|
964
|
-
* @since 2.0.0
|
|
965
|
-
*/
|
|
966
|
-
export const partition: {
|
|
967
|
-
<A, B extends A>(
|
|
968
|
-
refinement: (a: NoInfer<A>, i: number) => a is B
|
|
969
|
-
): (self: Chunk<A>) => [excluded: Chunk<Exclude<A, B>>, satisfying: Chunk<B>]
|
|
970
|
-
<A>(
|
|
971
|
-
predicate: (a: NoInfer<A>, i: number) => boolean
|
|
972
|
-
): (self: Chunk<A>) => [excluded: Chunk<A>, satisfying: Chunk<A>]
|
|
973
|
-
<A, B extends A>(
|
|
974
|
-
self: Chunk<A>,
|
|
975
|
-
refinement: (a: A, i: number) => a is B
|
|
976
|
-
): [excluded: Chunk<Exclude<A, B>>, satisfying: Chunk<B>]
|
|
977
|
-
<A>(self: Chunk<A>, predicate: (a: A, i: number) => boolean): [excluded: Chunk<A>, satisfying: Chunk<A>]
|
|
978
|
-
} = dual(
|
|
979
|
-
2,
|
|
980
|
-
<A>(self: Chunk<A>, predicate: (a: A, i: number) => boolean): [excluded: Chunk<A>, satisfying: Chunk<A>] =>
|
|
981
|
-
pipe(
|
|
982
|
-
RA.partition(toReadonlyArray(self), predicate),
|
|
983
|
-
([l, r]) => [unsafeFromArray(l), unsafeFromArray(r)]
|
|
984
|
-
)
|
|
985
|
-
)
|
|
986
|
-
|
|
987
|
-
/**
|
|
988
|
-
* Partitions the elements of this chunk into two chunks using f.
|
|
989
|
-
*
|
|
990
|
-
* @category filtering
|
|
991
|
-
* @since 2.0.0
|
|
992
|
-
*/
|
|
993
|
-
export const partitionMap: {
|
|
994
|
-
<A, B, C>(f: (a: A) => Either<C, B>): (self: Chunk<A>) => [left: Chunk<B>, right: Chunk<C>]
|
|
995
|
-
<A, B, C>(self: Chunk<A>, f: (a: A) => Either<C, B>): [left: Chunk<B>, right: Chunk<C>]
|
|
996
|
-
} = dual(2, <A, B, C>(self: Chunk<A>, f: (a: A) => Either<C, B>): [left: Chunk<B>, right: Chunk<C>] =>
|
|
997
|
-
pipe(
|
|
998
|
-
RA.partitionMap(toReadonlyArray(self), f),
|
|
999
|
-
([l, r]) => [unsafeFromArray(l), unsafeFromArray(r)]
|
|
1000
|
-
))
|
|
1001
|
-
|
|
1002
|
-
/**
|
|
1003
|
-
* Partitions the elements of this chunk into two chunks.
|
|
1004
|
-
*
|
|
1005
|
-
* @category filtering
|
|
1006
|
-
* @since 2.0.0
|
|
1007
|
-
*/
|
|
1008
|
-
export const separate = <A, B>(self: Chunk<Either<B, A>>): [Chunk<A>, Chunk<B>] =>
|
|
1009
|
-
pipe(
|
|
1010
|
-
RA.separate(toReadonlyArray(self)),
|
|
1011
|
-
([l, r]) => [unsafeFromArray(l), unsafeFromArray(r)]
|
|
1012
|
-
)
|
|
1013
|
-
|
|
1014
|
-
/**
|
|
1015
|
-
* Retireves the size of the chunk
|
|
1016
|
-
*
|
|
1017
|
-
* @since 2.0.0
|
|
1018
|
-
* @category elements
|
|
1019
|
-
*/
|
|
1020
|
-
export const size = <A>(self: Chunk<A>): number => self.length
|
|
1021
|
-
|
|
1022
|
-
/**
|
|
1023
|
-
* Sort the elements of a Chunk in increasing order, creating a new Chunk.
|
|
1024
|
-
*
|
|
1025
|
-
* @since 2.0.0
|
|
1026
|
-
* @category sorting
|
|
1027
|
-
*/
|
|
1028
|
-
export const sort: {
|
|
1029
|
-
<B>(O: Order.Order<B>): <A extends B>(self: Chunk<A>) => Chunk<A>
|
|
1030
|
-
<A extends B, B>(self: Chunk<A>, O: Order.Order<B>): Chunk<A>
|
|
1031
|
-
} = dual(
|
|
1032
|
-
2,
|
|
1033
|
-
<A extends B, B>(self: Chunk<A>, O: Order.Order<B>): Chunk<A> => unsafeFromArray(RA.sort(toReadonlyArray(self), O))
|
|
1034
|
-
)
|
|
1035
|
-
|
|
1036
|
-
/**
|
|
1037
|
-
* @since 2.0.0
|
|
1038
|
-
* @category sorting
|
|
1039
|
-
*/
|
|
1040
|
-
export const sortWith: {
|
|
1041
|
-
<A, B>(f: (a: A) => B, order: Order.Order<B>): (self: Chunk<A>) => Chunk<A>
|
|
1042
|
-
<A, B>(self: Chunk<A>, f: (a: A) => B, order: Order.Order<B>): Chunk<A>
|
|
1043
|
-
} = dual(
|
|
1044
|
-
3,
|
|
1045
|
-
<A, B>(self: Chunk<A>, f: (a: A) => B, order: Order.Order<B>): Chunk<A> => sort(self, Order.mapInput(order, f))
|
|
1046
|
-
)
|
|
1047
|
-
|
|
1048
|
-
/**
|
|
1049
|
-
* Returns two splits of this chunk at the specified index.
|
|
1050
|
-
*
|
|
1051
|
-
* @since 2.0.0
|
|
1052
|
-
* @category splitting
|
|
1053
|
-
*/
|
|
1054
|
-
export const splitAt: {
|
|
1055
|
-
(n: number): <A>(self: Chunk<A>) => [beforeIndex: Chunk<A>, fromIndex: Chunk<A>]
|
|
1056
|
-
<A>(self: Chunk<A>, n: number): [beforeIndex: Chunk<A>, fromIndex: Chunk<A>]
|
|
1057
|
-
} = dual(2, <A>(self: Chunk<A>, n: number): [Chunk<A>, Chunk<A>] => [take(self, n), drop(self, n)])
|
|
1058
|
-
|
|
1059
|
-
/**
|
|
1060
|
-
* Splits a `NonEmptyChunk` into two segments, with the first segment containing a maximum of `n` elements.
|
|
1061
|
-
* The value of `n` must be `>= 1`.
|
|
1062
|
-
*
|
|
1063
|
-
* @category splitting
|
|
1064
|
-
* @since 2.0.0
|
|
1065
|
-
*/
|
|
1066
|
-
export const splitNonEmptyAt: {
|
|
1067
|
-
(n: number): <A>(self: NonEmptyChunk<A>) => [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>]
|
|
1068
|
-
<A>(self: NonEmptyChunk<A>, n: number): [beforeIndex: NonEmptyChunk<A>, fromIndex: Chunk<A>]
|
|
1069
|
-
} = dual(2, <A>(self: NonEmptyChunk<A>, n: number): [Chunk<A>, Chunk<A>] => {
|
|
1070
|
-
const _n = Math.max(1, Math.floor(n))
|
|
1071
|
-
return _n >= self.length ?
|
|
1072
|
-
[self, empty()] :
|
|
1073
|
-
[take(self, _n), drop(self, _n)]
|
|
1074
|
-
})
|
|
1075
|
-
|
|
1076
|
-
/**
|
|
1077
|
-
* Splits this chunk into `n` equally sized chunks.
|
|
1078
|
-
*
|
|
1079
|
-
* @since 2.0.0
|
|
1080
|
-
* @category splitting
|
|
1081
|
-
*/
|
|
1082
|
-
export const split: {
|
|
1083
|
-
(n: number): <A>(self: Chunk<A>) => Chunk<Chunk<A>>
|
|
1084
|
-
<A>(self: Chunk<A>, n: number): Chunk<Chunk<A>>
|
|
1085
|
-
} = dual(2, <A>(self: Chunk<A>, n: number) => chunksOf(self, Math.ceil(self.length / Math.floor(n))))
|
|
1086
|
-
|
|
1087
|
-
/**
|
|
1088
|
-
* Splits this chunk on the first element that matches this predicate.
|
|
1089
|
-
* Returns a tuple containing two chunks: the first one is before the match, and the second one is from the match onward.
|
|
1090
|
-
*
|
|
1091
|
-
* @category splitting
|
|
1092
|
-
* @since 2.0.0
|
|
1093
|
-
*/
|
|
1094
|
-
export const splitWhere: {
|
|
1095
|
-
<A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => [beforeMatch: Chunk<A>, fromMatch: Chunk<A>]
|
|
1096
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): [beforeMatch: Chunk<A>, fromMatch: Chunk<A>]
|
|
1097
|
-
} = dual(2, <A>(self: Chunk<A>, predicate: Predicate<A>): [beforeMatch: Chunk<A>, fromMatch: Chunk<A>] => {
|
|
1098
|
-
let i = 0
|
|
1099
|
-
for (const a of toReadonlyArray(self)) {
|
|
1100
|
-
if (predicate(a)) {
|
|
1101
|
-
break
|
|
1102
|
-
} else {
|
|
1103
|
-
i++
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
return splitAt(self, i)
|
|
1107
|
-
})
|
|
1108
|
-
|
|
1109
|
-
/**
|
|
1110
|
-
* Returns every elements after the first.
|
|
1111
|
-
*
|
|
1112
|
-
* @since 2.0.0
|
|
1113
|
-
* @category elements
|
|
1114
|
-
*/
|
|
1115
|
-
export const tail = <A>(self: Chunk<A>): Option<Chunk<A>> => self.length > 0 ? O.some(drop(self, 1)) : O.none()
|
|
1116
|
-
|
|
1117
|
-
/**
|
|
1118
|
-
* Returns every elements after the first.
|
|
1119
|
-
*
|
|
1120
|
-
* @since 2.0.0
|
|
1121
|
-
* @category elements
|
|
1122
|
-
*/
|
|
1123
|
-
export const tailNonEmpty = <A>(self: NonEmptyChunk<A>): Chunk<A> => drop(self, 1)
|
|
1124
|
-
|
|
1125
|
-
/**
|
|
1126
|
-
* Takes the last `n` elements.
|
|
1127
|
-
*
|
|
1128
|
-
* @since 2.0.0
|
|
1129
|
-
* @category elements
|
|
1130
|
-
*/
|
|
1131
|
-
export const takeRight: {
|
|
1132
|
-
(n: number): <A>(self: Chunk<A>) => Chunk<A>
|
|
1133
|
-
<A>(self: Chunk<A>, n: number): Chunk<A>
|
|
1134
|
-
} = dual(2, <A>(self: Chunk<A>, n: number): Chunk<A> => drop(self, self.length - n))
|
|
1135
|
-
|
|
1136
|
-
/**
|
|
1137
|
-
* Takes all elements so long as the predicate returns true.
|
|
1138
|
-
*
|
|
1139
|
-
* @since 2.0.0
|
|
1140
|
-
* @category elements
|
|
1141
|
-
*/
|
|
1142
|
-
export const takeWhile: {
|
|
1143
|
-
<A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Chunk<B>
|
|
1144
|
-
<A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Chunk<A>
|
|
1145
|
-
<A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Chunk<B>
|
|
1146
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A>
|
|
1147
|
-
} = dual(2, <A>(self: Chunk<A>, predicate: Predicate<A>): Chunk<A> => {
|
|
1148
|
-
const out: Array<A> = []
|
|
1149
|
-
for (const a of toReadonlyArray(self)) {
|
|
1150
|
-
if (predicate(a)) {
|
|
1151
|
-
out.push(a)
|
|
1152
|
-
} else {
|
|
1153
|
-
break
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
return unsafeFromArray(out)
|
|
1157
|
-
})
|
|
1158
|
-
|
|
1159
|
-
/**
|
|
1160
|
-
* Creates a Chunks of unique values, in order, from all given Chunks.
|
|
1161
|
-
*
|
|
1162
|
-
* @since 2.0.0
|
|
1163
|
-
* @category elements
|
|
1164
|
-
*/
|
|
1165
|
-
export const union: {
|
|
1166
|
-
<A>(that: Chunk<A>): <B>(self: Chunk<B>) => Chunk<A | B>
|
|
1167
|
-
<A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<A | B>
|
|
1168
|
-
} = dual(
|
|
1169
|
-
2,
|
|
1170
|
-
<A, B>(self: Chunk<A>, that: Chunk<B>) => unsafeFromArray(RA.union(toReadonlyArray(self), toReadonlyArray(that)))
|
|
1171
|
-
)
|
|
1172
|
-
|
|
1173
|
-
/**
|
|
1174
|
-
* Remove duplicates from an array, keeping the first occurrence of an element.
|
|
1175
|
-
*
|
|
1176
|
-
* @since 2.0.0
|
|
1177
|
-
* @category elements
|
|
1178
|
-
*/
|
|
1179
|
-
export const dedupe = <A>(self: Chunk<A>): Chunk<A> => unsafeFromArray(RA.dedupe(toReadonlyArray(self)))
|
|
1180
|
-
|
|
1181
|
-
/**
|
|
1182
|
-
* Deduplicates adjacent elements that are identical.
|
|
1183
|
-
*
|
|
1184
|
-
* @since 2.0.0
|
|
1185
|
-
* @category filtering
|
|
1186
|
-
*/
|
|
1187
|
-
export const dedupeAdjacent = <A>(self: Chunk<A>): Chunk<A> => unsafeFromArray(RA.dedupeAdjacent(self))
|
|
1188
|
-
|
|
1189
|
-
/**
|
|
1190
|
-
* Takes a `Chunk` of pairs and return two corresponding `Chunk`s.
|
|
1191
|
-
*
|
|
1192
|
-
* Note: The function is reverse of `zip`.
|
|
1193
|
-
*
|
|
1194
|
-
* @since 2.0.0
|
|
1195
|
-
* @category elements
|
|
1196
|
-
*/
|
|
1197
|
-
export const unzip = <A, B>(self: Chunk<readonly [A, B]>): [Chunk<A>, Chunk<B>] => {
|
|
1198
|
-
const [left, right] = RA.unzip(self)
|
|
1199
|
-
return [unsafeFromArray(left), unsafeFromArray(right)]
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
/**
|
|
1203
|
-
* Zips this chunk pointwise with the specified chunk using the specified combiner.
|
|
1204
|
-
*
|
|
1205
|
-
* @since 2.0.0
|
|
1206
|
-
* @category zipping
|
|
1207
|
-
*/
|
|
1208
|
-
export const zipWith: {
|
|
1209
|
-
<A, B, C>(that: Chunk<B>, f: (a: A, b: B) => C): (self: Chunk<A>) => Chunk<C>
|
|
1210
|
-
<A, B, C>(self: Chunk<A>, that: Chunk<B>, f: (a: A, b: B) => C): Chunk<C>
|
|
1211
|
-
} = dual(
|
|
1212
|
-
3,
|
|
1213
|
-
<A, B, C>(self: Chunk<A>, that: Chunk<B>, f: (a: A, b: B) => C): Chunk<C> =>
|
|
1214
|
-
unsafeFromArray(RA.zipWith(self, that, f))
|
|
1215
|
-
)
|
|
1216
|
-
|
|
1217
|
-
/**
|
|
1218
|
-
* Zips this chunk pointwise with the specified chunk.
|
|
1219
|
-
*
|
|
1220
|
-
* @since 2.0.0
|
|
1221
|
-
* @category zipping
|
|
1222
|
-
*/
|
|
1223
|
-
export const zip: {
|
|
1224
|
-
<B>(that: Chunk<B>): <A>(self: Chunk<A>) => Chunk<[A, B]>
|
|
1225
|
-
<A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<[A, B]>
|
|
1226
|
-
} = dual(
|
|
1227
|
-
2,
|
|
1228
|
-
<A, B>(self: Chunk<A>, that: Chunk<B>): Chunk<[A, B]> => zipWith(self, that, (a, b) => [a, b])
|
|
1229
|
-
)
|
|
1230
|
-
|
|
1231
|
-
/**
|
|
1232
|
-
* Delete the element at the specified index, creating a new `Chunk`.
|
|
1233
|
-
*
|
|
1234
|
-
* @since 2.0.0
|
|
1235
|
-
*/
|
|
1236
|
-
export const remove: {
|
|
1237
|
-
(i: number): <A>(self: Chunk<A>) => Chunk<A>
|
|
1238
|
-
<A>(self: Chunk<A>, i: number): Chunk<A>
|
|
1239
|
-
} = dual(
|
|
1240
|
-
2,
|
|
1241
|
-
<A>(self: Chunk<A>, i: number): Chunk<A> => {
|
|
1242
|
-
if (i < 0 || i >= self.length) return self
|
|
1243
|
-
return unsafeFromArray(RA.remove(toReadonlyArray(self), i))
|
|
1244
|
-
}
|
|
1245
|
-
)
|
|
1246
|
-
|
|
1247
|
-
/**
|
|
1248
|
-
* @since 3.16.0
|
|
1249
|
-
*/
|
|
1250
|
-
export const removeOption: {
|
|
1251
|
-
(i: number): <A>(self: Chunk<A>) => Option<Chunk<A>>
|
|
1252
|
-
<A>(self: Chunk<A>, i: number): Option<Chunk<A>>
|
|
1253
|
-
} = dual(
|
|
1254
|
-
2,
|
|
1255
|
-
<A>(self: Chunk<A>, i: number): Option<Chunk<A>> => {
|
|
1256
|
-
if (i < 0 || i >= self.length) return O.none()
|
|
1257
|
-
return O.some(unsafeFromArray(RA.remove(toReadonlyArray(self), i)))
|
|
1258
|
-
}
|
|
1259
|
-
)
|
|
1260
|
-
|
|
1261
|
-
/**
|
|
1262
|
-
* @since 2.0.0
|
|
1263
|
-
*/
|
|
1264
|
-
export const modifyOption: {
|
|
1265
|
-
<A, B>(i: number, f: (a: A) => B): (self: Chunk<A>) => Option<Chunk<A | B>>
|
|
1266
|
-
<A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Option<Chunk<A | B>>
|
|
1267
|
-
} = dual(
|
|
1268
|
-
3,
|
|
1269
|
-
<A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Option<Chunk<A | B>> => {
|
|
1270
|
-
if (i < 0 || i >= self.length) return O.none()
|
|
1271
|
-
return O.some(unsafeFromArray(RA.modify(toReadonlyArray(self), i, f)))
|
|
1272
|
-
}
|
|
1273
|
-
)
|
|
1274
|
-
|
|
1275
|
-
/**
|
|
1276
|
-
* Apply a function to the element at the specified index, creating a new `Chunk`,
|
|
1277
|
-
* or returning the input if the index is out of bounds.
|
|
1278
|
-
*
|
|
1279
|
-
* @since 2.0.0
|
|
1280
|
-
*/
|
|
1281
|
-
export const modify: {
|
|
1282
|
-
<A, B>(i: number, f: (a: A) => B): (self: Chunk<A>) => Chunk<A | B>
|
|
1283
|
-
<A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Chunk<A | B>
|
|
1284
|
-
} = dual(
|
|
1285
|
-
3,
|
|
1286
|
-
<A, B>(self: Chunk<A>, i: number, f: (a: A) => B): Chunk<A | B> => O.getOrElse(modifyOption(self, i, f), () => self)
|
|
1287
|
-
)
|
|
1288
|
-
|
|
1289
|
-
/**
|
|
1290
|
-
* Change the element at the specified index, creating a new `Chunk`,
|
|
1291
|
-
* or returning the input if the index is out of bounds.
|
|
1292
|
-
*
|
|
1293
|
-
* @since 2.0.0
|
|
1294
|
-
*/
|
|
1295
|
-
export const replace: {
|
|
1296
|
-
<B>(i: number, b: B): <A>(self: Chunk<A>) => Chunk<B | A>
|
|
1297
|
-
<A, B>(self: Chunk<A>, i: number, b: B): Chunk<B | A>
|
|
1298
|
-
} = dual(3, <A, B>(self: Chunk<A>, i: number, b: B): Chunk<B | A> => modify(self, i, () => b))
|
|
1299
|
-
|
|
1300
|
-
/**
|
|
1301
|
-
* @since 2.0.0
|
|
1302
|
-
*/
|
|
1303
|
-
export const replaceOption: {
|
|
1304
|
-
<B>(i: number, b: B): <A>(self: Chunk<A>) => Option<Chunk<B | A>>
|
|
1305
|
-
<A, B>(self: Chunk<A>, i: number, b: B): Option<Chunk<B | A>>
|
|
1306
|
-
} = dual(3, <A, B>(self: Chunk<A>, i: number, b: B): Option<Chunk<B | A>> => modifyOption(self, i, () => b))
|
|
1307
|
-
|
|
1308
|
-
/**
|
|
1309
|
-
* Return a Chunk of length n with element i initialized with f(i).
|
|
1310
|
-
*
|
|
1311
|
-
* **Note**. `n` is normalized to an integer >= 1.
|
|
1312
|
-
*
|
|
1313
|
-
* @category constructors
|
|
1314
|
-
* @since 2.0.0
|
|
1315
|
-
*/
|
|
1316
|
-
export const makeBy: {
|
|
1317
|
-
<A>(f: (i: number) => A): (n: number) => NonEmptyChunk<A>
|
|
1318
|
-
<A>(n: number, f: (i: number) => A): NonEmptyChunk<A>
|
|
1319
|
-
} = dual(2, (n, f) => fromIterable(RA.makeBy(n, f)))
|
|
1320
|
-
|
|
1321
|
-
/**
|
|
1322
|
-
* Create a non empty `Chunk` containing a range of integers, including both endpoints.
|
|
1323
|
-
*
|
|
1324
|
-
* @category constructors
|
|
1325
|
-
* @since 2.0.0
|
|
1326
|
-
*/
|
|
1327
|
-
export const range = (start: number, end: number): NonEmptyChunk<number> =>
|
|
1328
|
-
start <= end ? makeBy(end - start + 1, (i) => start + i) : of(start)
|
|
1329
|
-
|
|
1330
|
-
// -------------------------------------------------------------------------------------
|
|
1331
|
-
// re-exports from ReadonlyArray
|
|
1332
|
-
// -------------------------------------------------------------------------------------
|
|
1333
|
-
|
|
1334
|
-
/**
|
|
1335
|
-
* Returns a function that checks if a `Chunk` contains a given value using the default `Equivalence`.
|
|
1336
|
-
*
|
|
1337
|
-
* @category elements
|
|
1338
|
-
* @since 2.0.0
|
|
1339
|
-
*/
|
|
1340
|
-
export const contains: {
|
|
1341
|
-
<A>(a: A): (self: Chunk<A>) => boolean
|
|
1342
|
-
<A>(self: Chunk<A>, a: A): boolean
|
|
1343
|
-
} = RA.contains
|
|
1344
|
-
|
|
1345
|
-
/**
|
|
1346
|
-
* Returns a function that checks if a `Chunk` contains a given value using a provided `isEquivalent` function.
|
|
1347
|
-
*
|
|
1348
|
-
* @category elements
|
|
1349
|
-
* @since 2.0.0
|
|
1350
|
-
*/
|
|
1351
|
-
export const containsWith: <A>(
|
|
1352
|
-
isEquivalent: (self: A, that: A) => boolean
|
|
1353
|
-
) => {
|
|
1354
|
-
(a: A): (self: Chunk<A>) => boolean
|
|
1355
|
-
(self: Chunk<A>, a: A): boolean
|
|
1356
|
-
} = RA.containsWith
|
|
1357
|
-
|
|
1358
|
-
/**
|
|
1359
|
-
* Returns the first element that satisfies the specified
|
|
1360
|
-
* predicate, or `None` if no such element exists.
|
|
1361
|
-
*
|
|
1362
|
-
* @category elements
|
|
1363
|
-
* @since 2.0.0
|
|
1364
|
-
*/
|
|
1365
|
-
export const findFirst: {
|
|
1366
|
-
<A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Option<B>
|
|
1367
|
-
<A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Option<A>
|
|
1368
|
-
<A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Option<B>
|
|
1369
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): Option<A>
|
|
1370
|
-
} = RA.findFirst
|
|
1371
|
-
|
|
1372
|
-
/**
|
|
1373
|
-
* Return the first index for which a predicate holds.
|
|
1374
|
-
*
|
|
1375
|
-
* @category elements
|
|
1376
|
-
* @since 2.0.0
|
|
1377
|
-
*/
|
|
1378
|
-
export const findFirstIndex: {
|
|
1379
|
-
<A>(predicate: Predicate<A>): (self: Chunk<A>) => Option<number>
|
|
1380
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): Option<number>
|
|
1381
|
-
} = RA.findFirstIndex
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* Find the last element for which a predicate holds.
|
|
1385
|
-
*
|
|
1386
|
-
* @category elements
|
|
1387
|
-
* @since 2.0.0
|
|
1388
|
-
*/
|
|
1389
|
-
export const findLast: {
|
|
1390
|
-
<A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => Option<B>
|
|
1391
|
-
<A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => Option<A>
|
|
1392
|
-
<A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): Option<B>
|
|
1393
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): Option<A>
|
|
1394
|
-
} = RA.findLast
|
|
1395
|
-
|
|
1396
|
-
/**
|
|
1397
|
-
* Return the last index for which a predicate holds.
|
|
1398
|
-
*
|
|
1399
|
-
* @category elements
|
|
1400
|
-
* @since 2.0.0
|
|
1401
|
-
*/
|
|
1402
|
-
export const findLastIndex: {
|
|
1403
|
-
<A>(predicate: Predicate<A>): (self: Chunk<A>) => Option<number>
|
|
1404
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): Option<number>
|
|
1405
|
-
} = RA.findLastIndex
|
|
1406
|
-
|
|
1407
|
-
/**
|
|
1408
|
-
* Check if a predicate holds true for every `Chunk` element.
|
|
1409
|
-
*
|
|
1410
|
-
* @category elements
|
|
1411
|
-
* @since 2.0.0
|
|
1412
|
-
*/
|
|
1413
|
-
export const every: {
|
|
1414
|
-
<A, B extends A>(refinement: Refinement<NoInfer<A>, B>): (self: Chunk<A>) => self is Chunk<B>
|
|
1415
|
-
<A>(predicate: Predicate<A>): (self: Chunk<A>) => boolean
|
|
1416
|
-
<A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): self is Chunk<B>
|
|
1417
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): boolean
|
|
1418
|
-
} = dual(
|
|
1419
|
-
2,
|
|
1420
|
-
<A, B extends A>(self: Chunk<A>, refinement: Refinement<A, B>): self is Chunk<B> =>
|
|
1421
|
-
RA.fromIterable(self).every(refinement)
|
|
1422
|
-
)
|
|
1423
|
-
|
|
1424
|
-
/**
|
|
1425
|
-
* Check if a predicate holds true for some `Chunk` element.
|
|
1426
|
-
*
|
|
1427
|
-
* @category elements
|
|
1428
|
-
* @since 2.0.0
|
|
1429
|
-
*/
|
|
1430
|
-
export const some: {
|
|
1431
|
-
<A>(predicate: Predicate<NoInfer<A>>): (self: Chunk<A>) => self is NonEmptyChunk<A>
|
|
1432
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): self is NonEmptyChunk<A>
|
|
1433
|
-
} = dual(
|
|
1434
|
-
2,
|
|
1435
|
-
<A>(self: Chunk<A>, predicate: Predicate<A>): self is NonEmptyChunk<A> => RA.fromIterable(self).some(predicate)
|
|
1436
|
-
)
|
|
1437
|
-
|
|
1438
|
-
/**
|
|
1439
|
-
* Joins the elements together with "sep" in the middle.
|
|
1440
|
-
*
|
|
1441
|
-
* @category folding
|
|
1442
|
-
* @since 2.0.0
|
|
1443
|
-
*/
|
|
1444
|
-
export const join: {
|
|
1445
|
-
(sep: string): (self: Chunk<string>) => string
|
|
1446
|
-
(self: Chunk<string>, sep: string): string
|
|
1447
|
-
} = RA.join
|
|
1448
|
-
|
|
1449
|
-
/**
|
|
1450
|
-
* @category folding
|
|
1451
|
-
* @since 2.0.0
|
|
1452
|
-
*/
|
|
1453
|
-
export const reduce: {
|
|
1454
|
-
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B
|
|
1455
|
-
<A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
1456
|
-
} = RA.reduce
|
|
1457
|
-
|
|
1458
|
-
/**
|
|
1459
|
-
* @category folding
|
|
1460
|
-
* @since 2.0.0
|
|
1461
|
-
*/
|
|
1462
|
-
export const reduceRight: {
|
|
1463
|
-
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Chunk<A>) => B
|
|
1464
|
-
<A, B>(self: Chunk<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
1465
|
-
} = RA.reduceRight
|
|
1466
|
-
|
|
1467
|
-
/**
|
|
1468
|
-
* Creates a `Chunk` of values not included in the other given `Chunk` using the provided `isEquivalent` function.
|
|
1469
|
-
* The order and references of result values are determined by the first `Chunk`.
|
|
1470
|
-
*
|
|
1471
|
-
* @since 3.2.0
|
|
1472
|
-
*/
|
|
1473
|
-
export const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {
|
|
1474
|
-
(that: Chunk<A>): (self: Chunk<A>) => Chunk<A>
|
|
1475
|
-
(self: Chunk<A>, that: Chunk<A>): Chunk<A>
|
|
1476
|
-
} => {
|
|
1477
|
-
return dual(
|
|
1478
|
-
2,
|
|
1479
|
-
(self: Chunk<A>, that: Chunk<A>): Chunk<A> => unsafeFromArray(RA.differenceWith(isEquivalent)(that, self))
|
|
1480
|
-
)
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
/**
|
|
1484
|
-
* Creates a `Chunk` of values not included in the other given `Chunk`.
|
|
1485
|
-
* The order and references of result values are determined by the first `Chunk`.
|
|
1486
|
-
*
|
|
1487
|
-
* @since 3.2.0
|
|
1488
|
-
*/
|
|
1489
|
-
export const difference: {
|
|
1490
|
-
<A>(that: Chunk<A>): (self: Chunk<A>) => Chunk<A>
|
|
1491
|
-
<A>(self: Chunk<A>, that: Chunk<A>): Chunk<A>
|
|
1492
|
-
} = dual(
|
|
1493
|
-
2,
|
|
1494
|
-
<A>(self: Chunk<A>, that: Chunk<A>): Chunk<A> => unsafeFromArray(RA.difference(that, self))
|
|
1495
|
-
)
|