effect 3.8.3 → 3.8.5
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/Array.js.map +1 -1
- package/dist/cjs/BigDecimal.js +2 -3
- package/dist/cjs/BigDecimal.js.map +1 -1
- package/dist/cjs/BigInt.js.map +1 -1
- package/dist/cjs/Boolean.js.map +1 -1
- package/dist/cjs/Cause.js.map +1 -1
- package/dist/cjs/Channel.js.map +1 -1
- package/dist/cjs/ChildExecutorDecision.js.map +1 -1
- package/dist/cjs/Chunk.js.map +1 -1
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/ConfigError.js.map +1 -1
- package/dist/cjs/ConfigProvider.js.map +1 -1
- package/dist/cjs/ConfigProviderPathPatch.js.map +1 -1
- package/dist/cjs/Console.js.map +1 -1
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/DateTime.js.map +1 -1
- package/dist/cjs/Deferred.js.map +1 -1
- package/dist/cjs/Differ.js.map +1 -1
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Either.js.map +1 -1
- package/dist/cjs/Equivalence.js.map +1 -1
- package/dist/cjs/ExecutionStrategy.js.map +1 -1
- package/dist/cjs/Exit.js.map +1 -1
- package/dist/cjs/Fiber.js.map +1 -1
- package/dist/cjs/FiberHandle.js.map +1 -1
- package/dist/cjs/FiberId.js.map +1 -1
- package/dist/cjs/FiberMap.js.map +1 -1
- package/dist/cjs/FiberRef.js.map +1 -1
- package/dist/cjs/FiberRefs.js.map +1 -1
- package/dist/cjs/FiberRefsPatch.js.map +1 -1
- package/dist/cjs/FiberSet.js.map +1 -1
- package/dist/cjs/Function.js.map +1 -1
- package/dist/cjs/GroupBy.js.map +1 -1
- package/dist/cjs/Hash.js.map +1 -1
- package/dist/cjs/HashMap.js.map +1 -1
- package/dist/cjs/HashSet.js.map +1 -1
- package/dist/cjs/Iterable.js.map +1 -1
- package/dist/cjs/KeyedPool.js.map +1 -1
- package/dist/cjs/Layer.js.map +1 -1
- package/dist/cjs/List.js.map +1 -1
- package/dist/cjs/LogLevel.js.map +1 -1
- package/dist/cjs/Logger.js.map +1 -1
- package/dist/cjs/Mailbox.js.map +1 -1
- package/dist/cjs/MergeDecision.js.map +1 -1
- package/dist/cjs/MergeState.js.map +1 -1
- package/dist/cjs/MergeStrategy.js.map +1 -1
- package/dist/cjs/Metric.js.map +1 -1
- package/dist/cjs/MetricHook.js.map +1 -1
- package/dist/cjs/MetricKey.js.map +1 -1
- package/dist/cjs/MetricPolling.js.map +1 -1
- package/dist/cjs/MetricState.js.map +1 -1
- package/dist/cjs/Micro.js +54 -23
- package/dist/cjs/Micro.js.map +1 -1
- package/dist/cjs/MutableHashMap.js.map +1 -1
- package/dist/cjs/MutableHashSet.js.map +1 -1
- package/dist/cjs/MutableList.js.map +1 -1
- package/dist/cjs/MutableQueue.js.map +1 -1
- package/dist/cjs/MutableRef.js.map +1 -1
- package/dist/cjs/Number.js.map +1 -1
- package/dist/cjs/Option.js.map +1 -1
- package/dist/cjs/Order.js.map +1 -1
- package/dist/cjs/Ordering.js.map +1 -1
- package/dist/cjs/Pipeable.js.map +1 -1
- package/dist/cjs/Pool.js.map +1 -1
- package/dist/cjs/Predicate.js.map +1 -1
- package/dist/cjs/PubSub.js.map +1 -1
- package/dist/cjs/Queue.js.map +1 -1
- package/dist/cjs/RcMap.js.map +1 -1
- package/dist/cjs/Readable.js.map +1 -1
- package/dist/cjs/Record.js.map +1 -1
- package/dist/cjs/RedBlackTree.js.map +1 -1
- package/dist/cjs/Ref.js.map +1 -1
- package/dist/cjs/Request.js.map +1 -1
- package/dist/cjs/RequestResolver.js.map +1 -1
- package/dist/cjs/Runtime.js.map +1 -1
- package/dist/cjs/RuntimeFlags.js.map +1 -1
- package/dist/cjs/RuntimeFlagsPatch.js.map +1 -1
- package/dist/cjs/STM.js.map +1 -1
- package/dist/cjs/Schedule.js.map +1 -1
- package/dist/cjs/ScheduleInterval.js.map +1 -1
- package/dist/cjs/ScheduleIntervals.js.map +1 -1
- package/dist/cjs/Scheduler.js.map +1 -1
- package/dist/cjs/Scope.js +25 -15
- package/dist/cjs/Scope.js.map +1 -1
- package/dist/cjs/ScopedRef.js.map +1 -1
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/SortedMap.js.map +1 -1
- package/dist/cjs/SortedSet.js.map +1 -1
- package/dist/cjs/Stream.js +17 -3
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/StreamHaltStrategy.js.map +1 -1
- package/dist/cjs/String.js.map +1 -1
- package/dist/cjs/Struct.js.map +1 -1
- package/dist/cjs/Subscribable.js.map +1 -1
- package/dist/cjs/SubscriptionRef.js.map +1 -1
- package/dist/cjs/SynchronizedRef.js.map +1 -1
- package/dist/cjs/TArray.js.map +1 -1
- package/dist/cjs/TDeferred.js.map +1 -1
- package/dist/cjs/TMap.js.map +1 -1
- package/dist/cjs/TPriorityQueue.js.map +1 -1
- package/dist/cjs/TPubSub.js.map +1 -1
- package/dist/cjs/TQueue.js.map +1 -1
- package/dist/cjs/TReentrantLock.js.map +1 -1
- package/dist/cjs/TRef.js.map +1 -1
- package/dist/cjs/TSemaphore.js.map +1 -1
- package/dist/cjs/TSet.js.map +1 -1
- package/dist/cjs/Take.js.map +1 -1
- package/dist/cjs/TestAnnotationMap.js.map +1 -1
- package/dist/cjs/TestClock.js.map +1 -1
- package/dist/cjs/TestServices.js.map +1 -1
- package/dist/cjs/Trie.js.map +1 -1
- package/dist/cjs/Tuple.js.map +1 -1
- package/dist/cjs/Unify.js.map +1 -1
- package/dist/cjs/UpstreamPullRequest.js.map +1 -1
- package/dist/cjs/UpstreamPullStrategy.js.map +1 -1
- package/dist/cjs/Utils.js +1 -14
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/internal/core.js +4 -3
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/runtime.js +1 -1
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/stream.js +12 -3
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +2684 -0
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/BigDecimal.d.ts +558 -1
- package/dist/dts/BigDecimal.d.ts.map +1 -1
- package/dist/dts/BigInt.d.ts +490 -0
- package/dist/dts/BigInt.d.ts.map +1 -1
- package/dist/dts/Boolean.d.ts +228 -0
- package/dist/dts/Boolean.d.ts.map +1 -1
- package/dist/dts/Cause.d.ts +172 -0
- package/dist/dts/Cause.d.ts.map +1 -1
- package/dist/dts/Channel.d.ts +750 -0
- package/dist/dts/Channel.d.ts.map +1 -1
- package/dist/dts/ChildExecutorDecision.d.ts +12 -0
- package/dist/dts/ChildExecutorDecision.d.ts.map +1 -1
- package/dist/dts/Chunk.d.ts +791 -0
- package/dist/dts/Chunk.d.ts.map +1 -1
- package/dist/dts/Config.d.ts +174 -0
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/ConfigError.d.ts +16 -0
- package/dist/dts/ConfigError.d.ts.map +1 -1
- package/dist/dts/ConfigProvider.d.ts +84 -0
- package/dist/dts/ConfigProvider.d.ts.map +1 -1
- package/dist/dts/ConfigProviderPathPatch.d.ts +32 -0
- package/dist/dts/ConfigProviderPathPatch.d.ts.map +1 -1
- package/dist/dts/Console.d.ts +24 -0
- package/dist/dts/Console.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +232 -0
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Cron.d.ts +12 -0
- package/dist/dts/Cron.d.ts.map +1 -1
- package/dist/dts/Data.d.ts +165 -0
- package/dist/dts/Data.d.ts.map +1 -1
- package/dist/dts/DateTime.d.ts +878 -0
- package/dist/dts/DateTime.d.ts.map +1 -1
- package/dist/dts/Deferred.d.ts +170 -0
- package/dist/dts/Deferred.d.ts.map +1 -1
- package/dist/dts/Differ.d.ts +78 -0
- package/dist/dts/Differ.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts +130 -0
- package/dist/dts/Duration.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +4117 -3
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Either.d.ts +620 -0
- package/dist/dts/Either.d.ts.map +1 -1
- package/dist/dts/Equivalence.d.ts +24 -0
- package/dist/dts/Equivalence.d.ts.map +1 -1
- package/dist/dts/ExecutionStrategy.d.ts +14 -0
- package/dist/dts/ExecutionStrategy.d.ts.map +1 -1
- package/dist/dts/Exit.d.ts +252 -0
- package/dist/dts/Exit.d.ts.map +1 -1
- package/dist/dts/Fiber.d.ts +182 -0
- package/dist/dts/Fiber.d.ts.map +1 -1
- package/dist/dts/FiberHandle.d.ts +42 -0
- package/dist/dts/FiberHandle.d.ts.map +1 -1
- package/dist/dts/FiberId.d.ts +24 -0
- package/dist/dts/FiberId.d.ts.map +1 -1
- package/dist/dts/FiberMap.d.ts +102 -0
- package/dist/dts/FiberMap.d.ts.map +1 -1
- package/dist/dts/FiberRef.d.ts +80 -0
- package/dist/dts/FiberRef.d.ts.map +1 -1
- package/dist/dts/FiberRefs.d.ts +84 -0
- package/dist/dts/FiberRefs.d.ts.map +1 -1
- package/dist/dts/FiberRefsPatch.d.ts +30 -0
- package/dist/dts/FiberRefsPatch.d.ts.map +1 -1
- package/dist/dts/FiberSet.d.ts +38 -0
- package/dist/dts/FiberSet.d.ts.map +1 -1
- package/dist/dts/Function.d.ts +144 -28
- package/dist/dts/Function.d.ts.map +1 -1
- package/dist/dts/GroupBy.d.ts +38 -0
- package/dist/dts/GroupBy.d.ts.map +1 -1
- package/dist/dts/Hash.d.ts +8 -0
- package/dist/dts/Hash.d.ts.map +1 -1
- package/dist/dts/HashMap.d.ts +300 -0
- package/dist/dts/HashMap.d.ts.map +1 -1
- package/dist/dts/HashSet.d.ts +284 -0
- package/dist/dts/HashSet.d.ts.map +1 -1
- package/dist/dts/Iterable.d.ts +454 -0
- package/dist/dts/Iterable.d.ts.map +1 -1
- package/dist/dts/KeyedPool.d.ts +34 -0
- package/dist/dts/KeyedPool.d.ts.map +1 -1
- package/dist/dts/Layer.d.ts +414 -0
- package/dist/dts/Layer.d.ts.map +1 -1
- package/dist/dts/List.d.ts +430 -0
- package/dist/dts/List.d.ts.map +1 -1
- package/dist/dts/LogLevel.d.ts +46 -0
- package/dist/dts/LogLevel.d.ts.map +1 -1
- package/dist/dts/Logger.d.ts +194 -0
- package/dist/dts/Logger.d.ts.map +1 -1
- package/dist/dts/Mailbox.d.ts +16 -0
- package/dist/dts/Mailbox.d.ts.map +1 -1
- package/dist/dts/MergeDecision.d.ts +8 -0
- package/dist/dts/MergeDecision.d.ts.map +1 -1
- package/dist/dts/MergeState.d.ts +8 -0
- package/dist/dts/MergeState.d.ts.map +1 -1
- package/dist/dts/MergeStrategy.d.ts +12 -0
- package/dist/dts/MergeStrategy.d.ts.map +1 -1
- package/dist/dts/Metric.d.ts +410 -0
- package/dist/dts/Metric.d.ts.map +1 -1
- package/dist/dts/MetricHook.d.ts +24 -0
- package/dist/dts/MetricHook.d.ts.map +1 -1
- package/dist/dts/MetricKey.d.ts +48 -0
- package/dist/dts/MetricKey.d.ts.map +1 -1
- package/dist/dts/MetricPolling.d.ts +40 -0
- package/dist/dts/MetricPolling.d.ts.map +1 -1
- package/dist/dts/MetricState.d.ts +16 -0
- package/dist/dts/MetricState.d.ts.map +1 -1
- package/dist/dts/Micro.d.ts +1203 -25
- package/dist/dts/Micro.d.ts.map +1 -1
- package/dist/dts/MutableHashMap.d.ts +50 -0
- package/dist/dts/MutableHashMap.d.ts.map +1 -1
- package/dist/dts/MutableHashSet.d.ts +24 -0
- package/dist/dts/MutableHashSet.d.ts.map +1 -1
- package/dist/dts/MutableList.d.ts +36 -0
- package/dist/dts/MutableList.d.ts.map +1 -1
- package/dist/dts/MutableQueue.d.ts +62 -0
- package/dist/dts/MutableQueue.d.ts.map +1 -1
- package/dist/dts/MutableRef.d.ts +56 -0
- package/dist/dts/MutableRef.d.ts.map +1 -1
- package/dist/dts/Number.d.ts +474 -0
- package/dist/dts/Number.d.ts.map +1 -1
- package/dist/dts/Option.d.ts +1019 -0
- package/dist/dts/Option.d.ts.map +1 -1
- package/dist/dts/Order.d.ts +24 -0
- package/dist/dts/Order.d.ts.map +1 -1
- package/dist/dts/Ordering.d.ts +66 -0
- package/dist/dts/Ordering.d.ts.map +1 -1
- package/dist/dts/Pipeable.d.ts +21 -21
- package/dist/dts/Pipeable.d.ts.map +1 -1
- package/dist/dts/Pool.d.ts +16 -0
- package/dist/dts/Pool.d.ts.map +1 -1
- package/dist/dts/Predicate.d.ts +498 -0
- package/dist/dts/Predicate.d.ts.map +1 -1
- package/dist/dts/PubSub.d.ts +28 -0
- package/dist/dts/PubSub.d.ts.map +1 -1
- package/dist/dts/Queue.d.ts +104 -0
- package/dist/dts/Queue.d.ts.map +1 -1
- package/dist/dts/RcMap.d.ts +70 -0
- package/dist/dts/RcMap.d.ts.map +1 -1
- package/dist/dts/Readable.d.ts +16 -0
- package/dist/dts/Readable.d.ts.map +1 -1
- package/dist/dts/Record.d.ts +800 -0
- package/dist/dts/Record.d.ts.map +1 -1
- package/dist/dts/RedBlackTree.d.ts +300 -0
- package/dist/dts/RedBlackTree.d.ts.map +1 -1
- package/dist/dts/Ref.d.ts +88 -0
- package/dist/dts/Ref.d.ts.map +1 -1
- package/dist/dts/Request.d.ts +76 -0
- package/dist/dts/Request.d.ts.map +1 -1
- package/dist/dts/RequestResolver.d.ts +144 -0
- package/dist/dts/RequestResolver.d.ts.map +1 -1
- package/dist/dts/Runtime.d.ts +126 -0
- package/dist/dts/Runtime.d.ts.map +1 -1
- package/dist/dts/RuntimeFlags.d.ts +100 -0
- package/dist/dts/RuntimeFlags.d.ts.map +1 -1
- package/dist/dts/RuntimeFlagsPatch.d.ts +112 -0
- package/dist/dts/RuntimeFlagsPatch.d.ts.map +1 -1
- package/dist/dts/STM.d.ts +1090 -0
- package/dist/dts/STM.d.ts.map +1 -1
- package/dist/dts/Schedule.d.ts +704 -0
- package/dist/dts/Schedule.d.ts.map +1 -1
- package/dist/dts/ScheduleInterval.d.ts +68 -0
- package/dist/dts/ScheduleInterval.d.ts.map +1 -1
- package/dist/dts/ScheduleIntervals.d.ts +50 -0
- package/dist/dts/ScheduleIntervals.d.ts.map +1 -1
- package/dist/dts/Scope.d.ts +76 -15
- package/dist/dts/Scope.d.ts.map +1 -1
- package/dist/dts/ScopedRef.d.ts +22 -0
- package/dist/dts/ScopedRef.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +464 -0
- package/dist/dts/Sink.d.ts.map +1 -1
- package/dist/dts/SortedMap.d.ts +76 -0
- package/dist/dts/SortedMap.d.ts.map +1 -1
- package/dist/dts/SortedSet.d.ts +142 -0
- package/dist/dts/SortedSet.d.ts.map +1 -1
- package/dist/dts/Stream.d.ts +4998 -1
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/StreamHaltStrategy.d.ts +12 -0
- package/dist/dts/StreamHaltStrategy.d.ts.map +1 -1
- package/dist/dts/String.d.ts +200 -0
- package/dist/dts/String.d.ts.map +1 -1
- package/dist/dts/Struct.d.ts +84 -0
- package/dist/dts/Struct.d.ts.map +1 -1
- package/dist/dts/Subscribable.d.ts +16 -0
- package/dist/dts/Subscribable.d.ts.map +1 -1
- package/dist/dts/SubscriptionRef.d.ts +152 -0
- package/dist/dts/SubscriptionRef.d.ts.map +1 -1
- package/dist/dts/SynchronizedRef.d.ts +152 -0
- package/dist/dts/SynchronizedRef.d.ts.map +1 -1
- package/dist/dts/TArray.d.ts +426 -0
- package/dist/dts/TArray.d.ts.map +1 -1
- package/dist/dts/TDeferred.d.ts +24 -0
- package/dist/dts/TDeferred.d.ts.map +1 -1
- package/dist/dts/TMap.d.ts +366 -0
- package/dist/dts/TMap.d.ts.map +1 -1
- package/dist/dts/TPriorityQueue.d.ts +60 -0
- package/dist/dts/TPriorityQueue.d.ts.map +1 -1
- package/dist/dts/TPubSub.d.ts +28 -0
- package/dist/dts/TPubSub.d.ts.map +1 -1
- package/dist/dts/TQueue.d.ts +108 -0
- package/dist/dts/TQueue.d.ts.map +1 -1
- package/dist/dts/TReentrantLock.d.ts +36 -0
- package/dist/dts/TReentrantLock.d.ts.map +1 -1
- package/dist/dts/TRef.d.ts +88 -0
- package/dist/dts/TRef.d.ts.map +1 -1
- package/dist/dts/TSemaphore.d.ts +40 -0
- package/dist/dts/TSemaphore.d.ts.map +1 -1
- package/dist/dts/TSet.d.ts +254 -0
- package/dist/dts/TSet.d.ts.map +1 -1
- package/dist/dts/Take.d.ts +56 -0
- package/dist/dts/Take.d.ts.map +1 -1
- package/dist/dts/TestAnnotationMap.d.ts.map +1 -1
- package/dist/dts/TestClock.d.ts.map +1 -1
- package/dist/dts/TestServices.d.ts.map +1 -1
- package/dist/dts/Trie.d.ts +906 -0
- package/dist/dts/Trie.d.ts.map +1 -1
- package/dist/dts/Tuple.d.ts +144 -0
- package/dist/dts/Tuple.d.ts.map +1 -1
- package/dist/dts/Unify.d.ts +18 -0
- package/dist/dts/Unify.d.ts.map +1 -1
- package/dist/dts/UpstreamPullRequest.d.ts +12 -0
- package/dist/dts/UpstreamPullRequest.d.ts.map +1 -1
- package/dist/dts/UpstreamPullStrategy.d.ts +12 -0
- package/dist/dts/UpstreamPullStrategy.d.ts.map +1 -1
- package/dist/dts/Utils.d.ts.map +1 -1
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/BigDecimal.js +2 -2
- package/dist/esm/BigDecimal.js.map +1 -1
- package/dist/esm/BigInt.js.map +1 -1
- package/dist/esm/Boolean.js.map +1 -1
- package/dist/esm/Cause.js.map +1 -1
- package/dist/esm/Channel.js.map +1 -1
- package/dist/esm/ChildExecutorDecision.js.map +1 -1
- package/dist/esm/Chunk.js.map +1 -1
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/ConfigError.js.map +1 -1
- package/dist/esm/ConfigProvider.js.map +1 -1
- package/dist/esm/ConfigProviderPathPatch.js.map +1 -1
- package/dist/esm/Console.js.map +1 -1
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/DateTime.js.map +1 -1
- package/dist/esm/Deferred.js.map +1 -1
- package/dist/esm/Differ.js.map +1 -1
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Either.js.map +1 -1
- package/dist/esm/Equivalence.js.map +1 -1
- package/dist/esm/ExecutionStrategy.js.map +1 -1
- package/dist/esm/Exit.js.map +1 -1
- package/dist/esm/Fiber.js.map +1 -1
- package/dist/esm/FiberHandle.js.map +1 -1
- package/dist/esm/FiberId.js.map +1 -1
- package/dist/esm/FiberMap.js.map +1 -1
- package/dist/esm/FiberRef.js.map +1 -1
- package/dist/esm/FiberRefs.js.map +1 -1
- package/dist/esm/FiberRefsPatch.js.map +1 -1
- package/dist/esm/FiberSet.js.map +1 -1
- package/dist/esm/Function.js.map +1 -1
- package/dist/esm/GroupBy.js.map +1 -1
- package/dist/esm/Hash.js.map +1 -1
- package/dist/esm/HashMap.js.map +1 -1
- package/dist/esm/HashSet.js.map +1 -1
- package/dist/esm/Iterable.js.map +1 -1
- package/dist/esm/KeyedPool.js.map +1 -1
- package/dist/esm/Layer.js.map +1 -1
- package/dist/esm/List.js.map +1 -1
- package/dist/esm/LogLevel.js.map +1 -1
- package/dist/esm/Logger.js.map +1 -1
- package/dist/esm/Mailbox.js.map +1 -1
- package/dist/esm/MergeDecision.js.map +1 -1
- package/dist/esm/MergeState.js.map +1 -1
- package/dist/esm/MergeStrategy.js.map +1 -1
- package/dist/esm/Metric.js.map +1 -1
- package/dist/esm/MetricHook.js.map +1 -1
- package/dist/esm/MetricKey.js.map +1 -1
- package/dist/esm/MetricPolling.js.map +1 -1
- package/dist/esm/MetricState.js.map +1 -1
- package/dist/esm/Micro.js +50 -20
- package/dist/esm/Micro.js.map +1 -1
- package/dist/esm/MutableHashMap.js.map +1 -1
- package/dist/esm/MutableHashSet.js.map +1 -1
- package/dist/esm/MutableList.js.map +1 -1
- package/dist/esm/MutableQueue.js.map +1 -1
- package/dist/esm/MutableRef.js.map +1 -1
- package/dist/esm/Number.js.map +1 -1
- package/dist/esm/Option.js.map +1 -1
- package/dist/esm/Order.js.map +1 -1
- package/dist/esm/Ordering.js.map +1 -1
- package/dist/esm/Pipeable.js.map +1 -1
- package/dist/esm/Pool.js.map +1 -1
- package/dist/esm/Predicate.js.map +1 -1
- package/dist/esm/PubSub.js.map +1 -1
- package/dist/esm/Queue.js.map +1 -1
- package/dist/esm/RcMap.js.map +1 -1
- package/dist/esm/Readable.js.map +1 -1
- package/dist/esm/Record.js.map +1 -1
- package/dist/esm/RedBlackTree.js.map +1 -1
- package/dist/esm/Ref.js.map +1 -1
- package/dist/esm/Request.js.map +1 -1
- package/dist/esm/RequestResolver.js.map +1 -1
- package/dist/esm/Runtime.js.map +1 -1
- package/dist/esm/RuntimeFlags.js.map +1 -1
- package/dist/esm/RuntimeFlagsPatch.js.map +1 -1
- package/dist/esm/STM.js.map +1 -1
- package/dist/esm/Schedule.js.map +1 -1
- package/dist/esm/ScheduleInterval.js.map +1 -1
- package/dist/esm/ScheduleIntervals.js.map +1 -1
- package/dist/esm/Scheduler.js.map +1 -1
- package/dist/esm/Scope.js +25 -15
- package/dist/esm/Scope.js.map +1 -1
- package/dist/esm/ScopedRef.js.map +1 -1
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/SortedMap.js.map +1 -1
- package/dist/esm/SortedSet.js.map +1 -1
- package/dist/esm/Stream.js +14 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/StreamHaltStrategy.js.map +1 -1
- package/dist/esm/String.js.map +1 -1
- package/dist/esm/Struct.js.map +1 -1
- package/dist/esm/Subscribable.js.map +1 -1
- package/dist/esm/SubscriptionRef.js.map +1 -1
- package/dist/esm/SynchronizedRef.js.map +1 -1
- package/dist/esm/TArray.js.map +1 -1
- package/dist/esm/TDeferred.js.map +1 -1
- package/dist/esm/TMap.js.map +1 -1
- package/dist/esm/TPriorityQueue.js.map +1 -1
- package/dist/esm/TPubSub.js.map +1 -1
- package/dist/esm/TQueue.js.map +1 -1
- package/dist/esm/TReentrantLock.js.map +1 -1
- package/dist/esm/TRef.js.map +1 -1
- package/dist/esm/TSemaphore.js.map +1 -1
- package/dist/esm/TSet.js.map +1 -1
- package/dist/esm/Take.js.map +1 -1
- package/dist/esm/TestAnnotationMap.js.map +1 -1
- package/dist/esm/TestClock.js.map +1 -1
- package/dist/esm/TestServices.js.map +1 -1
- package/dist/esm/Trie.js.map +1 -1
- package/dist/esm/Tuple.js.map +1 -1
- package/dist/esm/Unify.js.map +1 -1
- package/dist/esm/UpstreamPullRequest.js.map +1 -1
- package/dist/esm/UpstreamPullStrategy.js.map +1 -1
- package/dist/esm/Utils.js +1 -14
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/internal/core.js +1 -1
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/runtime.js +1 -1
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/stream.js +9 -0
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +2723 -36
- package/src/BigDecimal.ts +585 -18
- package/src/BigInt.ts +516 -16
- package/src/Boolean.ts +241 -8
- package/src/Cause.ts +177 -1
- package/src/Channel.ts +766 -49
- package/src/ChildExecutorDecision.ts +12 -0
- package/src/Chunk.ts +818 -4
- package/src/Config.ts +187 -8
- package/src/ConfigError.ts +16 -0
- package/src/ConfigProvider.ts +89 -1
- package/src/ConfigProviderPathPatch.ts +32 -0
- package/src/Console.ts +37 -8
- package/src/Context.ts +232 -0
- package/src/Cron.ts +12 -0
- package/src/Data.ts +165 -0
- package/src/DateTime.ts +1006 -50
- package/src/Deferred.ts +170 -0
- package/src/Differ.ts +89 -27
- package/src/Duration.ts +156 -16
- package/src/Effect.ts +4297 -123
- package/src/Either.ts +650 -34
- package/src/Equivalence.ts +24 -0
- package/src/ExecutionStrategy.ts +29 -10
- package/src/Exit.ts +252 -0
- package/src/Fiber.ts +182 -0
- package/src/FiberHandle.ts +42 -0
- package/src/FiberId.ts +24 -0
- package/src/FiberMap.ts +144 -21
- package/src/FiberRef.ts +80 -0
- package/src/FiberRefs.ts +84 -0
- package/src/FiberRefsPatch.ts +35 -1
- package/src/FiberSet.ts +38 -0
- package/src/Function.ts +416 -31
- package/src/GroupBy.ts +38 -0
- package/src/Hash.ts +8 -0
- package/src/HashMap.ts +300 -0
- package/src/HashSet.ts +284 -0
- package/src/Iterable.ts +456 -6
- package/src/KeyedPool.ts +34 -0
- package/src/Layer.ts +426 -30
- package/src/List.ts +476 -3
- package/src/LogLevel.ts +46 -0
- package/src/Logger.ts +195 -4
- package/src/Mailbox.ts +16 -0
- package/src/MergeDecision.ts +8 -0
- package/src/MergeState.ts +8 -0
- package/src/MergeStrategy.ts +25 -8
- package/src/Metric.ts +426 -15
- package/src/MetricHook.ts +24 -0
- package/src/MetricKey.ts +62 -8
- package/src/MetricPolling.ts +42 -6
- package/src/MetricState.ts +16 -0
- package/src/Micro.ts +1350 -102
- package/src/MutableHashMap.ts +105 -1
- package/src/MutableHashSet.ts +24 -0
- package/src/MutableList.ts +36 -0
- package/src/MutableQueue.ts +62 -0
- package/src/MutableRef.ts +56 -0
- package/src/Number.ts +500 -16
- package/src/Option.ts +1042 -16
- package/src/Order.ts +24 -0
- package/src/Ordering.ts +66 -0
- package/src/Pipeable.ts +224 -21
- package/src/Pool.ts +16 -0
- package/src/Predicate.ts +498 -0
- package/src/PubSub.ts +28 -0
- package/src/Queue.ts +104 -0
- package/src/RcMap.ts +70 -0
- package/src/Readable.ts +18 -7
- package/src/Record.ts +814 -40
- package/src/RedBlackTree.ts +305 -1
- package/src/Ref.ts +88 -0
- package/src/Request.ts +76 -0
- package/src/RequestResolver.ts +145 -4
- package/src/Runtime.ts +134 -2
- package/src/RuntimeFlags.ts +100 -0
- package/src/RuntimeFlagsPatch.ts +112 -0
- package/src/STM.ts +1107 -11
- package/src/Schedule.ts +704 -0
- package/src/ScheduleInterval.ts +68 -0
- package/src/ScheduleIntervals.ts +50 -0
- package/src/Scheduler.ts +2 -0
- package/src/Scope.ts +83 -15
- package/src/ScopedRef.ts +22 -0
- package/src/Sink.ts +464 -0
- package/src/SortedMap.ts +76 -0
- package/src/SortedSet.ts +143 -3
- package/src/Stream.ts +5041 -54
- package/src/StreamHaltStrategy.ts +29 -12
- package/src/String.ts +200 -0
- package/src/Struct.ts +86 -7
- package/src/Subscribable.ts +16 -0
- package/src/SubscriptionRef.ts +159 -11
- package/src/SynchronizedRef.ts +169 -8
- package/src/TArray.ts +431 -1
- package/src/TDeferred.ts +24 -0
- package/src/TMap.ts +381 -12
- package/src/TPriorityQueue.ts +60 -0
- package/src/TPubSub.ts +28 -0
- package/src/TQueue.ts +108 -0
- package/src/TReentrantLock.ts +36 -0
- package/src/TRef.ts +88 -0
- package/src/TSemaphore.ts +40 -0
- package/src/TSet.ts +280 -12
- package/src/Take.ts +56 -0
- package/src/TestAnnotationMap.ts +45 -1
- package/src/TestClock.ts +6 -0
- package/src/TestServices.ts +66 -0
- package/src/Trie.ts +906 -0
- package/src/Tuple.ts +157 -8
- package/src/Unify.ts +19 -3
- package/src/UpstreamPullRequest.ts +12 -0
- package/src/UpstreamPullStrategy.ts +12 -0
- package/src/Utils.ts +1 -15
- package/src/internal/core.ts +1 -1
- package/src/internal/runtime.ts +1 -1
- package/src/internal/stream.ts +27 -0
- package/src/internal/version.ts +1 -1
package/src/Array.ts
CHANGED
|
@@ -123,7 +123,33 @@ export const range = (start: number, end: number): NonEmptyArray<number> =>
|
|
|
123
123
|
* @since 2.0.0
|
|
124
124
|
*/
|
|
125
125
|
export const replicate: {
|
|
126
|
+
/**
|
|
127
|
+
* Return a `NonEmptyArray` containing a value repeated the specified number of times.
|
|
128
|
+
*
|
|
129
|
+
* **Note**. `n` is normalized to an integer >= 1.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* import { Array } from "effect"
|
|
133
|
+
*
|
|
134
|
+
* assert.deepStrictEqual(Array.replicate("a", 3), ["a", "a", "a"])
|
|
135
|
+
*
|
|
136
|
+
* @category constructors
|
|
137
|
+
* @since 2.0.0
|
|
138
|
+
*/
|
|
126
139
|
(n: number): <A>(a: A) => NonEmptyArray<A>
|
|
140
|
+
/**
|
|
141
|
+
* Return a `NonEmptyArray` containing a value repeated the specified number of times.
|
|
142
|
+
*
|
|
143
|
+
* **Note**. `n` is normalized to an integer >= 1.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* import { Array } from "effect"
|
|
147
|
+
*
|
|
148
|
+
* assert.deepStrictEqual(Array.replicate("a", 3), ["a", "a", "a"])
|
|
149
|
+
*
|
|
150
|
+
* @category constructors
|
|
151
|
+
* @since 2.0.0
|
|
152
|
+
*/
|
|
127
153
|
<A>(a: A, n: number): NonEmptyArray<A>
|
|
128
154
|
} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))
|
|
129
155
|
|
|
@@ -207,12 +233,44 @@ export const fromOption: <A>(self: Option<A>) => Array<A> = O.toArray
|
|
|
207
233
|
* @since 2.0.0
|
|
208
234
|
*/
|
|
209
235
|
export const match: {
|
|
236
|
+
/**
|
|
237
|
+
* Matches the elements of an array, applying functions to cases of empty and non-empty arrays.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* import { Array } from "effect"
|
|
241
|
+
*
|
|
242
|
+
* const match = Array.match({
|
|
243
|
+
* onEmpty: () => "empty",
|
|
244
|
+
* onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`
|
|
245
|
+
* })
|
|
246
|
+
* assert.deepStrictEqual(match([]), "empty")
|
|
247
|
+
* assert.deepStrictEqual(match([1, 2, 3]), "head: 1, tail: 2")
|
|
248
|
+
*
|
|
249
|
+
* @category pattern matching
|
|
250
|
+
* @since 2.0.0
|
|
251
|
+
*/
|
|
210
252
|
<B, A, C = B>(
|
|
211
253
|
options: {
|
|
212
254
|
readonly onEmpty: LazyArg<B>
|
|
213
255
|
readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C
|
|
214
256
|
}
|
|
215
257
|
): (self: ReadonlyArray<A>) => B | C
|
|
258
|
+
/**
|
|
259
|
+
* Matches the elements of an array, applying functions to cases of empty and non-empty arrays.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* import { Array } from "effect"
|
|
263
|
+
*
|
|
264
|
+
* const match = Array.match({
|
|
265
|
+
* onEmpty: () => "empty",
|
|
266
|
+
* onNonEmpty: ([head, ...tail]) => `head: ${head}, tail: ${tail.length}`
|
|
267
|
+
* })
|
|
268
|
+
* assert.deepStrictEqual(match([]), "empty")
|
|
269
|
+
* assert.deepStrictEqual(match([1, 2, 3]), "head: 1, tail: 2")
|
|
270
|
+
*
|
|
271
|
+
* @category pattern matching
|
|
272
|
+
* @since 2.0.0
|
|
273
|
+
*/
|
|
216
274
|
<A, B, C = B>(
|
|
217
275
|
self: ReadonlyArray<A>,
|
|
218
276
|
options: {
|
|
@@ -245,12 +303,44 @@ export const match: {
|
|
|
245
303
|
* @since 2.0.0
|
|
246
304
|
*/
|
|
247
305
|
export const matchLeft: {
|
|
306
|
+
/**
|
|
307
|
+
* Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* import { Array } from "effect"
|
|
311
|
+
*
|
|
312
|
+
* const matchLeft = Array.matchLeft({
|
|
313
|
+
* onEmpty: () => "empty",
|
|
314
|
+
* onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`
|
|
315
|
+
* })
|
|
316
|
+
* assert.deepStrictEqual(matchLeft([]), "empty")
|
|
317
|
+
* assert.deepStrictEqual(matchLeft([1, 2, 3]), "head: 1, tail: 2")
|
|
318
|
+
*
|
|
319
|
+
* @category pattern matching
|
|
320
|
+
* @since 2.0.0
|
|
321
|
+
*/
|
|
248
322
|
<B, A, C = B>(
|
|
249
323
|
options: {
|
|
250
324
|
readonly onEmpty: LazyArg<B>
|
|
251
325
|
readonly onNonEmpty: (head: A, tail: Array<A>) => C
|
|
252
326
|
}
|
|
253
327
|
): (self: ReadonlyArray<A>) => B | C
|
|
328
|
+
/**
|
|
329
|
+
* Matches the elements of an array from the left, applying functions to cases of empty and non-empty arrays.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* import { Array } from "effect"
|
|
333
|
+
*
|
|
334
|
+
* const matchLeft = Array.matchLeft({
|
|
335
|
+
* onEmpty: () => "empty",
|
|
336
|
+
* onNonEmpty: (head, tail) => `head: ${head}, tail: ${tail.length}`
|
|
337
|
+
* })
|
|
338
|
+
* assert.deepStrictEqual(matchLeft([]), "empty")
|
|
339
|
+
* assert.deepStrictEqual(matchLeft([1, 2, 3]), "head: 1, tail: 2")
|
|
340
|
+
*
|
|
341
|
+
* @category pattern matching
|
|
342
|
+
* @since 2.0.0
|
|
343
|
+
*/
|
|
254
344
|
<A, B, C = B>(
|
|
255
345
|
self: ReadonlyArray<A>,
|
|
256
346
|
options: {
|
|
@@ -283,12 +373,44 @@ export const matchLeft: {
|
|
|
283
373
|
* @since 2.0.0
|
|
284
374
|
*/
|
|
285
375
|
export const matchRight: {
|
|
376
|
+
/**
|
|
377
|
+
* Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* import { Array } from "effect"
|
|
381
|
+
*
|
|
382
|
+
* const matchRight = Array.matchRight({
|
|
383
|
+
* onEmpty: () => "empty",
|
|
384
|
+
* onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`
|
|
385
|
+
* })
|
|
386
|
+
* assert.deepStrictEqual(matchRight([]), "empty")
|
|
387
|
+
* assert.deepStrictEqual(matchRight([1, 2, 3]), "init: 2, last: 3")
|
|
388
|
+
*
|
|
389
|
+
* @category pattern matching
|
|
390
|
+
* @since 2.0.0
|
|
391
|
+
*/
|
|
286
392
|
<B, A, C = B>(
|
|
287
393
|
options: {
|
|
288
394
|
readonly onEmpty: LazyArg<B>
|
|
289
395
|
readonly onNonEmpty: (init: Array<A>, last: A) => C
|
|
290
396
|
}
|
|
291
397
|
): (self: ReadonlyArray<A>) => B | C
|
|
398
|
+
/**
|
|
399
|
+
* Matches the elements of an array from the right, applying functions to cases of empty and non-empty arrays.
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* import { Array } from "effect"
|
|
403
|
+
*
|
|
404
|
+
* const matchRight = Array.matchRight({
|
|
405
|
+
* onEmpty: () => "empty",
|
|
406
|
+
* onNonEmpty: (init, last) => `init: ${init.length}, last: ${last}`
|
|
407
|
+
* })
|
|
408
|
+
* assert.deepStrictEqual(matchRight([]), "empty")
|
|
409
|
+
* assert.deepStrictEqual(matchRight([1, 2, 3]), "init: 2, last: 3")
|
|
410
|
+
*
|
|
411
|
+
* @category pattern matching
|
|
412
|
+
* @since 2.0.0
|
|
413
|
+
*/
|
|
292
414
|
<A, B, C = B>(
|
|
293
415
|
self: ReadonlyArray<A>,
|
|
294
416
|
options: {
|
|
@@ -321,7 +443,33 @@ export const matchRight: {
|
|
|
321
443
|
* @since 2.0.0
|
|
322
444
|
*/
|
|
323
445
|
export const prepend: {
|
|
446
|
+
/**
|
|
447
|
+
* Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* import { Array } from "effect"
|
|
451
|
+
*
|
|
452
|
+
* const original = [2, 3, 4];
|
|
453
|
+
* const result = Array.prepend(original, 1);
|
|
454
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
455
|
+
*
|
|
456
|
+
* @category concatenating
|
|
457
|
+
* @since 2.0.0
|
|
458
|
+
*/
|
|
324
459
|
<B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>
|
|
460
|
+
/**
|
|
461
|
+
* Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* import { Array } from "effect"
|
|
465
|
+
*
|
|
466
|
+
* const original = [2, 3, 4];
|
|
467
|
+
* const result = Array.prepend(original, 1);
|
|
468
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
469
|
+
*
|
|
470
|
+
* @category concatenating
|
|
471
|
+
* @since 2.0.0
|
|
472
|
+
*/
|
|
325
473
|
<A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>
|
|
326
474
|
} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])
|
|
327
475
|
|
|
@@ -341,11 +489,71 @@ export const prepend: {
|
|
|
341
489
|
* @since 2.0.0
|
|
342
490
|
*/
|
|
343
491
|
export const prependAll: {
|
|
492
|
+
/**
|
|
493
|
+
* Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).
|
|
494
|
+
* If either array is non-empty, the result is also a non-empty array.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* import { Array } from "effect"
|
|
498
|
+
*
|
|
499
|
+
* const prefix = [0, 1];
|
|
500
|
+
* const array = [2, 3];
|
|
501
|
+
* const result = Array.prependAll(array, prefix);
|
|
502
|
+
* assert.deepStrictEqual(result, [0, 1, 2, 3]);
|
|
503
|
+
*
|
|
504
|
+
* @category concatenating
|
|
505
|
+
* @since 2.0.0
|
|
506
|
+
*/
|
|
344
507
|
<S extends Iterable<any>, T extends Iterable<any>>(
|
|
345
508
|
that: T
|
|
346
509
|
): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
|
|
510
|
+
/**
|
|
511
|
+
* Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).
|
|
512
|
+
* If either array is non-empty, the result is also a non-empty array.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* import { Array } from "effect"
|
|
516
|
+
*
|
|
517
|
+
* const prefix = [0, 1];
|
|
518
|
+
* const array = [2, 3];
|
|
519
|
+
* const result = Array.prependAll(array, prefix);
|
|
520
|
+
* assert.deepStrictEqual(result, [0, 1, 2, 3]);
|
|
521
|
+
*
|
|
522
|
+
* @category concatenating
|
|
523
|
+
* @since 2.0.0
|
|
524
|
+
*/
|
|
347
525
|
<A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>
|
|
526
|
+
/**
|
|
527
|
+
* Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).
|
|
528
|
+
* If either array is non-empty, the result is also a non-empty array.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* import { Array } from "effect"
|
|
532
|
+
*
|
|
533
|
+
* const prefix = [0, 1];
|
|
534
|
+
* const array = [2, 3];
|
|
535
|
+
* const result = Array.prependAll(array, prefix);
|
|
536
|
+
* assert.deepStrictEqual(result, [0, 1, 2, 3]);
|
|
537
|
+
*
|
|
538
|
+
* @category concatenating
|
|
539
|
+
* @since 2.0.0
|
|
540
|
+
*/
|
|
348
541
|
<A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>
|
|
542
|
+
/**
|
|
543
|
+
* Prepends the specified prefix array (or iterable) to the beginning of the specified array (or iterable).
|
|
544
|
+
* If either array is non-empty, the result is also a non-empty array.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* import { Array } from "effect"
|
|
548
|
+
*
|
|
549
|
+
* const prefix = [0, 1];
|
|
550
|
+
* const array = [2, 3];
|
|
551
|
+
* const result = Array.prependAll(array, prefix);
|
|
552
|
+
* assert.deepStrictEqual(result, [0, 1, 2, 3]);
|
|
553
|
+
*
|
|
554
|
+
* @category concatenating
|
|
555
|
+
* @since 2.0.0
|
|
556
|
+
*/
|
|
349
557
|
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>
|
|
350
558
|
} = dual(
|
|
351
559
|
2,
|
|
@@ -366,7 +574,33 @@ export const prependAll: {
|
|
|
366
574
|
* @since 2.0.0
|
|
367
575
|
*/
|
|
368
576
|
export const append: {
|
|
577
|
+
/**
|
|
578
|
+
* Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* import { Array } from "effect"
|
|
582
|
+
*
|
|
583
|
+
* const original = [1, 2, 3];
|
|
584
|
+
* const result = Array.append(original, 4);
|
|
585
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
586
|
+
*
|
|
587
|
+
* @category concatenating
|
|
588
|
+
* @since 2.0.0
|
|
589
|
+
*/
|
|
369
590
|
<B>(last: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>
|
|
591
|
+
/**
|
|
592
|
+
* Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* import { Array } from "effect"
|
|
596
|
+
*
|
|
597
|
+
* const original = [1, 2, 3];
|
|
598
|
+
* const result = Array.append(original, 4);
|
|
599
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 4]);
|
|
600
|
+
*
|
|
601
|
+
* @category concatenating
|
|
602
|
+
* @since 2.0.0
|
|
603
|
+
*/
|
|
370
604
|
<A, B>(self: Iterable<A>, last: B): NonEmptyArray<A | B>
|
|
371
605
|
} = dual(2, <A, B>(self: Iterable<A>, last: B): Array<A | B> => [...self, last])
|
|
372
606
|
|
|
@@ -378,11 +612,39 @@ export const append: {
|
|
|
378
612
|
* @since 2.0.0
|
|
379
613
|
*/
|
|
380
614
|
export const appendAll: {
|
|
615
|
+
/**
|
|
616
|
+
* Concatenates two arrays (or iterables), combining their elements.
|
|
617
|
+
* If either array is non-empty, the result is also a non-empty array.
|
|
618
|
+
*
|
|
619
|
+
* @category concatenating
|
|
620
|
+
* @since 2.0.0
|
|
621
|
+
*/
|
|
381
622
|
<S extends Iterable<any>, T extends Iterable<any>>(
|
|
382
623
|
that: T
|
|
383
624
|
): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
|
|
625
|
+
/**
|
|
626
|
+
* Concatenates two arrays (or iterables), combining their elements.
|
|
627
|
+
* If either array is non-empty, the result is also a non-empty array.
|
|
628
|
+
*
|
|
629
|
+
* @category concatenating
|
|
630
|
+
* @since 2.0.0
|
|
631
|
+
*/
|
|
384
632
|
<A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>
|
|
633
|
+
/**
|
|
634
|
+
* Concatenates two arrays (or iterables), combining their elements.
|
|
635
|
+
* If either array is non-empty, the result is also a non-empty array.
|
|
636
|
+
*
|
|
637
|
+
* @category concatenating
|
|
638
|
+
* @since 2.0.0
|
|
639
|
+
*/
|
|
385
640
|
<A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>
|
|
641
|
+
/**
|
|
642
|
+
* Concatenates two arrays (or iterables), combining their elements.
|
|
643
|
+
* If either array is non-empty, the result is also a non-empty array.
|
|
644
|
+
*
|
|
645
|
+
* @category concatenating
|
|
646
|
+
* @since 2.0.0
|
|
647
|
+
*/
|
|
386
648
|
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>
|
|
387
649
|
} = dual(
|
|
388
650
|
2,
|
|
@@ -411,7 +673,49 @@ export const appendAll: {
|
|
|
411
673
|
* @since 2.0.0
|
|
412
674
|
*/
|
|
413
675
|
export const scan: {
|
|
676
|
+
/**
|
|
677
|
+
* Accumulates values from an `Iterable` starting from the left, storing
|
|
678
|
+
* each intermediate result in an array. Useful for tracking the progression of
|
|
679
|
+
* a value through a series of transformations.
|
|
680
|
+
*
|
|
681
|
+
* @example
|
|
682
|
+
* import { Array } from "effect";
|
|
683
|
+
*
|
|
684
|
+
* const numbers = [1, 2, 3, 4]
|
|
685
|
+
* const result = Array.scan(numbers, 0, (acc, value) => acc + value)
|
|
686
|
+
* assert.deepStrictEqual(result, [0, 1, 3, 6, 10])
|
|
687
|
+
*
|
|
688
|
+
* // Explanation:
|
|
689
|
+
* // This function starts with the initial value (0 in this case)
|
|
690
|
+
* // and adds each element of the array to this accumulator one by one,
|
|
691
|
+
* // keeping track of the cumulative sum after each addition.
|
|
692
|
+
* // Each of these sums is captured in the resulting array.
|
|
693
|
+
*
|
|
694
|
+
* @category folding
|
|
695
|
+
* @since 2.0.0
|
|
696
|
+
*/
|
|
414
697
|
<B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>
|
|
698
|
+
/**
|
|
699
|
+
* Accumulates values from an `Iterable` starting from the left, storing
|
|
700
|
+
* each intermediate result in an array. Useful for tracking the progression of
|
|
701
|
+
* a value through a series of transformations.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* import { Array } from "effect";
|
|
705
|
+
*
|
|
706
|
+
* const numbers = [1, 2, 3, 4]
|
|
707
|
+
* const result = Array.scan(numbers, 0, (acc, value) => acc + value)
|
|
708
|
+
* assert.deepStrictEqual(result, [0, 1, 3, 6, 10])
|
|
709
|
+
*
|
|
710
|
+
* // Explanation:
|
|
711
|
+
* // This function starts with the initial value (0 in this case)
|
|
712
|
+
* // and adds each element of the array to this accumulator one by one,
|
|
713
|
+
* // keeping track of the cumulative sum after each addition.
|
|
714
|
+
* // Each of these sums is captured in the resulting array.
|
|
715
|
+
*
|
|
716
|
+
* @category folding
|
|
717
|
+
* @since 2.0.0
|
|
718
|
+
*/
|
|
415
719
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>
|
|
416
720
|
} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {
|
|
417
721
|
const out: NonEmptyArray<B> = [b]
|
|
@@ -439,7 +743,37 @@ export const scan: {
|
|
|
439
743
|
* @since 2.0.0
|
|
440
744
|
*/
|
|
441
745
|
export const scanRight: {
|
|
746
|
+
/**
|
|
747
|
+
* Accumulates values from an `Iterable` starting from the right, storing
|
|
748
|
+
* each intermediate result in an array. Useful for tracking the progression of
|
|
749
|
+
* a value through a series of transformations.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* import { Array } from "effect";
|
|
753
|
+
*
|
|
754
|
+
* const numbers = [1, 2, 3, 4]
|
|
755
|
+
* const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)
|
|
756
|
+
* assert.deepStrictEqual(result, [10, 9, 7, 4, 0])
|
|
757
|
+
*
|
|
758
|
+
* @category folding
|
|
759
|
+
* @since 2.0.0
|
|
760
|
+
*/
|
|
442
761
|
<B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>
|
|
762
|
+
/**
|
|
763
|
+
* Accumulates values from an `Iterable` starting from the right, storing
|
|
764
|
+
* each intermediate result in an array. Useful for tracking the progression of
|
|
765
|
+
* a value through a series of transformations.
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* import { Array } from "effect";
|
|
769
|
+
*
|
|
770
|
+
* const numbers = [1, 2, 3, 4]
|
|
771
|
+
* const result = Array.scanRight(numbers, 0, (acc, value) => acc + value)
|
|
772
|
+
* assert.deepStrictEqual(result, [10, 9, 7, 4, 0])
|
|
773
|
+
*
|
|
774
|
+
* @category folding
|
|
775
|
+
* @since 2.0.0
|
|
776
|
+
*/
|
|
443
777
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>
|
|
444
778
|
} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {
|
|
445
779
|
const input = fromIterable(self)
|
|
@@ -466,7 +800,35 @@ export const scanRight: {
|
|
|
466
800
|
* @since 2.0.0
|
|
467
801
|
*/
|
|
468
802
|
export const isArray: {
|
|
803
|
+
/**
|
|
804
|
+
* Determine if `unknown` is an Array.
|
|
805
|
+
*
|
|
806
|
+
* @param self - The value to check.
|
|
807
|
+
*
|
|
808
|
+
* @example
|
|
809
|
+
* import { isArray } from "effect/Array"
|
|
810
|
+
*
|
|
811
|
+
* assert.deepStrictEqual(isArray(null), false);
|
|
812
|
+
* assert.deepStrictEqual(isArray([1, 2, 3]), true);
|
|
813
|
+
*
|
|
814
|
+
* @category guards
|
|
815
|
+
* @since 2.0.0
|
|
816
|
+
*/
|
|
469
817
|
(self: unknown): self is Array<unknown>
|
|
818
|
+
/**
|
|
819
|
+
* Determine if `unknown` is an Array.
|
|
820
|
+
*
|
|
821
|
+
* @param self - The value to check.
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* import { isArray } from "effect/Array"
|
|
825
|
+
*
|
|
826
|
+
* assert.deepStrictEqual(isArray(null), false);
|
|
827
|
+
* assert.deepStrictEqual(isArray([1, 2, 3]), true);
|
|
828
|
+
*
|
|
829
|
+
* @category guards
|
|
830
|
+
* @since 2.0.0
|
|
831
|
+
*/
|
|
470
832
|
<T>(self: T): self is Extract<T, ReadonlyArray<any>>
|
|
471
833
|
} = Array.isArray
|
|
472
834
|
|
|
@@ -558,7 +920,19 @@ const clamp = <A>(i: number, as: ReadonlyArray<A>): number => Math.floor(Math.mi
|
|
|
558
920
|
* @since 2.0.0
|
|
559
921
|
*/
|
|
560
922
|
export const get: {
|
|
923
|
+
/**
|
|
924
|
+
* This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.
|
|
925
|
+
*
|
|
926
|
+
* @category getters
|
|
927
|
+
* @since 2.0.0
|
|
928
|
+
*/
|
|
561
929
|
(index: number): <A>(self: ReadonlyArray<A>) => Option<A>
|
|
930
|
+
/**
|
|
931
|
+
* This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.
|
|
932
|
+
*
|
|
933
|
+
* @category getters
|
|
934
|
+
* @since 2.0.0
|
|
935
|
+
*/
|
|
562
936
|
<A>(self: ReadonlyArray<A>, index: number): Option<A>
|
|
563
937
|
} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option<A> => {
|
|
564
938
|
const i = Math.floor(index)
|
|
@@ -572,7 +946,19 @@ export const get: {
|
|
|
572
946
|
* @category unsafe
|
|
573
947
|
*/
|
|
574
948
|
export const unsafeGet: {
|
|
949
|
+
/**
|
|
950
|
+
* Gets an element unsafely, will throw on out of bounds.
|
|
951
|
+
*
|
|
952
|
+
* @since 2.0.0
|
|
953
|
+
* @category unsafe
|
|
954
|
+
*/
|
|
575
955
|
(index: number): <A>(self: ReadonlyArray<A>) => A
|
|
956
|
+
/**
|
|
957
|
+
* Gets an element unsafely, will throw on out of bounds.
|
|
958
|
+
*
|
|
959
|
+
* @since 2.0.0
|
|
960
|
+
* @category unsafe
|
|
961
|
+
*/
|
|
576
962
|
<A>(self: ReadonlyArray<A>, index: number): A
|
|
577
963
|
} = dual(2, <A>(self: ReadonlyArray<A>, index: number): A => {
|
|
578
964
|
const i = Math.floor(index)
|
|
@@ -725,7 +1111,37 @@ export const initNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => sel
|
|
|
725
1111
|
* @since 2.0.0
|
|
726
1112
|
*/
|
|
727
1113
|
export const take: {
|
|
1114
|
+
/**
|
|
1115
|
+
* Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.
|
|
1116
|
+
*
|
|
1117
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
1118
|
+
*
|
|
1119
|
+
* @example
|
|
1120
|
+
* import { Array } from "effect"
|
|
1121
|
+
*
|
|
1122
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1123
|
+
* const result = Array.take(numbers, 3)
|
|
1124
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
1125
|
+
*
|
|
1126
|
+
* @category getters
|
|
1127
|
+
* @since 2.0.0
|
|
1128
|
+
*/
|
|
728
1129
|
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
1130
|
+
/**
|
|
1131
|
+
* Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.
|
|
1132
|
+
*
|
|
1133
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
1134
|
+
*
|
|
1135
|
+
* @example
|
|
1136
|
+
* import { Array } from "effect"
|
|
1137
|
+
*
|
|
1138
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1139
|
+
* const result = Array.take(numbers, 3)
|
|
1140
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
1141
|
+
*
|
|
1142
|
+
* @category getters
|
|
1143
|
+
* @since 2.0.0
|
|
1144
|
+
*/
|
|
729
1145
|
<A>(self: Iterable<A>, n: number): Array<A>
|
|
730
1146
|
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
731
1147
|
const input = fromIterable(self)
|
|
@@ -748,7 +1164,37 @@ export const take: {
|
|
|
748
1164
|
* @since 2.0.0
|
|
749
1165
|
*/
|
|
750
1166
|
export const takeRight: {
|
|
1167
|
+
/**
|
|
1168
|
+
* Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.
|
|
1169
|
+
*
|
|
1170
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
1171
|
+
*
|
|
1172
|
+
* @example
|
|
1173
|
+
* import { Array } from "effect"
|
|
1174
|
+
*
|
|
1175
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1176
|
+
* const result = Array.takeRight(numbers, 3)
|
|
1177
|
+
* assert.deepStrictEqual(result, [3, 4, 5])
|
|
1178
|
+
*
|
|
1179
|
+
* @category getters
|
|
1180
|
+
* @since 2.0.0
|
|
1181
|
+
*/
|
|
751
1182
|
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
1183
|
+
/**
|
|
1184
|
+
* Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.
|
|
1185
|
+
*
|
|
1186
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* import { Array } from "effect"
|
|
1190
|
+
*
|
|
1191
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1192
|
+
* const result = Array.takeRight(numbers, 3)
|
|
1193
|
+
* assert.deepStrictEqual(result, [3, 4, 5])
|
|
1194
|
+
*
|
|
1195
|
+
* @category getters
|
|
1196
|
+
* @since 2.0.0
|
|
1197
|
+
*/
|
|
752
1198
|
<A>(self: Iterable<A>, n: number): Array<A>
|
|
753
1199
|
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
754
1200
|
const input = fromIterable(self)
|
|
@@ -776,9 +1222,85 @@ export const takeRight: {
|
|
|
776
1222
|
* @since 2.0.0
|
|
777
1223
|
*/
|
|
778
1224
|
export const takeWhile: {
|
|
1225
|
+
/**
|
|
1226
|
+
* Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
1227
|
+
*
|
|
1228
|
+
* @example
|
|
1229
|
+
* import { Array } from "effect"
|
|
1230
|
+
*
|
|
1231
|
+
* const numbers = [1, 3, 2, 4, 1, 2]
|
|
1232
|
+
* const result = Array.takeWhile(numbers, x => x < 4)
|
|
1233
|
+
* assert.deepStrictEqual(result, [1, 3, 2])
|
|
1234
|
+
*
|
|
1235
|
+
* // Explanation:
|
|
1236
|
+
* // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.
|
|
1237
|
+
* // - The next element (`3`) is also less than `4`, so it adds `3`.
|
|
1238
|
+
* // - The next element (`2`) is again less than `4`, so it adds `2`.
|
|
1239
|
+
* // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.
|
|
1240
|
+
*
|
|
1241
|
+
* @category getters
|
|
1242
|
+
* @since 2.0.0
|
|
1243
|
+
*/
|
|
779
1244
|
<A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>
|
|
1245
|
+
/**
|
|
1246
|
+
* Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
1247
|
+
*
|
|
1248
|
+
* @example
|
|
1249
|
+
* import { Array } from "effect"
|
|
1250
|
+
*
|
|
1251
|
+
* const numbers = [1, 3, 2, 4, 1, 2]
|
|
1252
|
+
* const result = Array.takeWhile(numbers, x => x < 4)
|
|
1253
|
+
* assert.deepStrictEqual(result, [1, 3, 2])
|
|
1254
|
+
*
|
|
1255
|
+
* // Explanation:
|
|
1256
|
+
* // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.
|
|
1257
|
+
* // - The next element (`3`) is also less than `4`, so it adds `3`.
|
|
1258
|
+
* // - The next element (`2`) is again less than `4`, so it adds `2`.
|
|
1259
|
+
* // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.
|
|
1260
|
+
*
|
|
1261
|
+
* @category getters
|
|
1262
|
+
* @since 2.0.0
|
|
1263
|
+
*/
|
|
780
1264
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>
|
|
1265
|
+
/**
|
|
1266
|
+
* Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* import { Array } from "effect"
|
|
1270
|
+
*
|
|
1271
|
+
* const numbers = [1, 3, 2, 4, 1, 2]
|
|
1272
|
+
* const result = Array.takeWhile(numbers, x => x < 4)
|
|
1273
|
+
* assert.deepStrictEqual(result, [1, 3, 2])
|
|
1274
|
+
*
|
|
1275
|
+
* // Explanation:
|
|
1276
|
+
* // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.
|
|
1277
|
+
* // - The next element (`3`) is also less than `4`, so it adds `3`.
|
|
1278
|
+
* // - The next element (`2`) is again less than `4`, so it adds `2`.
|
|
1279
|
+
* // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.
|
|
1280
|
+
*
|
|
1281
|
+
* @category getters
|
|
1282
|
+
* @since 2.0.0
|
|
1283
|
+
*/
|
|
781
1284
|
<A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>
|
|
1285
|
+
/**
|
|
1286
|
+
* Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
1287
|
+
*
|
|
1288
|
+
* @example
|
|
1289
|
+
* import { Array } from "effect"
|
|
1290
|
+
*
|
|
1291
|
+
* const numbers = [1, 3, 2, 4, 1, 2]
|
|
1292
|
+
* const result = Array.takeWhile(numbers, x => x < 4)
|
|
1293
|
+
* assert.deepStrictEqual(result, [1, 3, 2])
|
|
1294
|
+
*
|
|
1295
|
+
* // Explanation:
|
|
1296
|
+
* // - The function starts with the first element (`1`), which is less than `4`, so it adds `1` to the result.
|
|
1297
|
+
* // - The next element (`3`) is also less than `4`, so it adds `3`.
|
|
1298
|
+
* // - The next element (`2`) is again less than `4`, so it adds `2`.
|
|
1299
|
+
* // - The function then encounters `4`, which is not less than `4`. At this point, it stops checking further elements and finalizes the result.
|
|
1300
|
+
*
|
|
1301
|
+
* @category getters
|
|
1302
|
+
* @since 2.0.0
|
|
1303
|
+
*/
|
|
782
1304
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>
|
|
783
1305
|
} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A> => {
|
|
784
1306
|
let i = 0
|
|
@@ -814,14 +1336,50 @@ const spanIndex = <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean
|
|
|
814
1336
|
* @since 2.0.0
|
|
815
1337
|
*/
|
|
816
1338
|
export const span: {
|
|
1339
|
+
/**
|
|
1340
|
+
* Split an `Iterable` into two parts:
|
|
1341
|
+
*
|
|
1342
|
+
* 1. the longest initial subarray for which all elements satisfy the specified predicate
|
|
1343
|
+
* 2. the remaining elements
|
|
1344
|
+
*
|
|
1345
|
+
* @category splitting
|
|
1346
|
+
* @since 2.0.0
|
|
1347
|
+
*/
|
|
817
1348
|
<A, B extends A>(
|
|
818
1349
|
refinement: (a: NoInfer<A>, i: number) => a is B
|
|
819
1350
|
): (self: Iterable<A>) => [init: Array<B>, rest: Array<Exclude<A, B>>]
|
|
1351
|
+
/**
|
|
1352
|
+
* Split an `Iterable` into two parts:
|
|
1353
|
+
*
|
|
1354
|
+
* 1. the longest initial subarray for which all elements satisfy the specified predicate
|
|
1355
|
+
* 2. the remaining elements
|
|
1356
|
+
*
|
|
1357
|
+
* @category splitting
|
|
1358
|
+
* @since 2.0.0
|
|
1359
|
+
*/
|
|
820
1360
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => [init: Array<A>, rest: Array<A>]
|
|
1361
|
+
/**
|
|
1362
|
+
* Split an `Iterable` into two parts:
|
|
1363
|
+
*
|
|
1364
|
+
* 1. the longest initial subarray for which all elements satisfy the specified predicate
|
|
1365
|
+
* 2. the remaining elements
|
|
1366
|
+
*
|
|
1367
|
+
* @category splitting
|
|
1368
|
+
* @since 2.0.0
|
|
1369
|
+
*/
|
|
821
1370
|
<A, B extends A>(
|
|
822
1371
|
self: Iterable<A>,
|
|
823
1372
|
refinement: (a: A, i: number) => a is B
|
|
824
1373
|
): [init: Array<B>, rest: Array<Exclude<A, B>>]
|
|
1374
|
+
/**
|
|
1375
|
+
* Split an `Iterable` into two parts:
|
|
1376
|
+
*
|
|
1377
|
+
* 1. the longest initial subarray for which all elements satisfy the specified predicate
|
|
1378
|
+
* 2. the remaining elements
|
|
1379
|
+
*
|
|
1380
|
+
* @category splitting
|
|
1381
|
+
* @since 2.0.0
|
|
1382
|
+
*/
|
|
825
1383
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [init: Array<A>, rest: Array<A>]
|
|
826
1384
|
} = dual(
|
|
827
1385
|
2,
|
|
@@ -845,7 +1403,37 @@ export const span: {
|
|
|
845
1403
|
* @since 2.0.0
|
|
846
1404
|
*/
|
|
847
1405
|
export const drop: {
|
|
1406
|
+
/**
|
|
1407
|
+
* Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.
|
|
1408
|
+
*
|
|
1409
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
1410
|
+
*
|
|
1411
|
+
* @example
|
|
1412
|
+
* import { Array } from "effect"
|
|
1413
|
+
*
|
|
1414
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1415
|
+
* const result = Array.drop(numbers, 2)
|
|
1416
|
+
* assert.deepStrictEqual(result, [3, 4, 5])
|
|
1417
|
+
*
|
|
1418
|
+
* @category getters
|
|
1419
|
+
* @since 2.0.0
|
|
1420
|
+
*/
|
|
848
1421
|
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
1422
|
+
/**
|
|
1423
|
+
* Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.
|
|
1424
|
+
*
|
|
1425
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
1426
|
+
*
|
|
1427
|
+
* @example
|
|
1428
|
+
* import { Array } from "effect"
|
|
1429
|
+
*
|
|
1430
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1431
|
+
* const result = Array.drop(numbers, 2)
|
|
1432
|
+
* assert.deepStrictEqual(result, [3, 4, 5])
|
|
1433
|
+
*
|
|
1434
|
+
* @category getters
|
|
1435
|
+
* @since 2.0.0
|
|
1436
|
+
*/
|
|
849
1437
|
<A>(self: Iterable<A>, n: number): Array<A>
|
|
850
1438
|
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
851
1439
|
const input = fromIterable(self)
|
|
@@ -868,7 +1456,37 @@ export const drop: {
|
|
|
868
1456
|
* @since 2.0.0
|
|
869
1457
|
*/
|
|
870
1458
|
export const dropRight: {
|
|
1459
|
+
/**
|
|
1460
|
+
* Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.
|
|
1461
|
+
*
|
|
1462
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* import { Array } from "effect"
|
|
1466
|
+
*
|
|
1467
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1468
|
+
* const result = Array.dropRight(numbers, 2)
|
|
1469
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
1470
|
+
*
|
|
1471
|
+
* @category getters
|
|
1472
|
+
* @since 2.0.0
|
|
1473
|
+
*/
|
|
871
1474
|
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
1475
|
+
/**
|
|
1476
|
+
* Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.
|
|
1477
|
+
*
|
|
1478
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
1479
|
+
*
|
|
1480
|
+
* @example
|
|
1481
|
+
* import { Array } from "effect"
|
|
1482
|
+
*
|
|
1483
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1484
|
+
* const result = Array.dropRight(numbers, 2)
|
|
1485
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
1486
|
+
*
|
|
1487
|
+
* @category getters
|
|
1488
|
+
* @since 2.0.0
|
|
1489
|
+
*/
|
|
872
1490
|
<A>(self: Iterable<A>, n: number): Array<A>
|
|
873
1491
|
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
874
1492
|
const input = fromIterable(self)
|
|
@@ -889,7 +1507,33 @@ export const dropRight: {
|
|
|
889
1507
|
* @since 2.0.0
|
|
890
1508
|
*/
|
|
891
1509
|
export const dropWhile: {
|
|
1510
|
+
/**
|
|
1511
|
+
* Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
1512
|
+
*
|
|
1513
|
+
* @example
|
|
1514
|
+
* import { Array } from "effect"
|
|
1515
|
+
*
|
|
1516
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1517
|
+
* const result = Array.dropWhile(numbers, x => x < 4)
|
|
1518
|
+
* assert.deepStrictEqual(result, [4, 5])
|
|
1519
|
+
*
|
|
1520
|
+
* @category getters
|
|
1521
|
+
* @since 2.0.0
|
|
1522
|
+
*/
|
|
892
1523
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>
|
|
1524
|
+
/**
|
|
1525
|
+
* Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
1526
|
+
*
|
|
1527
|
+
* @example
|
|
1528
|
+
* import { Array } from "effect"
|
|
1529
|
+
*
|
|
1530
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1531
|
+
* const result = Array.dropWhile(numbers, x => x < 4)
|
|
1532
|
+
* assert.deepStrictEqual(result, [4, 5])
|
|
1533
|
+
*
|
|
1534
|
+
* @category getters
|
|
1535
|
+
* @since 2.0.0
|
|
1536
|
+
*/
|
|
893
1537
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>
|
|
894
1538
|
} = dual(
|
|
895
1539
|
2,
|
|
@@ -911,7 +1555,33 @@ export const dropWhile: {
|
|
|
911
1555
|
* @since 2.0.0
|
|
912
1556
|
*/
|
|
913
1557
|
export const findFirstIndex: {
|
|
1558
|
+
/**
|
|
1559
|
+
* Return the first index for which a predicate holds.
|
|
1560
|
+
*
|
|
1561
|
+
* @example
|
|
1562
|
+
* import { Array, Option } from "effect"
|
|
1563
|
+
*
|
|
1564
|
+
* const numbers = [5, 3, 8, 9]
|
|
1565
|
+
* const result = Array.findFirstIndex(numbers, x => x > 5)
|
|
1566
|
+
* assert.deepStrictEqual(result, Option.some(2))
|
|
1567
|
+
*
|
|
1568
|
+
* @category elements
|
|
1569
|
+
* @since 2.0.0
|
|
1570
|
+
*/
|
|
914
1571
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>
|
|
1572
|
+
/**
|
|
1573
|
+
* Return the first index for which a predicate holds.
|
|
1574
|
+
*
|
|
1575
|
+
* @example
|
|
1576
|
+
* import { Array, Option } from "effect"
|
|
1577
|
+
*
|
|
1578
|
+
* const numbers = [5, 3, 8, 9]
|
|
1579
|
+
* const result = Array.findFirstIndex(numbers, x => x > 5)
|
|
1580
|
+
* assert.deepStrictEqual(result, Option.some(2))
|
|
1581
|
+
*
|
|
1582
|
+
* @category elements
|
|
1583
|
+
* @since 2.0.0
|
|
1584
|
+
*/
|
|
915
1585
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>
|
|
916
1586
|
} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {
|
|
917
1587
|
let i = 0
|
|
@@ -938,7 +1608,33 @@ export const findFirstIndex: {
|
|
|
938
1608
|
* @since 2.0.0
|
|
939
1609
|
*/
|
|
940
1610
|
export const findLastIndex: {
|
|
1611
|
+
/**
|
|
1612
|
+
* Return the last index for which a predicate holds.
|
|
1613
|
+
*
|
|
1614
|
+
* @example
|
|
1615
|
+
* import { Array, Option } from "effect"
|
|
1616
|
+
*
|
|
1617
|
+
* const numbers = [1, 3, 8, 9]
|
|
1618
|
+
* const result = Array.findLastIndex(numbers, x => x < 5)
|
|
1619
|
+
* assert.deepStrictEqual(result, Option.some(1))
|
|
1620
|
+
*
|
|
1621
|
+
* @category elements
|
|
1622
|
+
* @since 2.0.0
|
|
1623
|
+
*/
|
|
941
1624
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<number>
|
|
1625
|
+
/**
|
|
1626
|
+
* Return the last index for which a predicate holds.
|
|
1627
|
+
*
|
|
1628
|
+
* @example
|
|
1629
|
+
* import { Array, Option } from "effect"
|
|
1630
|
+
*
|
|
1631
|
+
* const numbers = [1, 3, 8, 9]
|
|
1632
|
+
* const result = Array.findLastIndex(numbers, x => x < 5)
|
|
1633
|
+
* assert.deepStrictEqual(result, Option.some(1))
|
|
1634
|
+
*
|
|
1635
|
+
* @category elements
|
|
1636
|
+
* @since 2.0.0
|
|
1637
|
+
*/
|
|
942
1638
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number>
|
|
943
1639
|
} = dual(2, <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<number> => {
|
|
944
1640
|
const input = fromIterable(self)
|
|
@@ -965,11 +1661,95 @@ export const findLastIndex: {
|
|
|
965
1661
|
* @since 2.0.0
|
|
966
1662
|
*/
|
|
967
1663
|
export const findFirst: {
|
|
1664
|
+
/**
|
|
1665
|
+
* Returns the first element that satisfies the specified
|
|
1666
|
+
* predicate, or `None` if no such element exists.
|
|
1667
|
+
*
|
|
1668
|
+
* @example
|
|
1669
|
+
* import { Array, Option } from "effect"
|
|
1670
|
+
*
|
|
1671
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1672
|
+
* const result = Array.findFirst(numbers, x => x > 3)
|
|
1673
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1674
|
+
*
|
|
1675
|
+
* @category elements
|
|
1676
|
+
* @since 2.0.0
|
|
1677
|
+
*/
|
|
968
1678
|
<A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>
|
|
1679
|
+
/**
|
|
1680
|
+
* Returns the first element that satisfies the specified
|
|
1681
|
+
* predicate, or `None` if no such element exists.
|
|
1682
|
+
*
|
|
1683
|
+
* @example
|
|
1684
|
+
* import { Array, Option } from "effect"
|
|
1685
|
+
*
|
|
1686
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1687
|
+
* const result = Array.findFirst(numbers, x => x > 3)
|
|
1688
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1689
|
+
*
|
|
1690
|
+
* @category elements
|
|
1691
|
+
* @since 2.0.0
|
|
1692
|
+
*/
|
|
969
1693
|
<A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>
|
|
1694
|
+
/**
|
|
1695
|
+
* Returns the first element that satisfies the specified
|
|
1696
|
+
* predicate, or `None` if no such element exists.
|
|
1697
|
+
*
|
|
1698
|
+
* @example
|
|
1699
|
+
* import { Array, Option } from "effect"
|
|
1700
|
+
*
|
|
1701
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1702
|
+
* const result = Array.findFirst(numbers, x => x > 3)
|
|
1703
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1704
|
+
*
|
|
1705
|
+
* @category elements
|
|
1706
|
+
* @since 2.0.0
|
|
1707
|
+
*/
|
|
970
1708
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>
|
|
1709
|
+
/**
|
|
1710
|
+
* Returns the first element that satisfies the specified
|
|
1711
|
+
* predicate, or `None` if no such element exists.
|
|
1712
|
+
*
|
|
1713
|
+
* @example
|
|
1714
|
+
* import { Array, Option } from "effect"
|
|
1715
|
+
*
|
|
1716
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1717
|
+
* const result = Array.findFirst(numbers, x => x > 3)
|
|
1718
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1719
|
+
*
|
|
1720
|
+
* @category elements
|
|
1721
|
+
* @since 2.0.0
|
|
1722
|
+
*/
|
|
971
1723
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>
|
|
1724
|
+
/**
|
|
1725
|
+
* Returns the first element that satisfies the specified
|
|
1726
|
+
* predicate, or `None` if no such element exists.
|
|
1727
|
+
*
|
|
1728
|
+
* @example
|
|
1729
|
+
* import { Array, Option } from "effect"
|
|
1730
|
+
*
|
|
1731
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1732
|
+
* const result = Array.findFirst(numbers, x => x > 3)
|
|
1733
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1734
|
+
*
|
|
1735
|
+
* @category elements
|
|
1736
|
+
* @since 2.0.0
|
|
1737
|
+
*/
|
|
972
1738
|
<A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>
|
|
1739
|
+
/**
|
|
1740
|
+
* Returns the first element that satisfies the specified
|
|
1741
|
+
* predicate, or `None` if no such element exists.
|
|
1742
|
+
*
|
|
1743
|
+
* @example
|
|
1744
|
+
* import { Array, Option } from "effect"
|
|
1745
|
+
*
|
|
1746
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1747
|
+
* const result = Array.findFirst(numbers, x => x > 3)
|
|
1748
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1749
|
+
*
|
|
1750
|
+
* @category elements
|
|
1751
|
+
* @since 2.0.0
|
|
1752
|
+
*/
|
|
973
1753
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>
|
|
974
1754
|
} = EffectIterable.findFirst
|
|
975
1755
|
|
|
@@ -988,11 +1768,95 @@ export const findFirst: {
|
|
|
988
1768
|
* @since 2.0.0
|
|
989
1769
|
*/
|
|
990
1770
|
export const findLast: {
|
|
1771
|
+
/**
|
|
1772
|
+
* Finds the last element in an iterable collection that satisfies the given predicate or refinement.
|
|
1773
|
+
* Returns an `Option` containing the found element, or `Option.none` if no element matches.
|
|
1774
|
+
*
|
|
1775
|
+
* @example
|
|
1776
|
+
* import { Array, Option } from "effect"
|
|
1777
|
+
*
|
|
1778
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1779
|
+
* const result = Array.findLast(numbers, n => n % 2 === 0)
|
|
1780
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1781
|
+
*
|
|
1782
|
+
* @category elements
|
|
1783
|
+
* @since 2.0.0
|
|
1784
|
+
*/
|
|
991
1785
|
<A, B>(f: (a: NoInfer<A>, i: number) => Option<B>): (self: Iterable<A>) => Option<B>
|
|
1786
|
+
/**
|
|
1787
|
+
* Finds the last element in an iterable collection that satisfies the given predicate or refinement.
|
|
1788
|
+
* Returns an `Option` containing the found element, or `Option.none` if no element matches.
|
|
1789
|
+
*
|
|
1790
|
+
* @example
|
|
1791
|
+
* import { Array, Option } from "effect"
|
|
1792
|
+
*
|
|
1793
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1794
|
+
* const result = Array.findLast(numbers, n => n % 2 === 0)
|
|
1795
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1796
|
+
*
|
|
1797
|
+
* @category elements
|
|
1798
|
+
* @since 2.0.0
|
|
1799
|
+
*/
|
|
992
1800
|
<A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Option<B>
|
|
1801
|
+
/**
|
|
1802
|
+
* Finds the last element in an iterable collection that satisfies the given predicate or refinement.
|
|
1803
|
+
* Returns an `Option` containing the found element, or `Option.none` if no element matches.
|
|
1804
|
+
*
|
|
1805
|
+
* @example
|
|
1806
|
+
* import { Array, Option } from "effect"
|
|
1807
|
+
*
|
|
1808
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1809
|
+
* const result = Array.findLast(numbers, n => n % 2 === 0)
|
|
1810
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1811
|
+
*
|
|
1812
|
+
* @category elements
|
|
1813
|
+
* @since 2.0.0
|
|
1814
|
+
*/
|
|
993
1815
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Option<A>
|
|
1816
|
+
/**
|
|
1817
|
+
* Finds the last element in an iterable collection that satisfies the given predicate or refinement.
|
|
1818
|
+
* Returns an `Option` containing the found element, or `Option.none` if no element matches.
|
|
1819
|
+
*
|
|
1820
|
+
* @example
|
|
1821
|
+
* import { Array, Option } from "effect"
|
|
1822
|
+
*
|
|
1823
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1824
|
+
* const result = Array.findLast(numbers, n => n % 2 === 0)
|
|
1825
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1826
|
+
*
|
|
1827
|
+
* @category elements
|
|
1828
|
+
* @since 2.0.0
|
|
1829
|
+
*/
|
|
994
1830
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Option<B>
|
|
1831
|
+
/**
|
|
1832
|
+
* Finds the last element in an iterable collection that satisfies the given predicate or refinement.
|
|
1833
|
+
* Returns an `Option` containing the found element, or `Option.none` if no element matches.
|
|
1834
|
+
*
|
|
1835
|
+
* @example
|
|
1836
|
+
* import { Array, Option } from "effect"
|
|
1837
|
+
*
|
|
1838
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1839
|
+
* const result = Array.findLast(numbers, n => n % 2 === 0)
|
|
1840
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1841
|
+
*
|
|
1842
|
+
* @category elements
|
|
1843
|
+
* @since 2.0.0
|
|
1844
|
+
*/
|
|
995
1845
|
<A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Option<B>
|
|
1846
|
+
/**
|
|
1847
|
+
* Finds the last element in an iterable collection that satisfies the given predicate or refinement.
|
|
1848
|
+
* Returns an `Option` containing the found element, or `Option.none` if no element matches.
|
|
1849
|
+
*
|
|
1850
|
+
* @example
|
|
1851
|
+
* import { Array, Option } from "effect"
|
|
1852
|
+
*
|
|
1853
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
1854
|
+
* const result = Array.findLast(numbers, n => n % 2 === 0)
|
|
1855
|
+
* assert.deepStrictEqual(result, Option.some(4))
|
|
1856
|
+
*
|
|
1857
|
+
* @category elements
|
|
1858
|
+
* @since 2.0.0
|
|
1859
|
+
*/
|
|
996
1860
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Option<A>
|
|
997
1861
|
} = dual(
|
|
998
1862
|
2,
|
|
@@ -1029,7 +1893,33 @@ export const findLast: {
|
|
|
1029
1893
|
* @since 2.0.0
|
|
1030
1894
|
*/
|
|
1031
1895
|
export const insertAt: {
|
|
1896
|
+
/**
|
|
1897
|
+
* Insert an element at the specified index, creating a new `NonEmptyArray`,
|
|
1898
|
+
* or return `None` if the index is out of bounds.
|
|
1899
|
+
*
|
|
1900
|
+
* @example
|
|
1901
|
+
* import { Array, Option } from "effect"
|
|
1902
|
+
*
|
|
1903
|
+
* const letters = ['a', 'b', 'c', 'e']
|
|
1904
|
+
* const result = Array.insertAt(letters, 3, 'd')
|
|
1905
|
+
* assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))
|
|
1906
|
+
*
|
|
1907
|
+
* @since 2.0.0
|
|
1908
|
+
*/
|
|
1032
1909
|
<B>(i: number, b: B): <A>(self: Iterable<A>) => Option<NonEmptyArray<A | B>>
|
|
1910
|
+
/**
|
|
1911
|
+
* Insert an element at the specified index, creating a new `NonEmptyArray`,
|
|
1912
|
+
* or return `None` if the index is out of bounds.
|
|
1913
|
+
*
|
|
1914
|
+
* @example
|
|
1915
|
+
* import { Array, Option } from "effect"
|
|
1916
|
+
*
|
|
1917
|
+
* const letters = ['a', 'b', 'c', 'e']
|
|
1918
|
+
* const result = Array.insertAt(letters, 3, 'd')
|
|
1919
|
+
* assert.deepStrictEqual(result, Option.some(['a', 'b', 'c', 'd', 'e']))
|
|
1920
|
+
*
|
|
1921
|
+
* @since 2.0.0
|
|
1922
|
+
*/
|
|
1033
1923
|
<A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>>
|
|
1034
1924
|
} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>> => {
|
|
1035
1925
|
const out: Array<A | B> = Array.from(self)
|
|
@@ -1055,12 +1945,35 @@ export const insertAt: {
|
|
|
1055
1945
|
* @since 2.0.0
|
|
1056
1946
|
*/
|
|
1057
1947
|
export const replace: {
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1948
|
+
/**
|
|
1949
|
+
* Change the element at the specified index, creating a new `Array`,
|
|
1950
|
+
* or return a copy of the input if the index is out of bounds.
|
|
1951
|
+
*
|
|
1952
|
+
* @example
|
|
1953
|
+
* import { Array } from "effect"
|
|
1954
|
+
*
|
|
1955
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
1956
|
+
* const result = Array.replace(letters, 1, 'z')
|
|
1957
|
+
* assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])
|
|
1958
|
+
*
|
|
1959
|
+
* @since 2.0.0
|
|
1960
|
+
*/
|
|
1961
|
+
<B>(i: number, b: B): <A, S extends Iterable<A> = Iterable<A>>(
|
|
1062
1962
|
self: S
|
|
1063
1963
|
) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>
|
|
1964
|
+
/**
|
|
1965
|
+
* Change the element at the specified index, creating a new `Array`,
|
|
1966
|
+
* or return a copy of the input if the index is out of bounds.
|
|
1967
|
+
*
|
|
1968
|
+
* @example
|
|
1969
|
+
* import { Array } from "effect"
|
|
1970
|
+
*
|
|
1971
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
1972
|
+
* const result = Array.replace(letters, 1, 'z')
|
|
1973
|
+
* assert.deepStrictEqual(result, ['a', 'z', 'c', 'd'])
|
|
1974
|
+
*
|
|
1975
|
+
* @since 2.0.0
|
|
1976
|
+
*/
|
|
1064
1977
|
<A, B, S extends Iterable<A> = Iterable<A>>(
|
|
1065
1978
|
self: S,
|
|
1066
1979
|
i: number,
|
|
@@ -1081,10 +1994,34 @@ export const replace: {
|
|
|
1081
1994
|
* @since 2.0.0
|
|
1082
1995
|
*/
|
|
1083
1996
|
export const replaceOption: {
|
|
1997
|
+
/**
|
|
1998
|
+
* Replaces an element in an array with the given value, returning an option of the updated array.
|
|
1999
|
+
*
|
|
2000
|
+
* @example
|
|
2001
|
+
* import { Array, Option } from "effect"
|
|
2002
|
+
*
|
|
2003
|
+
* const numbers = [1, 2, 3]
|
|
2004
|
+
* const result = Array.replaceOption(numbers, 1, 4)
|
|
2005
|
+
* assert.deepStrictEqual(result, Option.some([1, 4, 3]))
|
|
2006
|
+
*
|
|
2007
|
+
* @since 2.0.0
|
|
2008
|
+
*/
|
|
1084
2009
|
<B>(
|
|
1085
2010
|
i: number,
|
|
1086
2011
|
b: B
|
|
1087
2012
|
): <A, S extends Iterable<A> = Iterable<A>>(self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>
|
|
2013
|
+
/**
|
|
2014
|
+
* Replaces an element in an array with the given value, returning an option of the updated array.
|
|
2015
|
+
*
|
|
2016
|
+
* @example
|
|
2017
|
+
* import { Array, Option } from "effect"
|
|
2018
|
+
*
|
|
2019
|
+
* const numbers = [1, 2, 3]
|
|
2020
|
+
* const result = Array.replaceOption(numbers, 1, 4)
|
|
2021
|
+
* assert.deepStrictEqual(result, Option.some([1, 4, 3]))
|
|
2022
|
+
*
|
|
2023
|
+
* @since 2.0.0
|
|
2024
|
+
*/
|
|
1088
2025
|
<A, B, S extends Iterable<A> = Iterable<A>>(
|
|
1089
2026
|
self: S,
|
|
1090
2027
|
i: number,
|
|
@@ -1109,10 +2046,36 @@ export const replaceOption: {
|
|
|
1109
2046
|
* @since 2.0.0
|
|
1110
2047
|
*/
|
|
1111
2048
|
export const modify: {
|
|
2049
|
+
/**
|
|
2050
|
+
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
2051
|
+
* or return a copy of the input if the index is out of bounds.
|
|
2052
|
+
*
|
|
2053
|
+
* @example
|
|
2054
|
+
* import { Array } from "effect"
|
|
2055
|
+
*
|
|
2056
|
+
* const numbers = [1, 2, 3, 4]
|
|
2057
|
+
* const result = Array.modify(numbers, 2, (n) => n * 2)
|
|
2058
|
+
* assert.deepStrictEqual(result, [1, 2, 6, 4])
|
|
2059
|
+
*
|
|
2060
|
+
* @since 2.0.0
|
|
2061
|
+
*/
|
|
1112
2062
|
<A, B, S extends Iterable<A> = Iterable<A>>(
|
|
1113
2063
|
i: number,
|
|
1114
2064
|
f: (a: ReadonlyArray.Infer<S>) => B
|
|
1115
2065
|
): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>
|
|
2066
|
+
/**
|
|
2067
|
+
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
2068
|
+
* or return a copy of the input if the index is out of bounds.
|
|
2069
|
+
*
|
|
2070
|
+
* @example
|
|
2071
|
+
* import { Array } from "effect"
|
|
2072
|
+
*
|
|
2073
|
+
* const numbers = [1, 2, 3, 4]
|
|
2074
|
+
* const result = Array.modify(numbers, 2, (n) => n * 2)
|
|
2075
|
+
* assert.deepStrictEqual(result, [1, 2, 6, 4])
|
|
2076
|
+
*
|
|
2077
|
+
* @since 2.0.0
|
|
2078
|
+
*/
|
|
1116
2079
|
<A, B, S extends Iterable<A> = Iterable<A>>(
|
|
1117
2080
|
self: S,
|
|
1118
2081
|
i: number,
|
|
@@ -1141,10 +2104,42 @@ export const modify: {
|
|
|
1141
2104
|
* @since 2.0.0
|
|
1142
2105
|
*/
|
|
1143
2106
|
export const modifyOption: {
|
|
2107
|
+
/**
|
|
2108
|
+
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
2109
|
+
* or return `None` if the index is out of bounds.
|
|
2110
|
+
*
|
|
2111
|
+
* @example
|
|
2112
|
+
* import { Array, Option } from "effect"
|
|
2113
|
+
*
|
|
2114
|
+
* const numbers = [1, 2, 3, 4]
|
|
2115
|
+
* const result = Array.modifyOption(numbers, 2, (n) => n * 2)
|
|
2116
|
+
* assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))
|
|
2117
|
+
*
|
|
2118
|
+
* const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)
|
|
2119
|
+
* assert.deepStrictEqual(outOfBoundsResult, Option.none())
|
|
2120
|
+
*
|
|
2121
|
+
* @since 2.0.0
|
|
2122
|
+
*/
|
|
1144
2123
|
<A, B, S extends Iterable<A> = Iterable<A>>(
|
|
1145
2124
|
i: number,
|
|
1146
2125
|
f: (a: ReadonlyArray.Infer<S>) => B
|
|
1147
2126
|
): (self: S) => Option<ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>>
|
|
2127
|
+
/**
|
|
2128
|
+
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
2129
|
+
* or return `None` if the index is out of bounds.
|
|
2130
|
+
*
|
|
2131
|
+
* @example
|
|
2132
|
+
* import { Array, Option } from "effect"
|
|
2133
|
+
*
|
|
2134
|
+
* const numbers = [1, 2, 3, 4]
|
|
2135
|
+
* const result = Array.modifyOption(numbers, 2, (n) => n * 2)
|
|
2136
|
+
* assert.deepStrictEqual(result, Option.some([1, 2, 6, 4]))
|
|
2137
|
+
*
|
|
2138
|
+
* const outOfBoundsResult = Array.modifyOption(numbers, 5, (n) => n * 2)
|
|
2139
|
+
* assert.deepStrictEqual(outOfBoundsResult, Option.none())
|
|
2140
|
+
*
|
|
2141
|
+
* @since 2.0.0
|
|
2142
|
+
*/
|
|
1148
2143
|
<A, B, S extends Iterable<A> = Iterable<A>>(
|
|
1149
2144
|
self: S,
|
|
1150
2145
|
i: number,
|
|
@@ -1178,9 +2173,41 @@ export const modifyOption: {
|
|
|
1178
2173
|
* @since 2.0.0
|
|
1179
2174
|
*/
|
|
1180
2175
|
export const remove: {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
2176
|
+
/**
|
|
2177
|
+
* Delete the element at the specified index, creating a new `Array`,
|
|
2178
|
+
* or return a copy of the input if the index is out of bounds.
|
|
2179
|
+
*
|
|
2180
|
+
* @example
|
|
2181
|
+
* import { Array } from "effect"
|
|
2182
|
+
*
|
|
2183
|
+
* const numbers = [1, 2, 3, 4]
|
|
2184
|
+
* const result = Array.remove(numbers, 2)
|
|
2185
|
+
* assert.deepStrictEqual(result, [1, 2, 4])
|
|
2186
|
+
*
|
|
2187
|
+
* const outOfBoundsResult = Array.remove(numbers, 5)
|
|
2188
|
+
* assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])
|
|
2189
|
+
*
|
|
2190
|
+
* @since 2.0.0
|
|
2191
|
+
*/
|
|
2192
|
+
(i: number): <A>(self: Iterable<A>) => Array<A>
|
|
2193
|
+
/**
|
|
2194
|
+
* Delete the element at the specified index, creating a new `Array`,
|
|
2195
|
+
* or return a copy of the input if the index is out of bounds.
|
|
2196
|
+
*
|
|
2197
|
+
* @example
|
|
2198
|
+
* import { Array } from "effect"
|
|
2199
|
+
*
|
|
2200
|
+
* const numbers = [1, 2, 3, 4]
|
|
2201
|
+
* const result = Array.remove(numbers, 2)
|
|
2202
|
+
* assert.deepStrictEqual(result, [1, 2, 4])
|
|
2203
|
+
*
|
|
2204
|
+
* const outOfBoundsResult = Array.remove(numbers, 5)
|
|
2205
|
+
* assert.deepStrictEqual(outOfBoundsResult, [1, 2, 3, 4])
|
|
2206
|
+
*
|
|
2207
|
+
* @since 2.0.0
|
|
2208
|
+
*/
|
|
2209
|
+
<A>(self: Iterable<A>, i: number): Array<A>
|
|
2210
|
+
} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {
|
|
1184
2211
|
const out = Array.from(self)
|
|
1185
2212
|
if (isOutOfBound(i, out)) {
|
|
1186
2213
|
return out
|
|
@@ -1215,10 +2242,31 @@ export const reverse = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(
|
|
|
1215
2242
|
* @since 2.0.0
|
|
1216
2243
|
*/
|
|
1217
2244
|
export const sort: {
|
|
2245
|
+
/**
|
|
2246
|
+
* Create a new array with elements sorted in increasing order based on the specified comparator.
|
|
2247
|
+
* If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.
|
|
2248
|
+
*
|
|
2249
|
+
* @category sorting
|
|
2250
|
+
* @since 2.0.0
|
|
2251
|
+
*/
|
|
1218
2252
|
<B>(
|
|
1219
2253
|
O: Order.Order<B>
|
|
1220
2254
|
): <A extends B, S extends ReadonlyArray<A> | Iterable<A>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
|
|
2255
|
+
/**
|
|
2256
|
+
* Create a new array with elements sorted in increasing order based on the specified comparator.
|
|
2257
|
+
* If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.
|
|
2258
|
+
*
|
|
2259
|
+
* @category sorting
|
|
2260
|
+
* @since 2.0.0
|
|
2261
|
+
*/
|
|
1221
2262
|
<A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A>
|
|
2263
|
+
/**
|
|
2264
|
+
* Create a new array with elements sorted in increasing order based on the specified comparator.
|
|
2265
|
+
* If the input is a `NonEmptyReadonlyArray`, the output will also be a `NonEmptyReadonlyArray`.
|
|
2266
|
+
*
|
|
2267
|
+
* @category sorting
|
|
2268
|
+
* @since 2.0.0
|
|
2269
|
+
*/
|
|
1222
2270
|
<A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>
|
|
1223
2271
|
} = dual(2, <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A> => {
|
|
1224
2272
|
const out = Array.from(self)
|
|
@@ -1247,11 +2295,71 @@ export const sort: {
|
|
|
1247
2295
|
* @category elements
|
|
1248
2296
|
*/
|
|
1249
2297
|
export const sortWith: {
|
|
2298
|
+
/**
|
|
2299
|
+
* Sorts an array based on a provided mapping function and order. The mapping
|
|
2300
|
+
* function transforms the elements into a value that can be compared, and the
|
|
2301
|
+
* order defines how those values should be sorted.
|
|
2302
|
+
*
|
|
2303
|
+
* @example
|
|
2304
|
+
* import { Array, Order } from "effect"
|
|
2305
|
+
*
|
|
2306
|
+
* const strings = ["aaa", "b", "cc"]
|
|
2307
|
+
* const result = Array.sortWith(strings, (s) => s.length, Order.number)
|
|
2308
|
+
* assert.deepStrictEqual(result, ["b", "cc", "aaa"])
|
|
2309
|
+
*
|
|
2310
|
+
* // Explanation:
|
|
2311
|
+
* // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`
|
|
2312
|
+
* // converts each string into its length, and the `Order.number` specifies that the lengths should
|
|
2313
|
+
* // be sorted in ascending order.
|
|
2314
|
+
*
|
|
2315
|
+
* @since 2.0.0
|
|
2316
|
+
* @category elements
|
|
2317
|
+
*/
|
|
1250
2318
|
<S extends Iterable<any> | NonEmptyReadonlyArray<any>, B>(
|
|
1251
2319
|
f: (a: ReadonlyArray.Infer<S>) => B,
|
|
1252
2320
|
order: Order.Order<B>
|
|
1253
2321
|
): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
|
|
2322
|
+
/**
|
|
2323
|
+
* Sorts an array based on a provided mapping function and order. The mapping
|
|
2324
|
+
* function transforms the elements into a value that can be compared, and the
|
|
2325
|
+
* order defines how those values should be sorted.
|
|
2326
|
+
*
|
|
2327
|
+
* @example
|
|
2328
|
+
* import { Array, Order } from "effect"
|
|
2329
|
+
*
|
|
2330
|
+
* const strings = ["aaa", "b", "cc"]
|
|
2331
|
+
* const result = Array.sortWith(strings, (s) => s.length, Order.number)
|
|
2332
|
+
* assert.deepStrictEqual(result, ["b", "cc", "aaa"])
|
|
2333
|
+
*
|
|
2334
|
+
* // Explanation:
|
|
2335
|
+
* // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`
|
|
2336
|
+
* // converts each string into its length, and the `Order.number` specifies that the lengths should
|
|
2337
|
+
* // be sorted in ascending order.
|
|
2338
|
+
*
|
|
2339
|
+
* @since 2.0.0
|
|
2340
|
+
* @category elements
|
|
2341
|
+
*/
|
|
1254
2342
|
<A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B, O: Order.Order<B>): NonEmptyArray<A>
|
|
2343
|
+
/**
|
|
2344
|
+
* Sorts an array based on a provided mapping function and order. The mapping
|
|
2345
|
+
* function transforms the elements into a value that can be compared, and the
|
|
2346
|
+
* order defines how those values should be sorted.
|
|
2347
|
+
*
|
|
2348
|
+
* @example
|
|
2349
|
+
* import { Array, Order } from "effect"
|
|
2350
|
+
*
|
|
2351
|
+
* const strings = ["aaa", "b", "cc"]
|
|
2352
|
+
* const result = Array.sortWith(strings, (s) => s.length, Order.number)
|
|
2353
|
+
* assert.deepStrictEqual(result, ["b", "cc", "aaa"])
|
|
2354
|
+
*
|
|
2355
|
+
* // Explanation:
|
|
2356
|
+
* // The array of strings is sorted based on their lengths. The mapping function `(s) => s.length`
|
|
2357
|
+
* // converts each string into its length, and the `Order.number` specifies that the lengths should
|
|
2358
|
+
* // be sorted in ascending order.
|
|
2359
|
+
*
|
|
2360
|
+
* @since 2.0.0
|
|
2361
|
+
* @category elements
|
|
2362
|
+
*/
|
|
1255
2363
|
<A, B>(self: Iterable<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>
|
|
1256
2364
|
} = dual(
|
|
1257
2365
|
3,
|
|
@@ -1323,9 +2431,73 @@ export const sortBy = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(
|
|
|
1323
2431
|
* @since 2.0.0
|
|
1324
2432
|
*/
|
|
1325
2433
|
export const zip: {
|
|
2434
|
+
/**
|
|
2435
|
+
* Takes two `Iterable`s and returns an `Array` of corresponding pairs.
|
|
2436
|
+
* If one input `Iterable` is short, excess elements of the
|
|
2437
|
+
* longer `Iterable` are discarded.
|
|
2438
|
+
*
|
|
2439
|
+
* @example
|
|
2440
|
+
* import { Array } from "effect"
|
|
2441
|
+
*
|
|
2442
|
+
* const array1 = [1, 2, 3]
|
|
2443
|
+
* const array2 = ['a', 'b']
|
|
2444
|
+
* const result = Array.zip(array1, array2)
|
|
2445
|
+
* assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])
|
|
2446
|
+
*
|
|
2447
|
+
* @category zipping
|
|
2448
|
+
* @since 2.0.0
|
|
2449
|
+
*/
|
|
1326
2450
|
<B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>
|
|
2451
|
+
/**
|
|
2452
|
+
* Takes two `Iterable`s and returns an `Array` of corresponding pairs.
|
|
2453
|
+
* If one input `Iterable` is short, excess elements of the
|
|
2454
|
+
* longer `Iterable` are discarded.
|
|
2455
|
+
*
|
|
2456
|
+
* @example
|
|
2457
|
+
* import { Array } from "effect"
|
|
2458
|
+
*
|
|
2459
|
+
* const array1 = [1, 2, 3]
|
|
2460
|
+
* const array2 = ['a', 'b']
|
|
2461
|
+
* const result = Array.zip(array1, array2)
|
|
2462
|
+
* assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])
|
|
2463
|
+
*
|
|
2464
|
+
* @category zipping
|
|
2465
|
+
* @since 2.0.0
|
|
2466
|
+
*/
|
|
1327
2467
|
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>
|
|
2468
|
+
/**
|
|
2469
|
+
* Takes two `Iterable`s and returns an `Array` of corresponding pairs.
|
|
2470
|
+
* If one input `Iterable` is short, excess elements of the
|
|
2471
|
+
* longer `Iterable` are discarded.
|
|
2472
|
+
*
|
|
2473
|
+
* @example
|
|
2474
|
+
* import { Array } from "effect"
|
|
2475
|
+
*
|
|
2476
|
+
* const array1 = [1, 2, 3]
|
|
2477
|
+
* const array2 = ['a', 'b']
|
|
2478
|
+
* const result = Array.zip(array1, array2)
|
|
2479
|
+
* assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])
|
|
2480
|
+
*
|
|
2481
|
+
* @category zipping
|
|
2482
|
+
* @since 2.0.0
|
|
2483
|
+
*/
|
|
1328
2484
|
<A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>
|
|
2485
|
+
/**
|
|
2486
|
+
* Takes two `Iterable`s and returns an `Array` of corresponding pairs.
|
|
2487
|
+
* If one input `Iterable` is short, excess elements of the
|
|
2488
|
+
* longer `Iterable` are discarded.
|
|
2489
|
+
*
|
|
2490
|
+
* @example
|
|
2491
|
+
* import { Array } from "effect"
|
|
2492
|
+
*
|
|
2493
|
+
* const array1 = [1, 2, 3]
|
|
2494
|
+
* const array2 = ['a', 'b']
|
|
2495
|
+
* const result = Array.zip(array1, array2)
|
|
2496
|
+
* assert.deepStrictEqual(result, [[1, 'a'], [2, 'b']])
|
|
2497
|
+
*
|
|
2498
|
+
* @category zipping
|
|
2499
|
+
* @since 2.0.0
|
|
2500
|
+
*/
|
|
1329
2501
|
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>
|
|
1330
2502
|
} = dual(
|
|
1331
2503
|
2,
|
|
@@ -1348,9 +2520,73 @@ export const zip: {
|
|
|
1348
2520
|
* @since 2.0.0
|
|
1349
2521
|
*/
|
|
1350
2522
|
export const zipWith: {
|
|
2523
|
+
/**
|
|
2524
|
+
* Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one
|
|
2525
|
+
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
|
|
2526
|
+
*
|
|
2527
|
+
* @example
|
|
2528
|
+
* import { Array } from "effect"
|
|
2529
|
+
*
|
|
2530
|
+
* const array1 = [1, 2, 3]
|
|
2531
|
+
* const array2 = [4, 5, 6]
|
|
2532
|
+
* const result = Array.zipWith(array1, array2, (a, b) => a + b)
|
|
2533
|
+
* assert.deepStrictEqual(result, [5, 7, 9])
|
|
2534
|
+
*
|
|
2535
|
+
* @category zipping
|
|
2536
|
+
* @since 2.0.0
|
|
2537
|
+
*/
|
|
1351
2538
|
<B, A, C>(that: NonEmptyReadonlyArray<B>, f: (a: A, b: B) => C): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>
|
|
2539
|
+
/**
|
|
2540
|
+
* Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one
|
|
2541
|
+
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
|
|
2542
|
+
*
|
|
2543
|
+
* @example
|
|
2544
|
+
* import { Array } from "effect"
|
|
2545
|
+
*
|
|
2546
|
+
* const array1 = [1, 2, 3]
|
|
2547
|
+
* const array2 = [4, 5, 6]
|
|
2548
|
+
* const result = Array.zipWith(array1, array2, (a, b) => a + b)
|
|
2549
|
+
* assert.deepStrictEqual(result, [5, 7, 9])
|
|
2550
|
+
*
|
|
2551
|
+
* @category zipping
|
|
2552
|
+
* @since 2.0.0
|
|
2553
|
+
*/
|
|
1352
2554
|
<B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>
|
|
1353
|
-
|
|
2555
|
+
/**
|
|
2556
|
+
* Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one
|
|
2557
|
+
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
|
|
2558
|
+
*
|
|
2559
|
+
* @example
|
|
2560
|
+
* import { Array } from "effect"
|
|
2561
|
+
*
|
|
2562
|
+
* const array1 = [1, 2, 3]
|
|
2563
|
+
* const array2 = [4, 5, 6]
|
|
2564
|
+
* const result = Array.zipWith(array1, array2, (a, b) => a + b)
|
|
2565
|
+
* assert.deepStrictEqual(result, [5, 7, 9])
|
|
2566
|
+
*
|
|
2567
|
+
* @category zipping
|
|
2568
|
+
* @since 2.0.0
|
|
2569
|
+
*/
|
|
2570
|
+
<A, B, C>(
|
|
2571
|
+
self: NonEmptyReadonlyArray<A>,
|
|
2572
|
+
that: NonEmptyReadonlyArray<B>,
|
|
2573
|
+
f: (a: A, b: B) => C
|
|
2574
|
+
): NonEmptyArray<C>
|
|
2575
|
+
/**
|
|
2576
|
+
* Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one
|
|
2577
|
+
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
|
|
2578
|
+
*
|
|
2579
|
+
* @example
|
|
2580
|
+
* import { Array } from "effect"
|
|
2581
|
+
*
|
|
2582
|
+
* const array1 = [1, 2, 3]
|
|
2583
|
+
* const array2 = [4, 5, 6]
|
|
2584
|
+
* const result = Array.zipWith(array1, array2, (a, b) => a + b)
|
|
2585
|
+
* assert.deepStrictEqual(result, [5, 7, 9])
|
|
2586
|
+
*
|
|
2587
|
+
* @category zipping
|
|
2588
|
+
* @since 2.0.0
|
|
2589
|
+
*/
|
|
1354
2590
|
<B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>
|
|
1355
2591
|
} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C> => {
|
|
1356
2592
|
const as = fromIterable(self)
|
|
@@ -1409,10 +2645,47 @@ export const unzip: <S extends Iterable<readonly [any, any]> | NonEmptyReadonlyA
|
|
|
1409
2645
|
* @since 2.0.0
|
|
1410
2646
|
*/
|
|
1411
2647
|
export const intersperse: {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
2648
|
+
/**
|
|
2649
|
+
* Places an element in between members of an `Iterable`.
|
|
2650
|
+
* If the input is a non-empty array, the result is also a non-empty array.
|
|
2651
|
+
*
|
|
2652
|
+
* @example
|
|
2653
|
+
* import { Array } from "effect"
|
|
2654
|
+
*
|
|
2655
|
+
* const numbers = [1, 2, 3]
|
|
2656
|
+
* const result = Array.intersperse(numbers, 0)
|
|
2657
|
+
* assert.deepStrictEqual(result, [1, 0, 2, 0, 3])
|
|
2658
|
+
*
|
|
2659
|
+
* @since 2.0.0
|
|
2660
|
+
*/
|
|
2661
|
+
<B>(middle: B): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S> | B>
|
|
2662
|
+
/**
|
|
2663
|
+
* Places an element in between members of an `Iterable`.
|
|
2664
|
+
* If the input is a non-empty array, the result is also a non-empty array.
|
|
2665
|
+
*
|
|
2666
|
+
* @example
|
|
2667
|
+
* import { Array } from "effect"
|
|
2668
|
+
*
|
|
2669
|
+
* const numbers = [1, 2, 3]
|
|
2670
|
+
* const result = Array.intersperse(numbers, 0)
|
|
2671
|
+
* assert.deepStrictEqual(result, [1, 0, 2, 0, 3])
|
|
2672
|
+
*
|
|
2673
|
+
* @since 2.0.0
|
|
2674
|
+
*/
|
|
1415
2675
|
<A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>
|
|
2676
|
+
/**
|
|
2677
|
+
* Places an element in between members of an `Iterable`.
|
|
2678
|
+
* If the input is a non-empty array, the result is also a non-empty array.
|
|
2679
|
+
*
|
|
2680
|
+
* @example
|
|
2681
|
+
* import { Array } from "effect"
|
|
2682
|
+
*
|
|
2683
|
+
* const numbers = [1, 2, 3]
|
|
2684
|
+
* const result = Array.intersperse(numbers, 0)
|
|
2685
|
+
* assert.deepStrictEqual(result, [1, 0, 2, 0, 3])
|
|
2686
|
+
*
|
|
2687
|
+
* @since 2.0.0
|
|
2688
|
+
*/
|
|
1416
2689
|
<A, B>(self: Iterable<A>, middle: B): Array<A | B>
|
|
1417
2690
|
} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {
|
|
1418
2691
|
const input = fromIterable(self)
|
|
@@ -1442,7 +2715,29 @@ export const intersperse: {
|
|
|
1442
2715
|
* @since 2.0.0
|
|
1443
2716
|
*/
|
|
1444
2717
|
export const modifyNonEmptyHead: {
|
|
2718
|
+
/**
|
|
2719
|
+
* Apply a function to the head, creating a new `NonEmptyReadonlyArray`.
|
|
2720
|
+
*
|
|
2721
|
+
* @example
|
|
2722
|
+
* import { Array } from "effect"
|
|
2723
|
+
*
|
|
2724
|
+
* const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)
|
|
2725
|
+
* assert.deepStrictEqual(result, [10, 2, 3])
|
|
2726
|
+
*
|
|
2727
|
+
* @since 2.0.0
|
|
2728
|
+
*/
|
|
1445
2729
|
<A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
2730
|
+
/**
|
|
2731
|
+
* Apply a function to the head, creating a new `NonEmptyReadonlyArray`.
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* import { Array } from "effect"
|
|
2735
|
+
*
|
|
2736
|
+
* const result = Array.modifyNonEmptyHead([1, 2, 3], n => n * 10)
|
|
2737
|
+
* assert.deepStrictEqual(result, [10, 2, 3])
|
|
2738
|
+
*
|
|
2739
|
+
* @since 2.0.0
|
|
2740
|
+
*/
|
|
1446
2741
|
<A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>
|
|
1447
2742
|
} = dual(
|
|
1448
2743
|
2,
|
|
@@ -1464,7 +2759,29 @@ export const modifyNonEmptyHead: {
|
|
|
1464
2759
|
* @since 2.0.0
|
|
1465
2760
|
*/
|
|
1466
2761
|
export const setNonEmptyHead: {
|
|
2762
|
+
/**
|
|
2763
|
+
* Change the head, creating a new `NonEmptyReadonlyArray`.
|
|
2764
|
+
*
|
|
2765
|
+
* @example
|
|
2766
|
+
* import { Array } from "effect"
|
|
2767
|
+
*
|
|
2768
|
+
* const result = Array.setNonEmptyHead([1, 2, 3], 10)
|
|
2769
|
+
* assert.deepStrictEqual(result, [10, 2, 3])
|
|
2770
|
+
*
|
|
2771
|
+
* @since 2.0.0
|
|
2772
|
+
*/
|
|
1467
2773
|
<B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
2774
|
+
/**
|
|
2775
|
+
* Change the head, creating a new `NonEmptyReadonlyArray`.
|
|
2776
|
+
*
|
|
2777
|
+
* @example
|
|
2778
|
+
* import { Array } from "effect"
|
|
2779
|
+
*
|
|
2780
|
+
* const result = Array.setNonEmptyHead([1, 2, 3], 10)
|
|
2781
|
+
* assert.deepStrictEqual(result, [10, 2, 3])
|
|
2782
|
+
*
|
|
2783
|
+
* @since 2.0.0
|
|
2784
|
+
*/
|
|
1468
2785
|
<A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>
|
|
1469
2786
|
} = dual(
|
|
1470
2787
|
2,
|
|
@@ -1483,7 +2800,29 @@ export const setNonEmptyHead: {
|
|
|
1483
2800
|
* @since 2.0.0
|
|
1484
2801
|
*/
|
|
1485
2802
|
export const modifyNonEmptyLast: {
|
|
2803
|
+
/**
|
|
2804
|
+
* Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.
|
|
2805
|
+
*
|
|
2806
|
+
* @example
|
|
2807
|
+
* import { Array } from "effect"
|
|
2808
|
+
*
|
|
2809
|
+
* const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)
|
|
2810
|
+
* assert.deepStrictEqual(result, [1, 2, 6])
|
|
2811
|
+
*
|
|
2812
|
+
* @since 2.0.0
|
|
2813
|
+
*/
|
|
1486
2814
|
<A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
2815
|
+
/**
|
|
2816
|
+
* Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.
|
|
2817
|
+
*
|
|
2818
|
+
* @example
|
|
2819
|
+
* import { Array } from "effect"
|
|
2820
|
+
*
|
|
2821
|
+
* const result = Array.modifyNonEmptyLast([1, 2, 3], n => n * 2)
|
|
2822
|
+
* assert.deepStrictEqual(result, [1, 2, 6])
|
|
2823
|
+
*
|
|
2824
|
+
* @since 2.0.0
|
|
2825
|
+
*/
|
|
1487
2826
|
<A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>
|
|
1488
2827
|
} = dual(
|
|
1489
2828
|
2,
|
|
@@ -1503,7 +2842,29 @@ export const modifyNonEmptyLast: {
|
|
|
1503
2842
|
* @since 2.0.0
|
|
1504
2843
|
*/
|
|
1505
2844
|
export const setNonEmptyLast: {
|
|
2845
|
+
/**
|
|
2846
|
+
* Change the last element, creating a new `NonEmptyReadonlyArray`.
|
|
2847
|
+
*
|
|
2848
|
+
* @example
|
|
2849
|
+
* import { Array } from "effect"
|
|
2850
|
+
*
|
|
2851
|
+
* const result = Array.setNonEmptyLast([1, 2, 3], 4)
|
|
2852
|
+
* assert.deepStrictEqual(result, [1, 2, 4])
|
|
2853
|
+
*
|
|
2854
|
+
* @since 2.0.0
|
|
2855
|
+
*/
|
|
1506
2856
|
<B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
2857
|
+
/**
|
|
2858
|
+
* Change the last element, creating a new `NonEmptyReadonlyArray`.
|
|
2859
|
+
*
|
|
2860
|
+
* @example
|
|
2861
|
+
* import { Array } from "effect"
|
|
2862
|
+
*
|
|
2863
|
+
* const result = Array.setNonEmptyLast([1, 2, 3], 4)
|
|
2864
|
+
* assert.deepStrictEqual(result, [1, 2, 4])
|
|
2865
|
+
*
|
|
2866
|
+
* @since 2.0.0
|
|
2867
|
+
*/
|
|
1507
2868
|
<A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>
|
|
1508
2869
|
} = dual(
|
|
1509
2870
|
2,
|
|
@@ -1524,8 +2885,47 @@ export const setNonEmptyLast: {
|
|
|
1524
2885
|
* @since 2.0.0
|
|
1525
2886
|
*/
|
|
1526
2887
|
export const rotate: {
|
|
2888
|
+
/**
|
|
2889
|
+
* Rotate an `Iterable` by `n` steps.
|
|
2890
|
+
* If the input is a non-empty array, the result is also a non-empty array.
|
|
2891
|
+
*
|
|
2892
|
+
* @example
|
|
2893
|
+
* import { Array } from "effect"
|
|
2894
|
+
*
|
|
2895
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
2896
|
+
* const result = Array.rotate(letters, 2)
|
|
2897
|
+
* assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])
|
|
2898
|
+
*
|
|
2899
|
+
* @since 2.0.0
|
|
2900
|
+
*/
|
|
1527
2901
|
(n: number): <S extends Iterable<any>>(self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
|
|
2902
|
+
/**
|
|
2903
|
+
* Rotate an `Iterable` by `n` steps.
|
|
2904
|
+
* If the input is a non-empty array, the result is also a non-empty array.
|
|
2905
|
+
*
|
|
2906
|
+
* @example
|
|
2907
|
+
* import { Array } from "effect"
|
|
2908
|
+
*
|
|
2909
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
2910
|
+
* const result = Array.rotate(letters, 2)
|
|
2911
|
+
* assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])
|
|
2912
|
+
*
|
|
2913
|
+
* @since 2.0.0
|
|
2914
|
+
*/
|
|
1528
2915
|
<A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>
|
|
2916
|
+
/**
|
|
2917
|
+
* Rotate an `Iterable` by `n` steps.
|
|
2918
|
+
* If the input is a non-empty array, the result is also a non-empty array.
|
|
2919
|
+
*
|
|
2920
|
+
* @example
|
|
2921
|
+
* import { Array } from "effect"
|
|
2922
|
+
*
|
|
2923
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
2924
|
+
* const result = Array.rotate(letters, 2)
|
|
2925
|
+
* assert.deepStrictEqual(result, ['c', 'd', 'a', 'b'])
|
|
2926
|
+
*
|
|
2927
|
+
* @since 2.0.0
|
|
2928
|
+
*/
|
|
1529
2929
|
<A>(self: Iterable<A>, n: number): Array<A>
|
|
1530
2930
|
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
1531
2931
|
const input = fromIterable(self)
|
|
@@ -1589,7 +2989,33 @@ const _equivalence = Equal.equivalence()
|
|
|
1589
2989
|
* @since 2.0.0
|
|
1590
2990
|
*/
|
|
1591
2991
|
export const contains: {
|
|
2992
|
+
/**
|
|
2993
|
+
* Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.
|
|
2994
|
+
*
|
|
2995
|
+
* @example
|
|
2996
|
+
* import { Array } from "effect"
|
|
2997
|
+
*
|
|
2998
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
2999
|
+
* const result = Array.contains('c')(letters)
|
|
3000
|
+
* assert.deepStrictEqual(result, true)
|
|
3001
|
+
*
|
|
3002
|
+
* @category elements
|
|
3003
|
+
* @since 2.0.0
|
|
3004
|
+
*/
|
|
1592
3005
|
<A>(a: A): (self: Iterable<A>) => boolean
|
|
3006
|
+
/**
|
|
3007
|
+
* Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.
|
|
3008
|
+
*
|
|
3009
|
+
* @example
|
|
3010
|
+
* import { Array } from "effect"
|
|
3011
|
+
*
|
|
3012
|
+
* const letters = ['a', 'b', 'c', 'd']
|
|
3013
|
+
* const result = Array.contains('c')(letters)
|
|
3014
|
+
* assert.deepStrictEqual(result, true)
|
|
3015
|
+
*
|
|
3016
|
+
* @category elements
|
|
3017
|
+
* @since 2.0.0
|
|
3018
|
+
*/
|
|
1593
3019
|
<A>(self: Iterable<A>, a: A): boolean
|
|
1594
3020
|
} = containsWith(_equivalence)
|
|
1595
3021
|
|
|
@@ -1613,13 +3039,70 @@ export const contains: {
|
|
|
1613
3039
|
* @since 2.0.0
|
|
1614
3040
|
*/
|
|
1615
3041
|
export const chop: {
|
|
3042
|
+
/**
|
|
3043
|
+
* A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for "chopping" up the input
|
|
3044
|
+
* `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a
|
|
3045
|
+
* value and the rest of the `Array`.
|
|
3046
|
+
*
|
|
3047
|
+
* @example
|
|
3048
|
+
* import { Array } from "effect"
|
|
3049
|
+
*
|
|
3050
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3051
|
+
* const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])
|
|
3052
|
+
* assert.deepStrictEqual(result, [2, 4, 6, 8, 10])
|
|
3053
|
+
*
|
|
3054
|
+
* // Explanation:
|
|
3055
|
+
* // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.
|
|
3056
|
+
* // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,
|
|
3057
|
+
* // resulting in a new array `[2, 4, 6, 8, 10]`.
|
|
3058
|
+
*
|
|
3059
|
+
* @since 2.0.0
|
|
3060
|
+
*/
|
|
1616
3061
|
<S extends Iterable<any>, B>(
|
|
1617
3062
|
f: (as: NonEmptyReadonlyArray<ReadonlyArray.Infer<S>>) => readonly [B, ReadonlyArray<ReadonlyArray.Infer<S>>]
|
|
1618
3063
|
): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
|
|
3064
|
+
/**
|
|
3065
|
+
* A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for "chopping" up the input
|
|
3066
|
+
* `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a
|
|
3067
|
+
* value and the rest of the `Array`.
|
|
3068
|
+
*
|
|
3069
|
+
* @example
|
|
3070
|
+
* import { Array } from "effect"
|
|
3071
|
+
*
|
|
3072
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3073
|
+
* const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])
|
|
3074
|
+
* assert.deepStrictEqual(result, [2, 4, 6, 8, 10])
|
|
3075
|
+
*
|
|
3076
|
+
* // Explanation:
|
|
3077
|
+
* // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.
|
|
3078
|
+
* // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,
|
|
3079
|
+
* // resulting in a new array `[2, 4, 6, 8, 10]`.
|
|
3080
|
+
*
|
|
3081
|
+
* @since 2.0.0
|
|
3082
|
+
*/
|
|
1619
3083
|
<A, B>(
|
|
1620
3084
|
self: NonEmptyReadonlyArray<A>,
|
|
1621
3085
|
f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]
|
|
1622
3086
|
): NonEmptyArray<B>
|
|
3087
|
+
/**
|
|
3088
|
+
* A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for "chopping" up the input
|
|
3089
|
+
* `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a
|
|
3090
|
+
* value and the rest of the `Array`.
|
|
3091
|
+
*
|
|
3092
|
+
* @example
|
|
3093
|
+
* import { Array } from "effect"
|
|
3094
|
+
*
|
|
3095
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3096
|
+
* const result = Array.chop(numbers, (as): [number, Array<number>] => [as[0] * 2, as.slice(1)])
|
|
3097
|
+
* assert.deepStrictEqual(result, [2, 4, 6, 8, 10])
|
|
3098
|
+
*
|
|
3099
|
+
* // Explanation:
|
|
3100
|
+
* // The `chopFunction` takes the first element of the array, doubles it, and then returns it along with the rest of the array.
|
|
3101
|
+
* // The `chop` function applies this `chopFunction` recursively to the input array `[1, 2, 3, 4, 5]`,
|
|
3102
|
+
* // resulting in a new array `[2, 4, 6, 8, 10]`.
|
|
3103
|
+
*
|
|
3104
|
+
* @since 2.0.0
|
|
3105
|
+
*/
|
|
1623
3106
|
<A, B>(
|
|
1624
3107
|
self: Iterable<A>,
|
|
1625
3108
|
f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]
|
|
@@ -1658,12 +3141,40 @@ export const chop: {
|
|
|
1658
3141
|
* @since 2.0.0
|
|
1659
3142
|
*/
|
|
1660
3143
|
export const splitAt: {
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
3144
|
+
/**
|
|
3145
|
+
* Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.
|
|
3146
|
+
* The value of `n` can be `0`.
|
|
3147
|
+
*
|
|
3148
|
+
* @example
|
|
3149
|
+
* import { Array } from "effect"
|
|
3150
|
+
*
|
|
3151
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3152
|
+
* const result = Array.splitAt(numbers, 3)
|
|
3153
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])
|
|
3154
|
+
*
|
|
3155
|
+
* @category splitting
|
|
3156
|
+
* @since 2.0.0
|
|
3157
|
+
*/
|
|
3158
|
+
(n: number): <A>(self: Iterable<A>) => [beforeIndex: Array<A>, fromIndex: Array<A>]
|
|
3159
|
+
/**
|
|
3160
|
+
* Splits an `Iterable` into two segments, with the first segment containing a maximum of `n` elements.
|
|
3161
|
+
* The value of `n` can be `0`.
|
|
3162
|
+
*
|
|
3163
|
+
* @example
|
|
3164
|
+
* import { Array } from "effect"
|
|
3165
|
+
*
|
|
3166
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3167
|
+
* const result = Array.splitAt(numbers, 3)
|
|
3168
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])
|
|
3169
|
+
*
|
|
3170
|
+
* @category splitting
|
|
3171
|
+
* @since 2.0.0
|
|
3172
|
+
*/
|
|
3173
|
+
<A>(self: Iterable<A>, n: number): [beforeIndex: Array<A>, fromIndex: Array<A>]
|
|
3174
|
+
} = dual(2, <A>(self: Iterable<A>, n: number): [Array<A>, Array<A>] => {
|
|
3175
|
+
const input = Array.from(self)
|
|
3176
|
+
const _n = Math.floor(n)
|
|
3177
|
+
if (isNonEmptyReadonlyArray(input)) {
|
|
1667
3178
|
if (_n >= 1) {
|
|
1668
3179
|
return splitNonEmptyAt(input, _n)
|
|
1669
3180
|
}
|
|
@@ -1686,7 +3197,33 @@ export const splitAt: {
|
|
|
1686
3197
|
* @since 2.0.0
|
|
1687
3198
|
*/
|
|
1688
3199
|
export const splitNonEmptyAt: {
|
|
3200
|
+
/**
|
|
3201
|
+
* Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.
|
|
3202
|
+
* The value of `n` must be `>= 1`.
|
|
3203
|
+
*
|
|
3204
|
+
* @example
|
|
3205
|
+
* import { Array } from "effect"
|
|
3206
|
+
*
|
|
3207
|
+
* const result = Array.splitNonEmptyAt(["a", "b", "c", "d", "e"], 3)
|
|
3208
|
+
* assert.deepStrictEqual(result, [["a", "b", "c"], ["d", "e"]])
|
|
3209
|
+
*
|
|
3210
|
+
* @category splitting
|
|
3211
|
+
* @since 2.0.0
|
|
3212
|
+
*/
|
|
1689
3213
|
(n: number): <A>(self: NonEmptyReadonlyArray<A>) => [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]
|
|
3214
|
+
/**
|
|
3215
|
+
* Splits a `NonEmptyReadonlyArray` into two segments, with the first segment containing a maximum of `n` elements.
|
|
3216
|
+
* The value of `n` must be `>= 1`.
|
|
3217
|
+
*
|
|
3218
|
+
* @example
|
|
3219
|
+
* import { Array } from "effect"
|
|
3220
|
+
*
|
|
3221
|
+
* const result = Array.splitNonEmptyAt(["a", "b", "c", "d", "e"], 3)
|
|
3222
|
+
* assert.deepStrictEqual(result, [["a", "b", "c"], ["d", "e"]])
|
|
3223
|
+
*
|
|
3224
|
+
* @category splitting
|
|
3225
|
+
* @since 2.0.0
|
|
3226
|
+
*/
|
|
1690
3227
|
<A>(self: NonEmptyReadonlyArray<A>, n: number): [beforeIndex: NonEmptyArray<A>, fromIndex: Array<A>]
|
|
1691
3228
|
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {
|
|
1692
3229
|
const _n = Math.max(1, Math.floor(n))
|
|
@@ -1709,7 +3246,33 @@ export const splitNonEmptyAt: {
|
|
|
1709
3246
|
* @category splitting
|
|
1710
3247
|
*/
|
|
1711
3248
|
export const split: {
|
|
3249
|
+
/**
|
|
3250
|
+
* Splits this iterable into `n` equally sized arrays.
|
|
3251
|
+
*
|
|
3252
|
+
* @example
|
|
3253
|
+
* import { Array } from "effect"
|
|
3254
|
+
*
|
|
3255
|
+
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8]
|
|
3256
|
+
* const result = Array.split(numbers, 3)
|
|
3257
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])
|
|
3258
|
+
*
|
|
3259
|
+
* @since 2.0.0
|
|
3260
|
+
* @category splitting
|
|
3261
|
+
*/
|
|
1712
3262
|
(n: number): <A>(self: Iterable<A>) => Array<Array<A>>
|
|
3263
|
+
/**
|
|
3264
|
+
* Splits this iterable into `n` equally sized arrays.
|
|
3265
|
+
*
|
|
3266
|
+
* @example
|
|
3267
|
+
* import { Array } from "effect"
|
|
3268
|
+
*
|
|
3269
|
+
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8]
|
|
3270
|
+
* const result = Array.split(numbers, 3)
|
|
3271
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5, 6], [7, 8]])
|
|
3272
|
+
*
|
|
3273
|
+
* @since 2.0.0
|
|
3274
|
+
* @category splitting
|
|
3275
|
+
*/
|
|
1713
3276
|
<A>(self: Iterable<A>, n: number): Array<Array<A>>
|
|
1714
3277
|
} = dual(2, <A>(self: Iterable<A>, n: number) => {
|
|
1715
3278
|
const input = fromIterable(self)
|
|
@@ -1731,9 +3294,37 @@ export const split: {
|
|
|
1731
3294
|
* @since 2.0.0
|
|
1732
3295
|
*/
|
|
1733
3296
|
export const splitWhere: {
|
|
3297
|
+
/**
|
|
3298
|
+
* Splits this iterable on the first element that matches this predicate.
|
|
3299
|
+
* Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.
|
|
3300
|
+
*
|
|
3301
|
+
* @example
|
|
3302
|
+
* import { Array } from "effect"
|
|
3303
|
+
*
|
|
3304
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3305
|
+
* const result = Array.splitWhere(numbers, n => n > 3)
|
|
3306
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])
|
|
3307
|
+
*
|
|
3308
|
+
* @category splitting
|
|
3309
|
+
* @since 2.0.0
|
|
3310
|
+
*/
|
|
1734
3311
|
<A>(
|
|
1735
3312
|
predicate: (a: NoInfer<A>, i: number) => boolean
|
|
1736
3313
|
): (self: Iterable<A>) => [beforeMatch: Array<A>, fromMatch: Array<A>]
|
|
3314
|
+
/**
|
|
3315
|
+
* Splits this iterable on the first element that matches this predicate.
|
|
3316
|
+
* Returns a tuple containing two arrays: the first one is before the match, and the second one is from the match onward.
|
|
3317
|
+
*
|
|
3318
|
+
* @example
|
|
3319
|
+
* import { Array } from "effect"
|
|
3320
|
+
*
|
|
3321
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3322
|
+
* const result = Array.splitWhere(numbers, n => n > 3)
|
|
3323
|
+
* assert.deepStrictEqual(result, [[1, 2, 3], [4, 5]])
|
|
3324
|
+
*
|
|
3325
|
+
* @category splitting
|
|
3326
|
+
* @since 2.0.0
|
|
3327
|
+
*/
|
|
1737
3328
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>]
|
|
1738
3329
|
} = dual(
|
|
1739
3330
|
2,
|
|
@@ -1754,7 +3345,31 @@ export const splitWhere: {
|
|
|
1754
3345
|
* @since 2.0.0
|
|
1755
3346
|
*/
|
|
1756
3347
|
export const copy: {
|
|
3348
|
+
/**
|
|
3349
|
+
* Copies an array.
|
|
3350
|
+
*
|
|
3351
|
+
* @example
|
|
3352
|
+
* import { Array } from "effect"
|
|
3353
|
+
*
|
|
3354
|
+
* const numbers = [1, 2, 3]
|
|
3355
|
+
* const copy = Array.copy(numbers)
|
|
3356
|
+
* assert.deepStrictEqual(copy, [1, 2, 3])
|
|
3357
|
+
*
|
|
3358
|
+
* @since 2.0.0
|
|
3359
|
+
*/
|
|
1757
3360
|
<A>(self: NonEmptyReadonlyArray<A>): NonEmptyArray<A>
|
|
3361
|
+
/**
|
|
3362
|
+
* Copies an array.
|
|
3363
|
+
*
|
|
3364
|
+
* @example
|
|
3365
|
+
* import { Array } from "effect"
|
|
3366
|
+
*
|
|
3367
|
+
* const numbers = [1, 2, 3]
|
|
3368
|
+
* const copy = Array.copy(numbers)
|
|
3369
|
+
* assert.deepStrictEqual(copy, [1, 2, 3])
|
|
3370
|
+
*
|
|
3371
|
+
* @since 2.0.0
|
|
3372
|
+
*/
|
|
1758
3373
|
<A>(self: ReadonlyArray<A>): Array<A>
|
|
1759
3374
|
} = (<A>(self: ReadonlyArray<A>): Array<A> => self.slice()) as any
|
|
1760
3375
|
|
|
@@ -1786,12 +3401,91 @@ export const copy: {
|
|
|
1786
3401
|
* @since 2.0.0
|
|
1787
3402
|
*/
|
|
1788
3403
|
export const chunksOf: {
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
3404
|
+
/**
|
|
3405
|
+
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
3406
|
+
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
3407
|
+
* definition of `chunksOf`; it satisfies the property that
|
|
3408
|
+
*
|
|
3409
|
+
* ```ts
|
|
3410
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
3411
|
+
* ```
|
|
3412
|
+
*
|
|
3413
|
+
* whenever `n` evenly divides the length of `self`.
|
|
3414
|
+
*
|
|
3415
|
+
* @example
|
|
3416
|
+
* import { Array } from "effect"
|
|
3417
|
+
*
|
|
3418
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3419
|
+
* const result = Array.chunksOf(numbers, 2)
|
|
3420
|
+
* assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])
|
|
3421
|
+
*
|
|
3422
|
+
* // Explanation:
|
|
3423
|
+
* // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.
|
|
3424
|
+
* // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,
|
|
3425
|
+
* // the last chunk contains the remaining elements.
|
|
3426
|
+
* // The result is `[[1, 2], [3, 4], [5]]`.
|
|
3427
|
+
*
|
|
3428
|
+
* @category splitting
|
|
3429
|
+
* @since 2.0.0
|
|
3430
|
+
*/
|
|
3431
|
+
(n: number): <S extends Iterable<any>>(
|
|
1792
3432
|
self: S
|
|
1793
3433
|
) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>
|
|
3434
|
+
/**
|
|
3435
|
+
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
3436
|
+
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
3437
|
+
* definition of `chunksOf`; it satisfies the property that
|
|
3438
|
+
*
|
|
3439
|
+
* ```ts
|
|
3440
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
3441
|
+
* ```
|
|
3442
|
+
*
|
|
3443
|
+
* whenever `n` evenly divides the length of `self`.
|
|
3444
|
+
*
|
|
3445
|
+
* @example
|
|
3446
|
+
* import { Array } from "effect"
|
|
3447
|
+
*
|
|
3448
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3449
|
+
* const result = Array.chunksOf(numbers, 2)
|
|
3450
|
+
* assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])
|
|
3451
|
+
*
|
|
3452
|
+
* // Explanation:
|
|
3453
|
+
* // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.
|
|
3454
|
+
* // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,
|
|
3455
|
+
* // the last chunk contains the remaining elements.
|
|
3456
|
+
* // The result is `[[1, 2], [3, 4], [5]]`.
|
|
3457
|
+
*
|
|
3458
|
+
* @category splitting
|
|
3459
|
+
* @since 2.0.0
|
|
3460
|
+
*/
|
|
1794
3461
|
<A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>
|
|
3462
|
+
/**
|
|
3463
|
+
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
3464
|
+
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
3465
|
+
* definition of `chunksOf`; it satisfies the property that
|
|
3466
|
+
*
|
|
3467
|
+
* ```ts
|
|
3468
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
3469
|
+
* ```
|
|
3470
|
+
*
|
|
3471
|
+
* whenever `n` evenly divides the length of `self`.
|
|
3472
|
+
*
|
|
3473
|
+
* @example
|
|
3474
|
+
* import { Array } from "effect"
|
|
3475
|
+
*
|
|
3476
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3477
|
+
* const result = Array.chunksOf(numbers, 2)
|
|
3478
|
+
* assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])
|
|
3479
|
+
*
|
|
3480
|
+
* // Explanation:
|
|
3481
|
+
* // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.
|
|
3482
|
+
* // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,
|
|
3483
|
+
* // the last chunk contains the remaining elements.
|
|
3484
|
+
* // The result is `[[1, 2], [3, 4], [5]]`.
|
|
3485
|
+
*
|
|
3486
|
+
* @category splitting
|
|
3487
|
+
* @since 2.0.0
|
|
3488
|
+
*/
|
|
1795
3489
|
<A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>
|
|
1796
3490
|
} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {
|
|
1797
3491
|
const input = fromIterable(self)
|
|
@@ -1814,8 +3508,35 @@ export const chunksOf: {
|
|
|
1814
3508
|
* @since 2.0.0
|
|
1815
3509
|
*/
|
|
1816
3510
|
export const groupWith: {
|
|
3511
|
+
/**
|
|
3512
|
+
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.
|
|
3513
|
+
*
|
|
3514
|
+
* @example
|
|
3515
|
+
* import { Array } from "effect"
|
|
3516
|
+
*
|
|
3517
|
+
* const result = Array.groupWith(["a", "a", "b", "b", "b", "c", "a"], (x, y) => x === y)
|
|
3518
|
+
* assert.deepStrictEqual(result, [["a", "a"], ["b", "b", "b"], ["c"], ["a"]])
|
|
3519
|
+
*
|
|
3520
|
+
* @category grouping
|
|
3521
|
+
* @since 2.0.0
|
|
3522
|
+
*/
|
|
1817
3523
|
<A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>
|
|
1818
|
-
|
|
3524
|
+
/**
|
|
3525
|
+
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.
|
|
3526
|
+
*
|
|
3527
|
+
* @example
|
|
3528
|
+
* import { Array } from "effect"
|
|
3529
|
+
*
|
|
3530
|
+
* const result = Array.groupWith(["a", "a", "b", "b", "b", "c", "a"], (x, y) => x === y)
|
|
3531
|
+
* assert.deepStrictEqual(result, [["a", "a"], ["b", "b", "b"], ["c"], ["a"]])
|
|
3532
|
+
*
|
|
3533
|
+
* @category grouping
|
|
3534
|
+
* @since 2.0.0
|
|
3535
|
+
*/
|
|
3536
|
+
<A>(
|
|
3537
|
+
self: NonEmptyReadonlyArray<A>,
|
|
3538
|
+
isEquivalent: (self: A, that: A) => boolean
|
|
3539
|
+
): NonEmptyArray<NonEmptyArray<A>>
|
|
1819
3540
|
} = dual(
|
|
1820
3541
|
2,
|
|
1821
3542
|
<A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>
|
|
@@ -1873,9 +3594,51 @@ export const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmpt
|
|
|
1873
3594
|
* @since 2.0.0
|
|
1874
3595
|
*/
|
|
1875
3596
|
export const groupBy: {
|
|
3597
|
+
/**
|
|
3598
|
+
* Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
|
|
3599
|
+
* function on each element, and grouping the results according to values returned
|
|
3600
|
+
*
|
|
3601
|
+
* @example
|
|
3602
|
+
* import { Array } from "effect"
|
|
3603
|
+
*
|
|
3604
|
+
* const people = [
|
|
3605
|
+
* { name: "Alice", group: "A" },
|
|
3606
|
+
* { name: "Bob", group: "B" },
|
|
3607
|
+
* { name: "Charlie", group: "A" }
|
|
3608
|
+
* ]
|
|
3609
|
+
* const result = Array.groupBy(people, person => person.group)
|
|
3610
|
+
* assert.deepStrictEqual(result, {
|
|
3611
|
+
* A: [{ name: "Alice", group: "A" }, { name: "Charlie", group: "A" }],
|
|
3612
|
+
* B: [{ name: "Bob", group: "B" }]
|
|
3613
|
+
* })
|
|
3614
|
+
*
|
|
3615
|
+
* @category grouping
|
|
3616
|
+
* @since 2.0.0
|
|
3617
|
+
*/
|
|
1876
3618
|
<A, K extends string | symbol>(
|
|
1877
3619
|
f: (a: A) => K
|
|
1878
3620
|
): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>
|
|
3621
|
+
/**
|
|
3622
|
+
* Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
|
|
3623
|
+
* function on each element, and grouping the results according to values returned
|
|
3624
|
+
*
|
|
3625
|
+
* @example
|
|
3626
|
+
* import { Array } from "effect"
|
|
3627
|
+
*
|
|
3628
|
+
* const people = [
|
|
3629
|
+
* { name: "Alice", group: "A" },
|
|
3630
|
+
* { name: "Bob", group: "B" },
|
|
3631
|
+
* { name: "Charlie", group: "A" }
|
|
3632
|
+
* ]
|
|
3633
|
+
* const result = Array.groupBy(people, person => person.group)
|
|
3634
|
+
* assert.deepStrictEqual(result, {
|
|
3635
|
+
* A: [{ name: "Alice", group: "A" }, { name: "Charlie", group: "A" }],
|
|
3636
|
+
* B: [{ name: "Bob", group: "B" }]
|
|
3637
|
+
* })
|
|
3638
|
+
*
|
|
3639
|
+
* @category grouping
|
|
3640
|
+
* @since 2.0.0
|
|
3641
|
+
*/
|
|
1879
3642
|
<A, K extends string | symbol>(
|
|
1880
3643
|
self: Iterable<A>,
|
|
1881
3644
|
f: (a: A) => K
|
|
@@ -1910,21 +3673,77 @@ export const groupBy: {
|
|
|
1910
3673
|
* @since 2.0.0
|
|
1911
3674
|
*/
|
|
1912
3675
|
export const unionWith: {
|
|
3676
|
+
/**
|
|
3677
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
3678
|
+
*
|
|
3679
|
+
* @example
|
|
3680
|
+
* import { Array } from "effect"
|
|
3681
|
+
*
|
|
3682
|
+
* const array1 = [1, 2]
|
|
3683
|
+
* const array2 = [2, 3]
|
|
3684
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
3685
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
3686
|
+
*
|
|
3687
|
+
* @since 2.0.0
|
|
3688
|
+
*/
|
|
1913
3689
|
<S extends Iterable<any>, T extends Iterable<any>>(
|
|
1914
3690
|
that: T,
|
|
1915
3691
|
isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean
|
|
1916
3692
|
): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
|
|
3693
|
+
/**
|
|
3694
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
3695
|
+
*
|
|
3696
|
+
* @example
|
|
3697
|
+
* import { Array } from "effect"
|
|
3698
|
+
*
|
|
3699
|
+
* const array1 = [1, 2]
|
|
3700
|
+
* const array2 = [2, 3]
|
|
3701
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
3702
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
3703
|
+
*
|
|
3704
|
+
* @since 2.0.0
|
|
3705
|
+
*/
|
|
1917
3706
|
<A, B>(
|
|
1918
3707
|
self: NonEmptyReadonlyArray<A>,
|
|
1919
3708
|
that: Iterable<B>,
|
|
1920
3709
|
isEquivalent: (self: A, that: B) => boolean
|
|
1921
3710
|
): NonEmptyArray<A | B>
|
|
3711
|
+
/**
|
|
3712
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
3713
|
+
*
|
|
3714
|
+
* @example
|
|
3715
|
+
* import { Array } from "effect"
|
|
3716
|
+
*
|
|
3717
|
+
* const array1 = [1, 2]
|
|
3718
|
+
* const array2 = [2, 3]
|
|
3719
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
3720
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
3721
|
+
*
|
|
3722
|
+
* @since 2.0.0
|
|
3723
|
+
*/
|
|
1922
3724
|
<A, B>(
|
|
1923
3725
|
self: Iterable<A>,
|
|
1924
3726
|
that: NonEmptyReadonlyArray<B>,
|
|
1925
3727
|
isEquivalent: (self: A, that: B) => boolean
|
|
1926
3728
|
): NonEmptyArray<A | B>
|
|
1927
|
-
|
|
3729
|
+
/**
|
|
3730
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
3731
|
+
*
|
|
3732
|
+
* @example
|
|
3733
|
+
* import { Array } from "effect"
|
|
3734
|
+
*
|
|
3735
|
+
* const array1 = [1, 2]
|
|
3736
|
+
* const array2 = [2, 3]
|
|
3737
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
3738
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
3739
|
+
*
|
|
3740
|
+
* @since 2.0.0
|
|
3741
|
+
*/
|
|
3742
|
+
<A, B>(
|
|
3743
|
+
self: Iterable<A>,
|
|
3744
|
+
that: Iterable<B>,
|
|
3745
|
+
isEquivalent: (self: A, that: B) => boolean
|
|
3746
|
+
): Array<A | B>
|
|
1928
3747
|
} = dual(3, <A>(self: Iterable<A>, that: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {
|
|
1929
3748
|
const a = fromIterable(self)
|
|
1930
3749
|
const b = fromIterable(that)
|
|
@@ -1952,13 +3771,63 @@ export const unionWith: {
|
|
|
1952
3771
|
* @since 2.0.0
|
|
1953
3772
|
*/
|
|
1954
3773
|
export const union: {
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
3774
|
+
/**
|
|
3775
|
+
* Creates a union of two arrays, removing duplicates.
|
|
3776
|
+
*
|
|
3777
|
+
* @example
|
|
3778
|
+
* import { Array } from "effect"
|
|
3779
|
+
*
|
|
3780
|
+
* const array1 = [1, 2]
|
|
3781
|
+
* const array2 = [2, 3]
|
|
3782
|
+
* const result = Array.union(array1, array2)
|
|
3783
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
3784
|
+
*
|
|
3785
|
+
* @since 2.0.0
|
|
3786
|
+
*/
|
|
3787
|
+
<T extends Iterable<any>>(that: T): <S extends Iterable<any>>(
|
|
1958
3788
|
self: S
|
|
1959
3789
|
) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
|
|
3790
|
+
/**
|
|
3791
|
+
* Creates a union of two arrays, removing duplicates.
|
|
3792
|
+
*
|
|
3793
|
+
* @example
|
|
3794
|
+
* import { Array } from "effect"
|
|
3795
|
+
*
|
|
3796
|
+
* const array1 = [1, 2]
|
|
3797
|
+
* const array2 = [2, 3]
|
|
3798
|
+
* const result = Array.union(array1, array2)
|
|
3799
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
3800
|
+
*
|
|
3801
|
+
* @since 2.0.0
|
|
3802
|
+
*/
|
|
1960
3803
|
<A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>
|
|
3804
|
+
/**
|
|
3805
|
+
* Creates a union of two arrays, removing duplicates.
|
|
3806
|
+
*
|
|
3807
|
+
* @example
|
|
3808
|
+
* import { Array } from "effect"
|
|
3809
|
+
*
|
|
3810
|
+
* const array1 = [1, 2]
|
|
3811
|
+
* const array2 = [2, 3]
|
|
3812
|
+
* const result = Array.union(array1, array2)
|
|
3813
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
3814
|
+
*
|
|
3815
|
+
* @since 2.0.0
|
|
3816
|
+
*/
|
|
1961
3817
|
<A, B>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>
|
|
3818
|
+
/**
|
|
3819
|
+
* Creates a union of two arrays, removing duplicates.
|
|
3820
|
+
*
|
|
3821
|
+
* @example
|
|
3822
|
+
* import { Array } from "effect"
|
|
3823
|
+
*
|
|
3824
|
+
* const array1 = [1, 2]
|
|
3825
|
+
* const array2 = [2, 3]
|
|
3826
|
+
* const result = Array.union(array1, array2)
|
|
3827
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
3828
|
+
*
|
|
3829
|
+
* @since 2.0.0
|
|
3830
|
+
*/
|
|
1962
3831
|
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>
|
|
1963
3832
|
} = dual(2, <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => unionWith(self, that, _equivalence))
|
|
1964
3833
|
|
|
@@ -2003,7 +3872,35 @@ export const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean)
|
|
|
2003
3872
|
* @since 2.0.0
|
|
2004
3873
|
*/
|
|
2005
3874
|
export const intersection: {
|
|
3875
|
+
/**
|
|
3876
|
+
* Creates an `Array` of unique values that are included in all given `Iterable`s.
|
|
3877
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
3878
|
+
*
|
|
3879
|
+
* @example
|
|
3880
|
+
* import { Array } from "effect"
|
|
3881
|
+
*
|
|
3882
|
+
* const array1 = [1, 2, 3]
|
|
3883
|
+
* const array2 = [3, 4, 1]
|
|
3884
|
+
* const result = Array.intersection(array1, array2)
|
|
3885
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
3886
|
+
*
|
|
3887
|
+
* @since 2.0.0
|
|
3888
|
+
*/
|
|
2006
3889
|
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>
|
|
3890
|
+
/**
|
|
3891
|
+
* Creates an `Array` of unique values that are included in all given `Iterable`s.
|
|
3892
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
3893
|
+
*
|
|
3894
|
+
* @example
|
|
3895
|
+
* import { Array } from "effect"
|
|
3896
|
+
*
|
|
3897
|
+
* const array1 = [1, 2, 3]
|
|
3898
|
+
* const array2 = [3, 4, 1]
|
|
3899
|
+
* const result = Array.intersection(array1, array2)
|
|
3900
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
3901
|
+
*
|
|
3902
|
+
* @since 2.0.0
|
|
3903
|
+
*/
|
|
2007
3904
|
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>
|
|
2008
3905
|
} = intersectionWith(_equivalence)
|
|
2009
3906
|
|
|
@@ -2047,7 +3944,35 @@ export const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean):
|
|
|
2047
3944
|
* @since 2.0.0
|
|
2048
3945
|
*/
|
|
2049
3946
|
export const difference: {
|
|
3947
|
+
/**
|
|
3948
|
+
* Creates a `Array` of values not included in the other given `Iterable`.
|
|
3949
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
3950
|
+
*
|
|
3951
|
+
* @example
|
|
3952
|
+
* import { Array } from "effect"
|
|
3953
|
+
*
|
|
3954
|
+
* const array1 = [1, 2, 3]
|
|
3955
|
+
* const array2 = [2, 3, 4]
|
|
3956
|
+
* const difference = Array.difference(array1, array2)
|
|
3957
|
+
* assert.deepStrictEqual(difference, [1])
|
|
3958
|
+
*
|
|
3959
|
+
* @since 2.0.0
|
|
3960
|
+
*/
|
|
2050
3961
|
<A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>
|
|
3962
|
+
/**
|
|
3963
|
+
* Creates a `Array` of values not included in the other given `Iterable`.
|
|
3964
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
3965
|
+
*
|
|
3966
|
+
* @example
|
|
3967
|
+
* import { Array } from "effect"
|
|
3968
|
+
*
|
|
3969
|
+
* const array1 = [1, 2, 3]
|
|
3970
|
+
* const array2 = [2, 3, 4]
|
|
3971
|
+
* const difference = Array.difference(array1, array2)
|
|
3972
|
+
* assert.deepStrictEqual(difference, [1])
|
|
3973
|
+
*
|
|
3974
|
+
* @since 2.0.0
|
|
3975
|
+
*/
|
|
2051
3976
|
<A>(self: Iterable<A>, that: Iterable<A>): Array<A>
|
|
2052
3977
|
} = differenceWith(_equivalence)
|
|
2053
3978
|
|
|
@@ -2118,9 +4043,17 @@ export declare namespace ReadonlyArray {
|
|
|
2118
4043
|
* @since 2.0.0
|
|
2119
4044
|
*/
|
|
2120
4045
|
export const map: {
|
|
4046
|
+
/**
|
|
4047
|
+
* @category mapping
|
|
4048
|
+
* @since 2.0.0
|
|
4049
|
+
*/
|
|
2121
4050
|
<S extends ReadonlyArray<any>, B>(
|
|
2122
4051
|
f: (a: ReadonlyArray.Infer<S>, i: number) => B
|
|
2123
4052
|
): (self: S) => ReadonlyArray.With<S, B>
|
|
4053
|
+
/**
|
|
4054
|
+
* @category mapping
|
|
4055
|
+
* @since 2.0.0
|
|
4056
|
+
*/
|
|
2124
4057
|
<S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>
|
|
2125
4058
|
} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))
|
|
2126
4059
|
|
|
@@ -2131,10 +4064,31 @@ export const map: {
|
|
|
2131
4064
|
* @since 2.0.0
|
|
2132
4065
|
*/
|
|
2133
4066
|
export const flatMap: {
|
|
4067
|
+
/**
|
|
4068
|
+
* Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.
|
|
4069
|
+
*
|
|
4070
|
+
* @category sequencing
|
|
4071
|
+
* @since 2.0.0
|
|
4072
|
+
*/
|
|
2134
4073
|
<S extends ReadonlyArray<any>, T extends ReadonlyArray<any>>(
|
|
2135
4074
|
f: (a: ReadonlyArray.Infer<S>, i: number) => T
|
|
2136
4075
|
): (self: S) => ReadonlyArray.AndNonEmpty<S, T, ReadonlyArray.Infer<T>>
|
|
2137
|
-
|
|
4076
|
+
/**
|
|
4077
|
+
* Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.
|
|
4078
|
+
*
|
|
4079
|
+
* @category sequencing
|
|
4080
|
+
* @since 2.0.0
|
|
4081
|
+
*/
|
|
4082
|
+
<A, B>(
|
|
4083
|
+
self: NonEmptyReadonlyArray<A>,
|
|
4084
|
+
f: (a: A, i: number) => NonEmptyReadonlyArray<B>
|
|
4085
|
+
): NonEmptyArray<B>
|
|
4086
|
+
/**
|
|
4087
|
+
* Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.
|
|
4088
|
+
*
|
|
4089
|
+
* @category sequencing
|
|
4090
|
+
* @since 2.0.0
|
|
4091
|
+
*/
|
|
2138
4092
|
<A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>
|
|
2139
4093
|
} = dual(
|
|
2140
4094
|
2,
|
|
@@ -2190,9 +4144,41 @@ export const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) =>
|
|
|
2190
4144
|
* @since 2.0.0
|
|
2191
4145
|
*/
|
|
2192
4146
|
export const filterMap: {
|
|
4147
|
+
/**
|
|
4148
|
+
* Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.
|
|
4149
|
+
* This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.
|
|
4150
|
+
*
|
|
4151
|
+
* @example
|
|
4152
|
+
* import { Array, Option } from "effect";
|
|
4153
|
+
*
|
|
4154
|
+
* const data = [1, 2, 3, 4, 5];
|
|
4155
|
+
* const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
4156
|
+
* const result = Array.filterMap(data, evenSquares);
|
|
4157
|
+
*
|
|
4158
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
4159
|
+
*
|
|
4160
|
+
* @category filtering
|
|
4161
|
+
* @since 2.0.0
|
|
4162
|
+
*/
|
|
2193
4163
|
<A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>
|
|
2194
|
-
|
|
2195
|
-
|
|
4164
|
+
/**
|
|
4165
|
+
* Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.
|
|
4166
|
+
* This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.
|
|
4167
|
+
*
|
|
4168
|
+
* @example
|
|
4169
|
+
* import { Array, Option } from "effect";
|
|
4170
|
+
*
|
|
4171
|
+
* const data = [1, 2, 3, 4, 5];
|
|
4172
|
+
* const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
4173
|
+
* const result = Array.filterMap(data, evenSquares);
|
|
4174
|
+
*
|
|
4175
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
4176
|
+
*
|
|
4177
|
+
* @category filtering
|
|
4178
|
+
* @since 2.0.0
|
|
4179
|
+
*/
|
|
4180
|
+
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>
|
|
4181
|
+
} = dual(
|
|
2196
4182
|
2,
|
|
2197
4183
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B> => {
|
|
2198
4184
|
const as = fromIterable(self)
|
|
@@ -2225,7 +4211,41 @@ export const filterMap: {
|
|
|
2225
4211
|
* @since 2.0.0
|
|
2226
4212
|
*/
|
|
2227
4213
|
export const filterMapWhile: {
|
|
4214
|
+
/**
|
|
4215
|
+
* Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.
|
|
4216
|
+
* This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.
|
|
4217
|
+
* This is useful when you need to transform an array but only up to the point where a certain condition holds true.
|
|
4218
|
+
*
|
|
4219
|
+
* @example
|
|
4220
|
+
* import { Array, Option } from "effect";
|
|
4221
|
+
*
|
|
4222
|
+
* const data = [2, 4, 5];
|
|
4223
|
+
* const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
4224
|
+
* const result = Array.filterMapWhile(data, toSquareTillOdd);
|
|
4225
|
+
*
|
|
4226
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
4227
|
+
*
|
|
4228
|
+
* @category filtering
|
|
4229
|
+
* @since 2.0.0
|
|
4230
|
+
*/
|
|
2228
4231
|
<A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>
|
|
4232
|
+
/**
|
|
4233
|
+
* Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.
|
|
4234
|
+
* This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.
|
|
4235
|
+
* This is useful when you need to transform an array but only up to the point where a certain condition holds true.
|
|
4236
|
+
*
|
|
4237
|
+
* @example
|
|
4238
|
+
* import { Array, Option } from "effect";
|
|
4239
|
+
*
|
|
4240
|
+
* const data = [2, 4, 5];
|
|
4241
|
+
* const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
4242
|
+
* const result = Array.filterMapWhile(data, toSquareTillOdd);
|
|
4243
|
+
*
|
|
4244
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
4245
|
+
*
|
|
4246
|
+
* @category filtering
|
|
4247
|
+
* @since 2.0.0
|
|
4248
|
+
*/
|
|
2229
4249
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>
|
|
2230
4250
|
} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>) => {
|
|
2231
4251
|
let i = 0
|
|
@@ -2266,7 +4286,53 @@ export const filterMapWhile: {
|
|
|
2266
4286
|
* @since 2.0.0
|
|
2267
4287
|
*/
|
|
2268
4288
|
export const partitionMap: {
|
|
4289
|
+
/**
|
|
4290
|
+
* Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.
|
|
4291
|
+
* This function is particularly useful for operations where each element can result in two possible types,
|
|
4292
|
+
* and you want to separate these types into different collections. For instance, separating validation results
|
|
4293
|
+
* into successes and failures.
|
|
4294
|
+
*
|
|
4295
|
+
* @example
|
|
4296
|
+
* import { Array, Either } from "effect";
|
|
4297
|
+
*
|
|
4298
|
+
* const data = [1, 2, 3, 4, 5]
|
|
4299
|
+
* const isEven = (x: number) => x % 2 === 0
|
|
4300
|
+
* const partitioned = Array.partitionMap(data, x =>
|
|
4301
|
+
* isEven(x) ? Either.right(x) : Either.left(x)
|
|
4302
|
+
* )
|
|
4303
|
+
*
|
|
4304
|
+
* assert.deepStrictEqual(partitioned, [
|
|
4305
|
+
* [1, 3, 5],
|
|
4306
|
+
* [2, 4]
|
|
4307
|
+
* ])
|
|
4308
|
+
*
|
|
4309
|
+
* @category filtering
|
|
4310
|
+
* @since 2.0.0
|
|
4311
|
+
*/
|
|
2269
4312
|
<A, B, C>(f: (a: A, i: number) => array_<C, B>): (self: Iterable<A>) => [left: Array<B>, right: Array<C>]
|
|
4313
|
+
/**
|
|
4314
|
+
* Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.
|
|
4315
|
+
* This function is particularly useful for operations where each element can result in two possible types,
|
|
4316
|
+
* and you want to separate these types into different collections. For instance, separating validation results
|
|
4317
|
+
* into successes and failures.
|
|
4318
|
+
*
|
|
4319
|
+
* @example
|
|
4320
|
+
* import { Array, Either } from "effect";
|
|
4321
|
+
*
|
|
4322
|
+
* const data = [1, 2, 3, 4, 5]
|
|
4323
|
+
* const isEven = (x: number) => x % 2 === 0
|
|
4324
|
+
* const partitioned = Array.partitionMap(data, x =>
|
|
4325
|
+
* isEven(x) ? Either.right(x) : Either.left(x)
|
|
4326
|
+
* )
|
|
4327
|
+
*
|
|
4328
|
+
* assert.deepStrictEqual(partitioned, [
|
|
4329
|
+
* [1, 3, 5],
|
|
4330
|
+
* [2, 4]
|
|
4331
|
+
* ])
|
|
4332
|
+
*
|
|
4333
|
+
* @category filtering
|
|
4334
|
+
* @since 2.0.0
|
|
4335
|
+
*/
|
|
2270
4336
|
<A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>]
|
|
2271
4337
|
} = dual(
|
|
2272
4338
|
2,
|
|
@@ -2362,9 +4428,25 @@ export const getRights = <T extends Iterable<array_<any, any>>>(
|
|
|
2362
4428
|
* @since 2.0.0
|
|
2363
4429
|
*/
|
|
2364
4430
|
export const filter: {
|
|
4431
|
+
/**
|
|
4432
|
+
* @category filtering
|
|
4433
|
+
* @since 2.0.0
|
|
4434
|
+
*/
|
|
2365
4435
|
<A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>
|
|
4436
|
+
/**
|
|
4437
|
+
* @category filtering
|
|
4438
|
+
* @since 2.0.0
|
|
4439
|
+
*/
|
|
2366
4440
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>
|
|
4441
|
+
/**
|
|
4442
|
+
* @category filtering
|
|
4443
|
+
* @since 2.0.0
|
|
4444
|
+
*/
|
|
2367
4445
|
<A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>
|
|
4446
|
+
/**
|
|
4447
|
+
* @category filtering
|
|
4448
|
+
* @since 2.0.0
|
|
4449
|
+
*/
|
|
2368
4450
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>
|
|
2369
4451
|
} = dual(
|
|
2370
4452
|
2,
|
|
@@ -2387,16 +4469,40 @@ export const filter: {
|
|
|
2387
4469
|
* @since 2.0.0
|
|
2388
4470
|
*/
|
|
2389
4471
|
export const partition: {
|
|
4472
|
+
/**
|
|
4473
|
+
* Separate elements based on a predicate that also exposes the index of the element.
|
|
4474
|
+
*
|
|
4475
|
+
* @category filtering
|
|
4476
|
+
* @since 2.0.0
|
|
4477
|
+
*/
|
|
2390
4478
|
<A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (
|
|
2391
4479
|
self: Iterable<A>
|
|
2392
4480
|
) => [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]
|
|
4481
|
+
/**
|
|
4482
|
+
* Separate elements based on a predicate that also exposes the index of the element.
|
|
4483
|
+
*
|
|
4484
|
+
* @category filtering
|
|
4485
|
+
* @since 2.0.0
|
|
4486
|
+
*/
|
|
2393
4487
|
<A>(
|
|
2394
4488
|
predicate: (a: NoInfer<A>, i: number) => boolean
|
|
2395
4489
|
): (self: Iterable<A>) => [excluded: Array<A>, satisfying: Array<A>]
|
|
4490
|
+
/**
|
|
4491
|
+
* Separate elements based on a predicate that also exposes the index of the element.
|
|
4492
|
+
*
|
|
4493
|
+
* @category filtering
|
|
4494
|
+
* @since 2.0.0
|
|
4495
|
+
*/
|
|
2396
4496
|
<A, B extends A>(
|
|
2397
4497
|
self: Iterable<A>,
|
|
2398
4498
|
refinement: (a: A, i: number) => a is B
|
|
2399
4499
|
): [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]
|
|
4500
|
+
/**
|
|
4501
|
+
* Separate elements based on a predicate that also exposes the index of the element.
|
|
4502
|
+
*
|
|
4503
|
+
* @category filtering
|
|
4504
|
+
* @since 2.0.0
|
|
4505
|
+
*/
|
|
2400
4506
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>]
|
|
2401
4507
|
} = dual(
|
|
2402
4508
|
2,
|
|
@@ -2448,7 +4554,33 @@ export const separate: <T extends Iterable<array_<any, any>>>(
|
|
|
2448
4554
|
* @since 2.0.0
|
|
2449
4555
|
*/
|
|
2450
4556
|
export const reduce: {
|
|
4557
|
+
/**
|
|
4558
|
+
* Reduces an array from the left.
|
|
4559
|
+
*
|
|
4560
|
+
* @example
|
|
4561
|
+
* import { Array } from "effect"
|
|
4562
|
+
*
|
|
4563
|
+
* const numbers = [1, 2, 3]
|
|
4564
|
+
* const result = Array.reduce(numbers, 0, (acc, n) => acc + n)
|
|
4565
|
+
* assert.deepStrictEqual(result, 6)
|
|
4566
|
+
*
|
|
4567
|
+
* @category folding
|
|
4568
|
+
* @since 2.0.0
|
|
4569
|
+
*/
|
|
2451
4570
|
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B
|
|
4571
|
+
/**
|
|
4572
|
+
* Reduces an array from the left.
|
|
4573
|
+
*
|
|
4574
|
+
* @example
|
|
4575
|
+
* import { Array } from "effect"
|
|
4576
|
+
*
|
|
4577
|
+
* const numbers = [1, 2, 3]
|
|
4578
|
+
* const result = Array.reduce(numbers, 0, (acc, n) => acc + n)
|
|
4579
|
+
* assert.deepStrictEqual(result, 6)
|
|
4580
|
+
*
|
|
4581
|
+
* @category folding
|
|
4582
|
+
* @since 2.0.0
|
|
4583
|
+
*/
|
|
2452
4584
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
2453
4585
|
} = dual(
|
|
2454
4586
|
3,
|
|
@@ -2470,7 +4602,33 @@ export const reduce: {
|
|
|
2470
4602
|
* @since 2.0.0
|
|
2471
4603
|
*/
|
|
2472
4604
|
export const reduceRight: {
|
|
4605
|
+
/**
|
|
4606
|
+
* Reduces an array from the right.
|
|
4607
|
+
*
|
|
4608
|
+
* @example
|
|
4609
|
+
* import { Array } from "effect"
|
|
4610
|
+
*
|
|
4611
|
+
* const numbers = [1, 2, 3]
|
|
4612
|
+
* const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)
|
|
4613
|
+
* assert.deepStrictEqual(result, 6)
|
|
4614
|
+
*
|
|
4615
|
+
* @category folding
|
|
4616
|
+
* @since 2.0.0
|
|
4617
|
+
*/
|
|
2473
4618
|
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B
|
|
4619
|
+
/**
|
|
4620
|
+
* Reduces an array from the right.
|
|
4621
|
+
*
|
|
4622
|
+
* @example
|
|
4623
|
+
* import { Array } from "effect"
|
|
4624
|
+
*
|
|
4625
|
+
* const numbers = [1, 2, 3]
|
|
4626
|
+
* const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)
|
|
4627
|
+
* assert.deepStrictEqual(result, 6)
|
|
4628
|
+
*
|
|
4629
|
+
* @category folding
|
|
4630
|
+
* @since 2.0.0
|
|
4631
|
+
*/
|
|
2474
4632
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
2475
4633
|
} = dual(
|
|
2476
4634
|
3,
|
|
@@ -2494,6 +4652,20 @@ export const reduceRight: {
|
|
|
2494
4652
|
*/
|
|
2495
4653
|
export const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.
|
|
2496
4654
|
<A, B extends A>(refinement: Refinement<A, B>): (a: A) => Array<B>
|
|
4655
|
+
/**
|
|
4656
|
+
* Lifts a predicate into an array.
|
|
4657
|
+
*
|
|
4658
|
+
* @example
|
|
4659
|
+
* import { Array } from "effect"
|
|
4660
|
+
*
|
|
4661
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
4662
|
+
* const to = Array.liftPredicate(isEven)
|
|
4663
|
+
* assert.deepStrictEqual(to(1), [])
|
|
4664
|
+
* assert.deepStrictEqual(to(2), [2])
|
|
4665
|
+
*
|
|
4666
|
+
* @category lifting
|
|
4667
|
+
* @since 2.0.0
|
|
4668
|
+
*/
|
|
2497
4669
|
<A>(predicate: Predicate<A>): <B extends A>(b: B) => Array<B>
|
|
2498
4670
|
} = <A>(predicate: Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []
|
|
2499
4671
|
|
|
@@ -2540,7 +4712,43 @@ export const liftNullable = <A extends Array<unknown>, B>(
|
|
|
2540
4712
|
* @since 2.0.0
|
|
2541
4713
|
*/
|
|
2542
4714
|
export const flatMapNullable: {
|
|
4715
|
+
/**
|
|
4716
|
+
* Maps over an array and flattens the result, removing null and undefined values.
|
|
4717
|
+
*
|
|
4718
|
+
* @example
|
|
4719
|
+
* import { Array } from "effect"
|
|
4720
|
+
*
|
|
4721
|
+
* const numbers = [1, 2, 3]
|
|
4722
|
+
* const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))
|
|
4723
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
4724
|
+
*
|
|
4725
|
+
* // Explanation:
|
|
4726
|
+
* // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers
|
|
4727
|
+
* // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened
|
|
4728
|
+
* // to remove null values, resulting in [1, 3].
|
|
4729
|
+
*
|
|
4730
|
+
* @category sequencing
|
|
4731
|
+
* @since 2.0.0
|
|
4732
|
+
*/
|
|
2543
4733
|
<A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>
|
|
4734
|
+
/**
|
|
4735
|
+
* Maps over an array and flattens the result, removing null and undefined values.
|
|
4736
|
+
*
|
|
4737
|
+
* @example
|
|
4738
|
+
* import { Array } from "effect"
|
|
4739
|
+
*
|
|
4740
|
+
* const numbers = [1, 2, 3]
|
|
4741
|
+
* const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))
|
|
4742
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
4743
|
+
*
|
|
4744
|
+
* // Explanation:
|
|
4745
|
+
* // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers
|
|
4746
|
+
* // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened
|
|
4747
|
+
* // to remove null values, resulting in [1, 3].
|
|
4748
|
+
*
|
|
4749
|
+
* @category sequencing
|
|
4750
|
+
* @since 2.0.0
|
|
4751
|
+
*/
|
|
2544
4752
|
<A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>
|
|
2545
4753
|
} = dual(
|
|
2546
4754
|
2,
|
|
@@ -2590,11 +4798,35 @@ export const liftEither = <A extends Array<unknown>, E, B>(
|
|
|
2590
4798
|
* @since 2.0.0
|
|
2591
4799
|
*/
|
|
2592
4800
|
export const every: {
|
|
4801
|
+
/**
|
|
4802
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
4803
|
+
*
|
|
4804
|
+
* @category elements
|
|
4805
|
+
* @since 2.0.0
|
|
4806
|
+
*/
|
|
2593
4807
|
<A, B extends A>(
|
|
2594
4808
|
refinement: (a: NoInfer<A>, i: number) => a is B
|
|
2595
4809
|
): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>
|
|
4810
|
+
/**
|
|
4811
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
4812
|
+
*
|
|
4813
|
+
* @category elements
|
|
4814
|
+
* @since 2.0.0
|
|
4815
|
+
*/
|
|
2596
4816
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => boolean
|
|
4817
|
+
/**
|
|
4818
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
4819
|
+
*
|
|
4820
|
+
* @category elements
|
|
4821
|
+
* @since 2.0.0
|
|
4822
|
+
*/
|
|
2597
4823
|
<A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B>
|
|
4824
|
+
/**
|
|
4825
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
4826
|
+
*
|
|
4827
|
+
* @category elements
|
|
4828
|
+
* @since 2.0.0
|
|
4829
|
+
*/
|
|
2598
4830
|
<A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): boolean
|
|
2599
4831
|
} = dual(
|
|
2600
4832
|
2,
|
|
@@ -2609,9 +4841,19 @@ export const every: {
|
|
|
2609
4841
|
* @since 2.0.0
|
|
2610
4842
|
*/
|
|
2611
4843
|
export const some: {
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
4844
|
+
/**
|
|
4845
|
+
* Check if a predicate holds true for some `ReadonlyArray` element.
|
|
4846
|
+
*
|
|
4847
|
+
* @category elements
|
|
4848
|
+
* @since 2.0.0
|
|
4849
|
+
*/
|
|
4850
|
+
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>
|
|
4851
|
+
/**
|
|
4852
|
+
* Check if a predicate holds true for some `ReadonlyArray` element.
|
|
4853
|
+
*
|
|
4854
|
+
* @category elements
|
|
4855
|
+
* @since 2.0.0
|
|
4856
|
+
*/
|
|
2615
4857
|
<A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>
|
|
2616
4858
|
} = dual(
|
|
2617
4859
|
2,
|
|
@@ -2638,7 +4880,43 @@ export const some: {
|
|
|
2638
4880
|
* @since 2.0.0
|
|
2639
4881
|
*/
|
|
2640
4882
|
export const extend: {
|
|
4883
|
+
/**
|
|
4884
|
+
* Extends an array with a function that maps each subarray to a value.
|
|
4885
|
+
*
|
|
4886
|
+
* @example
|
|
4887
|
+
* import { Array } from "effect"
|
|
4888
|
+
*
|
|
4889
|
+
* const numbers = [1, 2, 3]
|
|
4890
|
+
* const result = Array.extend(numbers, as => as.length)
|
|
4891
|
+
* assert.deepStrictEqual(result, [3, 2, 1])
|
|
4892
|
+
*
|
|
4893
|
+
* // Explanation:
|
|
4894
|
+
* // The function maps each subarray starting from each element to its length.
|
|
4895
|
+
* // The subarrays are: [1, 2, 3], [2, 3], [3].
|
|
4896
|
+
* // The lengths are: 3, 2, 1.
|
|
4897
|
+
* // Therefore, the result is [3, 2, 1].
|
|
4898
|
+
*
|
|
4899
|
+
* @since 2.0.0
|
|
4900
|
+
*/
|
|
2641
4901
|
<A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>
|
|
4902
|
+
/**
|
|
4903
|
+
* Extends an array with a function that maps each subarray to a value.
|
|
4904
|
+
*
|
|
4905
|
+
* @example
|
|
4906
|
+
* import { Array } from "effect"
|
|
4907
|
+
*
|
|
4908
|
+
* const numbers = [1, 2, 3]
|
|
4909
|
+
* const result = Array.extend(numbers, as => as.length)
|
|
4910
|
+
* assert.deepStrictEqual(result, [3, 2, 1])
|
|
4911
|
+
*
|
|
4912
|
+
* // Explanation:
|
|
4913
|
+
* // The function maps each subarray starting from each element to its length.
|
|
4914
|
+
* // The subarrays are: [1, 2, 3], [2, 3], [3].
|
|
4915
|
+
* // The lengths are: 3, 2, 1.
|
|
4916
|
+
* // Therefore, the result is [3, 2, 1].
|
|
4917
|
+
*
|
|
4918
|
+
* @since 2.0.0
|
|
4919
|
+
*/
|
|
2642
4920
|
<A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>
|
|
2643
4921
|
} = dual(
|
|
2644
4922
|
2,
|
|
@@ -2657,7 +4935,29 @@ export const extend: {
|
|
|
2657
4935
|
* @since 2.0.0
|
|
2658
4936
|
*/
|
|
2659
4937
|
export const min: {
|
|
4938
|
+
/**
|
|
4939
|
+
* Finds the minimum element in an array based on a comparator.
|
|
4940
|
+
*
|
|
4941
|
+
* @example
|
|
4942
|
+
* import { Array, Order } from "effect"
|
|
4943
|
+
*
|
|
4944
|
+
* const min = Array.min([3, 1, 2], Order.number)
|
|
4945
|
+
* assert.deepStrictEqual(min, 1)
|
|
4946
|
+
*
|
|
4947
|
+
* @since 2.0.0
|
|
4948
|
+
*/
|
|
2660
4949
|
<A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A
|
|
4950
|
+
/**
|
|
4951
|
+
* Finds the minimum element in an array based on a comparator.
|
|
4952
|
+
*
|
|
4953
|
+
* @example
|
|
4954
|
+
* import { Array, Order } from "effect"
|
|
4955
|
+
*
|
|
4956
|
+
* const min = Array.min([3, 1, 2], Order.number)
|
|
4957
|
+
* assert.deepStrictEqual(min, 1)
|
|
4958
|
+
*
|
|
4959
|
+
* @since 2.0.0
|
|
4960
|
+
*/
|
|
2661
4961
|
<A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A
|
|
2662
4962
|
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))
|
|
2663
4963
|
|
|
@@ -2673,7 +4973,29 @@ export const min: {
|
|
|
2673
4973
|
* @since 2.0.0
|
|
2674
4974
|
*/
|
|
2675
4975
|
export const max: {
|
|
4976
|
+
/**
|
|
4977
|
+
* Finds the maximum element in an array based on a comparator.
|
|
4978
|
+
*
|
|
4979
|
+
* @example
|
|
4980
|
+
* import { Array, Order } from "effect"
|
|
4981
|
+
*
|
|
4982
|
+
* const max = Array.max([3, 1, 2], Order.number)
|
|
4983
|
+
* assert.deepStrictEqual(max, 3)
|
|
4984
|
+
*
|
|
4985
|
+
* @since 2.0.0
|
|
4986
|
+
*/
|
|
2676
4987
|
<A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A
|
|
4988
|
+
/**
|
|
4989
|
+
* Finds the maximum element in an array based on a comparator.
|
|
4990
|
+
*
|
|
4991
|
+
* @example
|
|
4992
|
+
* import { Array, Order } from "effect"
|
|
4993
|
+
*
|
|
4994
|
+
* const max = Array.max([3, 1, 2], Order.number)
|
|
4995
|
+
* assert.deepStrictEqual(max, 3)
|
|
4996
|
+
*
|
|
4997
|
+
* @since 2.0.0
|
|
4998
|
+
*/
|
|
2677
4999
|
<A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A
|
|
2678
5000
|
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))
|
|
2679
5001
|
|
|
@@ -2734,7 +5056,29 @@ export const getEquivalence: <A>(
|
|
|
2734
5056
|
* @since 2.0.0
|
|
2735
5057
|
*/
|
|
2736
5058
|
export const forEach: {
|
|
5059
|
+
/**
|
|
5060
|
+
* Performs a side-effect for each element of the `Iterable`.
|
|
5061
|
+
*
|
|
5062
|
+
* @example
|
|
5063
|
+
* import { Array } from "effect"
|
|
5064
|
+
*
|
|
5065
|
+
* const numbers = [1, 2, 3]
|
|
5066
|
+
* Array.forEach(numbers, n => console.log(n)) // 1, 2, 3
|
|
5067
|
+
*
|
|
5068
|
+
* @since 2.0.0
|
|
5069
|
+
*/
|
|
2737
5070
|
<A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void
|
|
5071
|
+
/**
|
|
5072
|
+
* Performs a side-effect for each element of the `Iterable`.
|
|
5073
|
+
*
|
|
5074
|
+
* @example
|
|
5075
|
+
* import { Array } from "effect"
|
|
5076
|
+
*
|
|
5077
|
+
* const numbers = [1, 2, 3]
|
|
5078
|
+
* Array.forEach(numbers, n => console.log(n)) // 1, 2, 3
|
|
5079
|
+
*
|
|
5080
|
+
* @since 2.0.0
|
|
5081
|
+
*/
|
|
2738
5082
|
<A>(self: Iterable<A>, f: (a: A, i: number) => void): void
|
|
2739
5083
|
} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))
|
|
2740
5084
|
|
|
@@ -2752,10 +5096,52 @@ export const forEach: {
|
|
|
2752
5096
|
* @since 2.0.0
|
|
2753
5097
|
*/
|
|
2754
5098
|
export const dedupeWith: {
|
|
5099
|
+
/**
|
|
5100
|
+
* Remove duplicates from an `Iterable` using the provided `isEquivalent` function,
|
|
5101
|
+
* preserving the order of the first occurrence of each element.
|
|
5102
|
+
*
|
|
5103
|
+
* @example
|
|
5104
|
+
* import { Array } from "effect"
|
|
5105
|
+
*
|
|
5106
|
+
* const numbers = [1, 2, 2, 3, 3, 3]
|
|
5107
|
+
* const unique = Array.dedupeWith(numbers, (a, b) => a === b)
|
|
5108
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5109
|
+
*
|
|
5110
|
+
* @since 2.0.0
|
|
5111
|
+
*/
|
|
2755
5112
|
<S extends Iterable<any>>(
|
|
2756
5113
|
isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean
|
|
2757
5114
|
): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
|
|
2758
|
-
|
|
5115
|
+
/**
|
|
5116
|
+
* Remove duplicates from an `Iterable` using the provided `isEquivalent` function,
|
|
5117
|
+
* preserving the order of the first occurrence of each element.
|
|
5118
|
+
*
|
|
5119
|
+
* @example
|
|
5120
|
+
* import { Array } from "effect"
|
|
5121
|
+
*
|
|
5122
|
+
* const numbers = [1, 2, 2, 3, 3, 3]
|
|
5123
|
+
* const unique = Array.dedupeWith(numbers, (a, b) => a === b)
|
|
5124
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5125
|
+
*
|
|
5126
|
+
* @since 2.0.0
|
|
5127
|
+
*/
|
|
5128
|
+
<A>(
|
|
5129
|
+
self: NonEmptyReadonlyArray<A>,
|
|
5130
|
+
isEquivalent: (self: A, that: A) => boolean
|
|
5131
|
+
): NonEmptyArray<A>
|
|
5132
|
+
/**
|
|
5133
|
+
* Remove duplicates from an `Iterable` using the provided `isEquivalent` function,
|
|
5134
|
+
* preserving the order of the first occurrence of each element.
|
|
5135
|
+
*
|
|
5136
|
+
* @example
|
|
5137
|
+
* import { Array } from "effect"
|
|
5138
|
+
*
|
|
5139
|
+
* const numbers = [1, 2, 2, 3, 3, 3]
|
|
5140
|
+
* const unique = Array.dedupeWith(numbers, (a, b) => a === b)
|
|
5141
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5142
|
+
*
|
|
5143
|
+
* @since 2.0.0
|
|
5144
|
+
*/
|
|
2759
5145
|
<A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>
|
|
2760
5146
|
} = dual(
|
|
2761
5147
|
2,
|
|
@@ -2799,7 +5185,31 @@ export const dedupe = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(
|
|
|
2799
5185
|
* @since 2.0.0
|
|
2800
5186
|
*/
|
|
2801
5187
|
export const dedupeAdjacentWith: {
|
|
5188
|
+
/**
|
|
5189
|
+
* Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.
|
|
5190
|
+
*
|
|
5191
|
+
* @example
|
|
5192
|
+
* import { Array } from "effect"
|
|
5193
|
+
*
|
|
5194
|
+
* const numbers = [1, 1, 2, 2, 3, 3]
|
|
5195
|
+
* const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)
|
|
5196
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5197
|
+
*
|
|
5198
|
+
* @since 2.0.0
|
|
5199
|
+
*/
|
|
2802
5200
|
<A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>
|
|
5201
|
+
/**
|
|
5202
|
+
* Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.
|
|
5203
|
+
*
|
|
5204
|
+
* @example
|
|
5205
|
+
* import { Array } from "effect"
|
|
5206
|
+
*
|
|
5207
|
+
* const numbers = [1, 1, 2, 2, 3, 3]
|
|
5208
|
+
* const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)
|
|
5209
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5210
|
+
*
|
|
5211
|
+
* @since 2.0.0
|
|
5212
|
+
*/
|
|
2803
5213
|
<A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>
|
|
2804
5214
|
} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {
|
|
2805
5215
|
const out: Array<A> = []
|
|
@@ -2841,7 +5251,33 @@ export const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacent
|
|
|
2841
5251
|
* @category folding
|
|
2842
5252
|
*/
|
|
2843
5253
|
export const join: {
|
|
5254
|
+
/**
|
|
5255
|
+
* Joins the elements together with "sep" in the middle.
|
|
5256
|
+
*
|
|
5257
|
+
* @example
|
|
5258
|
+
* import { Array } from "effect"
|
|
5259
|
+
*
|
|
5260
|
+
* const strings = ["a", "b", "c"]
|
|
5261
|
+
* const joined = Array.join(strings, "-")
|
|
5262
|
+
* assert.deepStrictEqual(joined, "a-b-c")
|
|
5263
|
+
*
|
|
5264
|
+
* @since 2.0.0
|
|
5265
|
+
* @category folding
|
|
5266
|
+
*/
|
|
2844
5267
|
(sep: string): (self: Iterable<string>) => string
|
|
5268
|
+
/**
|
|
5269
|
+
* Joins the elements together with "sep" in the middle.
|
|
5270
|
+
*
|
|
5271
|
+
* @example
|
|
5272
|
+
* import { Array } from "effect"
|
|
5273
|
+
*
|
|
5274
|
+
* const strings = ["a", "b", "c"]
|
|
5275
|
+
* const joined = Array.join(strings, "-")
|
|
5276
|
+
* assert.deepStrictEqual(joined, "a-b-c")
|
|
5277
|
+
*
|
|
5278
|
+
* @since 2.0.0
|
|
5279
|
+
* @category folding
|
|
5280
|
+
*/
|
|
2845
5281
|
(self: Iterable<string>, sep: string): string
|
|
2846
5282
|
} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))
|
|
2847
5283
|
|
|
@@ -2859,10 +5295,36 @@ export const join: {
|
|
|
2859
5295
|
* @category folding
|
|
2860
5296
|
*/
|
|
2861
5297
|
export const mapAccum: {
|
|
5298
|
+
/**
|
|
5299
|
+
* Statefully maps over the chunk, producing new elements of type `B`.
|
|
5300
|
+
*
|
|
5301
|
+
* @example
|
|
5302
|
+
* import { Array } from "effect"
|
|
5303
|
+
*
|
|
5304
|
+
* const numbers = [1, 2, 3]
|
|
5305
|
+
* const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])
|
|
5306
|
+
* assert.deepStrictEqual(result, [6, [1, 3, 6]])
|
|
5307
|
+
*
|
|
5308
|
+
* @since 2.0.0
|
|
5309
|
+
* @category folding
|
|
5310
|
+
*/
|
|
2862
5311
|
<S, A, B>(
|
|
2863
5312
|
s: S,
|
|
2864
5313
|
f: (s: S, a: A, i: number) => readonly [S, B]
|
|
2865
5314
|
): (self: Iterable<A>) => [state: S, mappedArray: Array<B>]
|
|
5315
|
+
/**
|
|
5316
|
+
* Statefully maps over the chunk, producing new elements of type `B`.
|
|
5317
|
+
*
|
|
5318
|
+
* @example
|
|
5319
|
+
* import { Array } from "effect"
|
|
5320
|
+
*
|
|
5321
|
+
* const numbers = [1, 2, 3]
|
|
5322
|
+
* const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])
|
|
5323
|
+
* assert.deepStrictEqual(result, [6, [1, 3, 6]])
|
|
5324
|
+
*
|
|
5325
|
+
* @since 2.0.0
|
|
5326
|
+
* @category folding
|
|
5327
|
+
*/
|
|
2866
5328
|
<S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => readonly [S, B]): [state: S, mappedArray: Array<B>]
|
|
2867
5329
|
} = dual(
|
|
2868
5330
|
3,
|
|
@@ -2895,7 +5357,35 @@ export const mapAccum: {
|
|
|
2895
5357
|
* @category elements
|
|
2896
5358
|
*/
|
|
2897
5359
|
export const cartesianWith: {
|
|
5360
|
+
/**
|
|
5361
|
+
* Zips this chunk crosswise with the specified chunk using the specified combiner.
|
|
5362
|
+
*
|
|
5363
|
+
* @example
|
|
5364
|
+
* import { Array } from "effect"
|
|
5365
|
+
*
|
|
5366
|
+
* const array1 = [1, 2]
|
|
5367
|
+
* const array2 = ["a", "b"]
|
|
5368
|
+
* const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)
|
|
5369
|
+
* assert.deepStrictEqual(product, ["1-a", "1-b", "2-a", "2-b"])
|
|
5370
|
+
*
|
|
5371
|
+
* @since 2.0.0
|
|
5372
|
+
* @category elements
|
|
5373
|
+
*/
|
|
2898
5374
|
<A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>
|
|
5375
|
+
/**
|
|
5376
|
+
* Zips this chunk crosswise with the specified chunk using the specified combiner.
|
|
5377
|
+
*
|
|
5378
|
+
* @example
|
|
5379
|
+
* import { Array } from "effect"
|
|
5380
|
+
*
|
|
5381
|
+
* const array1 = [1, 2]
|
|
5382
|
+
* const array2 = ["a", "b"]
|
|
5383
|
+
* const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)
|
|
5384
|
+
* assert.deepStrictEqual(product, ["1-a", "1-b", "2-a", "2-b"])
|
|
5385
|
+
*
|
|
5386
|
+
* @since 2.0.0
|
|
5387
|
+
* @category elements
|
|
5388
|
+
*/
|
|
2899
5389
|
<A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>
|
|
2900
5390
|
} = dual(
|
|
2901
5391
|
3,
|
|
@@ -2918,7 +5408,35 @@ export const cartesianWith: {
|
|
|
2918
5408
|
* @category elements
|
|
2919
5409
|
*/
|
|
2920
5410
|
export const cartesian: {
|
|
5411
|
+
/**
|
|
5412
|
+
* Zips this chunk crosswise with the specified chunk.
|
|
5413
|
+
*
|
|
5414
|
+
* @example
|
|
5415
|
+
* import { Array } from "effect"
|
|
5416
|
+
*
|
|
5417
|
+
* const array1 = [1, 2]
|
|
5418
|
+
* const array2 = ["a", "b"]
|
|
5419
|
+
* const product = Array.cartesian(array1, array2)
|
|
5420
|
+
* assert.deepStrictEqual(product, [[1, "a"], [1, "b"], [2, "a"], [2, "b"]])
|
|
5421
|
+
*
|
|
5422
|
+
* @since 2.0.0
|
|
5423
|
+
* @category elements
|
|
5424
|
+
*/
|
|
2921
5425
|
<B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>
|
|
5426
|
+
/**
|
|
5427
|
+
* Zips this chunk crosswise with the specified chunk.
|
|
5428
|
+
*
|
|
5429
|
+
* @example
|
|
5430
|
+
* import { Array } from "effect"
|
|
5431
|
+
*
|
|
5432
|
+
* const array1 = [1, 2]
|
|
5433
|
+
* const array2 = ["a", "b"]
|
|
5434
|
+
* const product = Array.cartesian(array1, array2)
|
|
5435
|
+
* assert.deepStrictEqual(product, [[1, "a"], [1, "b"], [2, "a"], [2, "b"]])
|
|
5436
|
+
*
|
|
5437
|
+
* @since 2.0.0
|
|
5438
|
+
* @category elements
|
|
5439
|
+
*/
|
|
2922
5440
|
<A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>
|
|
2923
5441
|
} = dual(
|
|
2924
5442
|
2,
|
|
@@ -3018,12 +5536,95 @@ export const Do: ReadonlyArray<{}> = of({})
|
|
|
3018
5536
|
* @since 3.2.0
|
|
3019
5537
|
*/
|
|
3020
5538
|
export const bind: {
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
5539
|
+
/**
|
|
5540
|
+
* The "do simulation" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.
|
|
5541
|
+
*
|
|
5542
|
+
* It can be used to simulate "array comprehension".
|
|
5543
|
+
* It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.
|
|
5544
|
+
*
|
|
5545
|
+
* Here's how the do simulation works:
|
|
5546
|
+
*
|
|
5547
|
+
* 1. Start the do simulation using the `Do` value
|
|
5548
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
5549
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
5550
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
5551
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
5552
|
+
*
|
|
5553
|
+
* @see {@link bindTo}
|
|
5554
|
+
* @see {@link Do}
|
|
5555
|
+
* @see {@link let_ let}
|
|
5556
|
+
*
|
|
5557
|
+
* @example
|
|
5558
|
+
* import { Array as Arr, pipe } from "effect"
|
|
5559
|
+
* const doResult = pipe(
|
|
5560
|
+
* Arr.Do,
|
|
5561
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
5562
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
5563
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
5564
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
5565
|
+
* )
|
|
5566
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
5567
|
+
*
|
|
5568
|
+
* // equivalent
|
|
5569
|
+
* const x = [1, 3, 5],
|
|
5570
|
+
* y = [2, 4, 6],
|
|
5571
|
+
* result = [];
|
|
5572
|
+
* for(let i = 0; i < x.length; i++) {
|
|
5573
|
+
* for(let j = 0; j < y.length; j++) {
|
|
5574
|
+
* const _x = x[i], _y = y[j];
|
|
5575
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
5576
|
+
* }
|
|
5577
|
+
* }
|
|
5578
|
+
*
|
|
5579
|
+
* @category do notation
|
|
5580
|
+
* @since 3.2.0
|
|
5581
|
+
*/
|
|
5582
|
+
<A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: A) => ReadonlyArray<B>): (
|
|
3025
5583
|
self: ReadonlyArray<A>
|
|
3026
5584
|
) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
|
|
5585
|
+
/**
|
|
5586
|
+
* The "do simulation" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.
|
|
5587
|
+
*
|
|
5588
|
+
* It can be used to simulate "array comprehension".
|
|
5589
|
+
* It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.
|
|
5590
|
+
*
|
|
5591
|
+
* Here's how the do simulation works:
|
|
5592
|
+
*
|
|
5593
|
+
* 1. Start the do simulation using the `Do` value
|
|
5594
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
5595
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
5596
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
5597
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
5598
|
+
*
|
|
5599
|
+
* @see {@link bindTo}
|
|
5600
|
+
* @see {@link Do}
|
|
5601
|
+
* @see {@link let_ let}
|
|
5602
|
+
*
|
|
5603
|
+
* @example
|
|
5604
|
+
* import { Array as Arr, pipe } from "effect"
|
|
5605
|
+
* const doResult = pipe(
|
|
5606
|
+
* Arr.Do,
|
|
5607
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
5608
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
5609
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
5610
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
5611
|
+
* )
|
|
5612
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
5613
|
+
*
|
|
5614
|
+
* // equivalent
|
|
5615
|
+
* const x = [1, 3, 5],
|
|
5616
|
+
* y = [2, 4, 6],
|
|
5617
|
+
* result = [];
|
|
5618
|
+
* for(let i = 0; i < x.length; i++) {
|
|
5619
|
+
* for(let j = 0; j < y.length; j++) {
|
|
5620
|
+
* const _x = x[i], _y = y[j];
|
|
5621
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
5622
|
+
* }
|
|
5623
|
+
* }
|
|
5624
|
+
*
|
|
5625
|
+
* @category do notation
|
|
5626
|
+
* @since 3.2.0
|
|
5627
|
+
*/
|
|
3027
5628
|
<A extends object, N extends string, B>(
|
|
3028
5629
|
self: ReadonlyArray<A>,
|
|
3029
5630
|
tag: Exclude<N, keyof A>,
|
|
@@ -3075,7 +5676,93 @@ export const bind: {
|
|
|
3075
5676
|
* @since 3.2.0
|
|
3076
5677
|
*/
|
|
3077
5678
|
export const bindTo: {
|
|
5679
|
+
/**
|
|
5680
|
+
* The "do simulation" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.
|
|
5681
|
+
*
|
|
5682
|
+
* It can be used to simulate "array comprehension".
|
|
5683
|
+
* It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.
|
|
5684
|
+
*
|
|
5685
|
+
* Here's how the do simulation works:
|
|
5686
|
+
*
|
|
5687
|
+
* 1. Start the do simulation using the `Do` value
|
|
5688
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
5689
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
5690
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
5691
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
5692
|
+
*
|
|
5693
|
+
* @see {@link bindTo}
|
|
5694
|
+
* @see {@link Do}
|
|
5695
|
+
* @see {@link let_ let}
|
|
5696
|
+
*
|
|
5697
|
+
* @example
|
|
5698
|
+
* import { Array as Arr, pipe } from "effect"
|
|
5699
|
+
* const doResult = pipe(
|
|
5700
|
+
* Arr.Do,
|
|
5701
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
5702
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
5703
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
5704
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
5705
|
+
* )
|
|
5706
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
5707
|
+
*
|
|
5708
|
+
* // equivalent
|
|
5709
|
+
* const x = [1, 3, 5],
|
|
5710
|
+
* y = [2, 4, 6],
|
|
5711
|
+
* result = [];
|
|
5712
|
+
* for(let i = 0; i < x.length; i++) {
|
|
5713
|
+
* for(let j = 0; j < y.length; j++) {
|
|
5714
|
+
* const _x = x[i], _y = y[j];
|
|
5715
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
5716
|
+
* }
|
|
5717
|
+
* }
|
|
5718
|
+
*
|
|
5719
|
+
* @category do notation
|
|
5720
|
+
* @since 3.2.0
|
|
5721
|
+
*/
|
|
3078
5722
|
<N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>
|
|
5723
|
+
/**
|
|
5724
|
+
* The "do simulation" for array allows you to sequentially apply operations to the elements of arrays, just as nested loops allow you to go through all combinations of elements in an arrays.
|
|
5725
|
+
*
|
|
5726
|
+
* It can be used to simulate "array comprehension".
|
|
5727
|
+
* It's a technique that allows you to create new arrays by iterating over existing ones and applying specific **conditions** or **transformations** to the elements. It's like assembling a new collection from pieces of other collections based on certain rules.
|
|
5728
|
+
*
|
|
5729
|
+
* Here's how the do simulation works:
|
|
5730
|
+
*
|
|
5731
|
+
* 1. Start the do simulation using the `Do` value
|
|
5732
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
5733
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
5734
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
5735
|
+
* 5. Regular `Option` functions like `map` and `filter` can still be used within the do simulation. These functions will receive the accumulated variables as arguments within the scope
|
|
5736
|
+
*
|
|
5737
|
+
* @see {@link bindTo}
|
|
5738
|
+
* @see {@link Do}
|
|
5739
|
+
* @see {@link let_ let}
|
|
5740
|
+
*
|
|
5741
|
+
* @example
|
|
5742
|
+
* import { Array as Arr, pipe } from "effect"
|
|
5743
|
+
* const doResult = pipe(
|
|
5744
|
+
* Arr.Do,
|
|
5745
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
5746
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
5747
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
5748
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
5749
|
+
* )
|
|
5750
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
5751
|
+
*
|
|
5752
|
+
* // equivalent
|
|
5753
|
+
* const x = [1, 3, 5],
|
|
5754
|
+
* y = [2, 4, 6],
|
|
5755
|
+
* result = [];
|
|
5756
|
+
* for(let i = 0; i < x.length; i++) {
|
|
5757
|
+
* for(let j = 0; j < y.length; j++) {
|
|
5758
|
+
* const _x = x[i], _y = y[j];
|
|
5759
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
5760
|
+
* }
|
|
5761
|
+
* }
|
|
5762
|
+
*
|
|
5763
|
+
* @category do notation
|
|
5764
|
+
* @since 3.2.0
|
|
5765
|
+
*/
|
|
3079
5766
|
<A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>
|
|
3080
5767
|
} = doNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any
|
|
3081
5768
|
|