effect 3.8.4 → 3.9.0
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 +24 -3
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/BigDecimal.js +5 -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 +3 -0
- 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 +3 -0
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/DateTime.js +6 -0
- 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 +3 -0
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/Effect.js +122 -35
- 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 +3 -0
- package/dist/cjs/FiberHandle.js.map +1 -1
- package/dist/cjs/FiberId.js.map +1 -1
- package/dist/cjs/FiberMap.js +3 -0
- 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 +3 -0
- 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/Inspectable.js +15 -1
- package/dist/cjs/Inspectable.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 +6 -0
- 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/ManagedRuntime.js +16 -1
- package/dist/cjs/ManagedRuntime.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 +6 -0
- package/dist/cjs/Micro.js.map +1 -1
- package/dist/cjs/MutableHashMap.js +3 -0
- package/dist/cjs/MutableHashMap.js.map +1 -1
- package/dist/cjs/MutableHashSet.js +3 -0
- package/dist/cjs/MutableHashSet.js.map +1 -1
- package/dist/cjs/MutableList.js +3 -0
- package/dist/cjs/MutableList.js.map +1 -1
- package/dist/cjs/MutableQueue.js +3 -0
- package/dist/cjs/MutableQueue.js.map +1 -1
- package/dist/cjs/MutableRef.js +3 -0
- 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 +18 -2
- 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/RegExp.js +20 -1
- package/dist/cjs/RegExp.js.map +1 -1
- package/dist/cjs/Request.js.map +1 -1
- package/dist/cjs/RequestResolver.js.map +1 -1
- package/dist/cjs/Resource.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.map +1 -1
- package/dist/cjs/ScopedRef.js.map +1 -1
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/SortedMap.js +3 -0
- package/dist/cjs/SortedMap.js.map +1 -1
- package/dist/cjs/SortedSet.js +3 -0
- 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 +21 -2
- 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/cause.js +3 -0
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/context.js +6 -1
- package/dist/cjs/internal/context.js.map +1 -1
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +16 -3
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/effect/circular.js +5 -1
- package/dist/cjs/internal/effect/circular.js.map +1 -1
- package/dist/cjs/internal/fiberId.js +9 -0
- package/dist/cjs/internal/fiberId.js.map +1 -1
- package/dist/cjs/internal/hashMap.js +3 -0
- package/dist/cjs/internal/hashMap.js.map +1 -1
- package/dist/cjs/internal/hashSet.js +3 -0
- package/dist/cjs/internal/hashSet.js.map +1 -1
- package/dist/cjs/internal/layer.js +33 -19
- package/dist/cjs/internal/layer.js.map +1 -1
- package/dist/cjs/internal/mailbox.js +3 -0
- package/dist/cjs/internal/mailbox.js.map +1 -1
- package/dist/cjs/internal/managedRuntime/circular.js +10 -0
- package/dist/cjs/internal/managedRuntime/circular.js.map +1 -0
- package/dist/cjs/internal/managedRuntime.js +23 -9
- package/dist/cjs/internal/managedRuntime.js.map +1 -1
- package/dist/cjs/internal/option.js +3 -0
- package/dist/cjs/internal/option.js.map +1 -1
- package/dist/cjs/internal/pool.js +6 -1
- package/dist/cjs/internal/pool.js.map +1 -1
- package/dist/cjs/internal/redBlackTree.js +3 -0
- package/dist/cjs/internal/redBlackTree.js.map +1 -1
- package/dist/cjs/internal/resource.js +15 -5
- package/dist/cjs/internal/resource.js.map +1 -1
- package/dist/cjs/internal/runtime.js +4 -1
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/scopedRef.js +11 -8
- package/dist/cjs/internal/scopedRef.js.map +1 -1
- package/dist/cjs/internal/stm/core.js +1 -2
- package/dist/cjs/internal/stm/core.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/trie.js +3 -0
- package/dist/cjs/internal/trie.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +2735 -2
- 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 +234 -3
- 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 +171 -1
- 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 +4350 -13
- 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 +315 -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/Inspectable.d.ts +15 -0
- package/dist/dts/Inspectable.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 +460 -5
- 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/ManagedRuntime.d.ts +41 -2
- package/dist/dts/ManagedRuntime.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 +1110 -0
- 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 +37 -1
- package/dist/dts/Pool.d.ts.map +1 -1
- package/dist/dts/Predicate.d.ts +513 -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 +106 -2
- 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/RegExp.d.ts +12 -2
- package/dist/dts/RegExp.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/Resource.d.ts +21 -1
- package/dist/dts/Resource.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 +36 -0
- package/dist/dts/Scope.d.ts.map +1 -1
- package/dist/dts/ScopedRef.d.ts +43 -1
- 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 +203 -0
- package/dist/dts/Tuple.d.ts.map +1 -1
- package/dist/dts/Types.d.ts +39 -0
- package/dist/dts/Types.d.ts.map +1 -1
- package/dist/dts/Unify.d.ts +26 -13
- 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/core.d.ts.map +1 -1
- package/dist/dts/internal/hashMap.d.ts.map +1 -1
- package/dist/dts/internal/layer.d.ts.map +1 -1
- package/dist/dts/internal/managedRuntime/circular.d.ts +2 -0
- package/dist/dts/internal/managedRuntime/circular.d.ts.map +1 -0
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Array.js +21 -0
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/BigDecimal.js +6 -3
- 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 +4 -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 +4 -1
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/DateTime.js +6 -0
- 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 +4 -1
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/Effect.js +116 -30
- 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 +3 -0
- package/dist/esm/FiberHandle.js.map +1 -1
- package/dist/esm/FiberId.js.map +1 -1
- package/dist/esm/FiberMap.js +3 -0
- 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 +3 -0
- 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/Inspectable.js +14 -0
- package/dist/esm/Inspectable.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 +7 -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/ManagedRuntime.js +15 -0
- package/dist/esm/ManagedRuntime.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 +7 -1
- package/dist/esm/Micro.js.map +1 -1
- package/dist/esm/MutableHashMap.js +4 -1
- package/dist/esm/MutableHashMap.js.map +1 -1
- package/dist/esm/MutableHashSet.js +4 -1
- package/dist/esm/MutableHashSet.js.map +1 -1
- package/dist/esm/MutableList.js +4 -1
- package/dist/esm/MutableList.js.map +1 -1
- package/dist/esm/MutableQueue.js +4 -1
- package/dist/esm/MutableQueue.js.map +1 -1
- package/dist/esm/MutableRef.js +4 -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 +15 -0
- 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/RegExp.js +16 -0
- package/dist/esm/RegExp.js.map +1 -1
- package/dist/esm/Request.js.map +1 -1
- package/dist/esm/RequestResolver.js.map +1 -1
- package/dist/esm/Resource.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.map +1 -1
- package/dist/esm/ScopedRef.js.map +1 -1
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/SortedMap.js +4 -1
- package/dist/esm/SortedMap.js.map +1 -1
- package/dist/esm/SortedSet.js +4 -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 +19 -0
- 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/cause.js +4 -1
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/context.js +7 -2
- package/dist/esm/internal/context.js.map +1 -1
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +14 -2
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/effect/circular.js +5 -1
- package/dist/esm/internal/effect/circular.js.map +1 -1
- package/dist/esm/internal/fiberId.js +10 -1
- package/dist/esm/internal/fiberId.js.map +1 -1
- package/dist/esm/internal/hashMap.js +4 -1
- package/dist/esm/internal/hashMap.js.map +1 -1
- package/dist/esm/internal/hashSet.js +4 -1
- package/dist/esm/internal/hashSet.js.map +1 -1
- package/dist/esm/internal/layer.js +32 -18
- package/dist/esm/internal/layer.js.map +1 -1
- package/dist/esm/internal/mailbox.js +3 -0
- package/dist/esm/internal/mailbox.js.map +1 -1
- package/dist/esm/internal/managedRuntime/circular.js +4 -0
- package/dist/esm/internal/managedRuntime/circular.js.map +1 -0
- package/dist/esm/internal/managedRuntime.js +21 -8
- package/dist/esm/internal/managedRuntime.js.map +1 -1
- package/dist/esm/internal/option.js +4 -1
- package/dist/esm/internal/option.js.map +1 -1
- package/dist/esm/internal/pool.js +6 -1
- package/dist/esm/internal/pool.js.map +1 -1
- package/dist/esm/internal/redBlackTree.js +4 -1
- package/dist/esm/internal/redBlackTree.js.map +1 -1
- package/dist/esm/internal/resource.js +15 -5
- package/dist/esm/internal/resource.js.map +1 -1
- package/dist/esm/internal/runtime.js +4 -1
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/scopedRef.js +11 -8
- package/dist/esm/internal/scopedRef.js.map +1 -1
- package/dist/esm/internal/stm/core.js +1 -2
- package/dist/esm/internal/stm/core.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/trie.js +4 -1
- package/dist/esm/internal/trie.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Array.ts +2791 -40
- package/src/BigDecimal.ts +589 -19
- 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 +822 -5
- 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 +234 -3
- package/src/Cron.ts +16 -1
- package/src/Data.ts +165 -0
- package/src/DateTime.ts +1012 -50
- package/src/Deferred.ts +171 -1
- package/src/Differ.ts +89 -27
- package/src/Duration.ts +160 -17
- package/src/Effect.ts +4717 -164
- 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 +45 -0
- package/src/FiberId.ts +24 -0
- package/src/FiberMap.ts +147 -21
- package/src/FiberRef.ts +80 -0
- package/src/FiberRefs.ts +84 -0
- package/src/FiberRefsPatch.ts +35 -1
- package/src/FiberSet.ts +41 -0
- package/src/Function.ts +416 -31
- package/src/GroupBy.ts +38 -0
- package/src/Hash.ts +8 -0
- package/src/HashMap.ts +316 -0
- package/src/HashSet.ts +284 -0
- package/src/Inspectable.ts +22 -0
- package/src/Iterable.ts +456 -6
- package/src/KeyedPool.ts +34 -0
- package/src/Layer.ts +475 -38
- package/src/List.ts +483 -4
- package/src/LogLevel.ts +46 -0
- package/src/Logger.ts +195 -4
- package/src/Mailbox.ts +16 -0
- package/src/ManagedRuntime.ts +46 -2
- 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 +1223 -61
- package/src/MutableHashMap.ts +109 -2
- package/src/MutableHashSet.ts +28 -1
- package/src/MutableList.ts +40 -1
- package/src/MutableQueue.ts +66 -1
- package/src/MutableRef.ts +60 -1
- 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 +42 -1
- package/src/Predicate.ts +514 -0
- package/src/PubSub.ts +28 -0
- package/src/Queue.ts +106 -2
- 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/RegExp.ts +17 -0
- package/src/Request.ts +76 -0
- package/src/RequestResolver.ts +145 -4
- package/src/Resource.ts +22 -1
- 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 +36 -0
- package/src/ScopedRef.ts +44 -1
- package/src/Sink.ts +464 -0
- package/src/SortedMap.ts +80 -1
- package/src/SortedSet.ts +147 -4
- 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 +223 -8
- package/src/Types.ts +41 -0
- package/src/Unify.ts +28 -17
- package/src/UpstreamPullRequest.ts +12 -0
- package/src/UpstreamPullStrategy.ts +12 -0
- package/src/Utils.ts +1 -15
- package/src/internal/cause.ts +4 -1
- package/src/internal/context.ts +7 -2
- package/src/internal/core-effect.ts +7 -7
- package/src/internal/core.ts +14 -2
- package/src/internal/effect/circular.ts +8 -2
- package/src/internal/fiberId.ts +10 -1
- package/src/internal/hashMap.ts +4 -1
- package/src/internal/hashSet.ts +4 -1
- package/src/internal/layer.ts +105 -38
- package/src/internal/mailbox.ts +3 -0
- package/src/internal/managedRuntime/circular.ts +6 -0
- package/src/internal/managedRuntime.ts +36 -22
- package/src/internal/option.ts +4 -1
- package/src/internal/pool.ts +7 -1
- package/src/internal/redBlackTree.ts +4 -1
- package/src/internal/resource.ts +16 -5
- package/src/internal/runtime.ts +4 -1
- package/src/internal/scopedRef.ts +12 -8
- package/src/internal/stm/core.ts +2 -3
- package/src/internal/stream.ts +27 -0
- package/src/internal/trie.ts +4 -1
- 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,10 +3345,94 @@ 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
|
|
|
3376
|
+
/**
|
|
3377
|
+
* Pads an array.
|
|
3378
|
+
* Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.
|
|
3379
|
+
* If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.
|
|
3380
|
+
* If `n` is less than or equal to 0, the returned array will be an empty array.
|
|
3381
|
+
*
|
|
3382
|
+
* @example
|
|
3383
|
+
* import { Array } from "effect"
|
|
3384
|
+
*
|
|
3385
|
+
* const arr = [1, 2, 3]
|
|
3386
|
+
* const result = Array.pad(arr, 6, 0)
|
|
3387
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])
|
|
3388
|
+
*
|
|
3389
|
+
* @since 3.8.4
|
|
3390
|
+
*/
|
|
3391
|
+
export const pad: {
|
|
3392
|
+
/**
|
|
3393
|
+
* Pads an array.
|
|
3394
|
+
* Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.
|
|
3395
|
+
* If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.
|
|
3396
|
+
* If `n` is less than or equal to 0, the returned array will be an empty array.
|
|
3397
|
+
*
|
|
3398
|
+
* @example
|
|
3399
|
+
* import { Array } from "effect"
|
|
3400
|
+
*
|
|
3401
|
+
* const arr = [1, 2, 3]
|
|
3402
|
+
* const result = Array.pad(arr, 6, 0)
|
|
3403
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])
|
|
3404
|
+
*
|
|
3405
|
+
* @since 3.8.4
|
|
3406
|
+
*/
|
|
3407
|
+
<A, T>(n: number, fill: T): (
|
|
3408
|
+
self: Array<A>
|
|
3409
|
+
) => Array<A | T>
|
|
3410
|
+
/**
|
|
3411
|
+
* Pads an array.
|
|
3412
|
+
* Returns a new array of length `n` with the elements of `array` followed by `fill` elements if `array` is shorter than `n`.
|
|
3413
|
+
* If `array` is longer than `n`, the returned array will be a slice of `array` containing the `n` first elements of `array`.
|
|
3414
|
+
* If `n` is less than or equal to 0, the returned array will be an empty array.
|
|
3415
|
+
*
|
|
3416
|
+
* @example
|
|
3417
|
+
* import { Array } from "effect"
|
|
3418
|
+
*
|
|
3419
|
+
* const arr = [1, 2, 3]
|
|
3420
|
+
* const result = Array.pad(arr, 6, 0)
|
|
3421
|
+
* assert.deepStrictEqual(result, [1, 2, 3, 0, 0, 0])
|
|
3422
|
+
*
|
|
3423
|
+
* @since 3.8.4
|
|
3424
|
+
*/
|
|
3425
|
+
<A, T>(self: Array<A>, n: number, fill: T): Array<A | T>
|
|
3426
|
+
} = dual(3, <A, T>(self: Array<A>, n: number, fill: T): Array<A | T> => {
|
|
3427
|
+
if (self.length >= n) {
|
|
3428
|
+
return take(self, n)
|
|
3429
|
+
}
|
|
3430
|
+
return appendAll(
|
|
3431
|
+
self,
|
|
3432
|
+
makeBy(n - self.length, () => fill)
|
|
3433
|
+
)
|
|
3434
|
+
})
|
|
3435
|
+
|
|
1761
3436
|
/**
|
|
1762
3437
|
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
1763
3438
|
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
@@ -1786,12 +3461,91 @@ export const copy: {
|
|
|
1786
3461
|
* @since 2.0.0
|
|
1787
3462
|
*/
|
|
1788
3463
|
export const chunksOf: {
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
3464
|
+
/**
|
|
3465
|
+
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
3466
|
+
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
3467
|
+
* definition of `chunksOf`; it satisfies the property that
|
|
3468
|
+
*
|
|
3469
|
+
* ```ts
|
|
3470
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
3471
|
+
* ```
|
|
3472
|
+
*
|
|
3473
|
+
* whenever `n` evenly divides the length of `self`.
|
|
3474
|
+
*
|
|
3475
|
+
* @example
|
|
3476
|
+
* import { Array } from "effect"
|
|
3477
|
+
*
|
|
3478
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3479
|
+
* const result = Array.chunksOf(numbers, 2)
|
|
3480
|
+
* assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])
|
|
3481
|
+
*
|
|
3482
|
+
* // Explanation:
|
|
3483
|
+
* // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.
|
|
3484
|
+
* // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,
|
|
3485
|
+
* // the last chunk contains the remaining elements.
|
|
3486
|
+
* // The result is `[[1, 2], [3, 4], [5]]`.
|
|
3487
|
+
*
|
|
3488
|
+
* @category splitting
|
|
3489
|
+
* @since 2.0.0
|
|
3490
|
+
*/
|
|
3491
|
+
(n: number): <S extends Iterable<any>>(
|
|
1792
3492
|
self: S
|
|
1793
3493
|
) => ReadonlyArray.With<S, NonEmptyArray<ReadonlyArray.Infer<S>>>
|
|
3494
|
+
/**
|
|
3495
|
+
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
3496
|
+
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
3497
|
+
* definition of `chunksOf`; it satisfies the property that
|
|
3498
|
+
*
|
|
3499
|
+
* ```ts
|
|
3500
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
3501
|
+
* ```
|
|
3502
|
+
*
|
|
3503
|
+
* whenever `n` evenly divides the length of `self`.
|
|
3504
|
+
*
|
|
3505
|
+
* @example
|
|
3506
|
+
* import { Array } from "effect"
|
|
3507
|
+
*
|
|
3508
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3509
|
+
* const result = Array.chunksOf(numbers, 2)
|
|
3510
|
+
* assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])
|
|
3511
|
+
*
|
|
3512
|
+
* // Explanation:
|
|
3513
|
+
* // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.
|
|
3514
|
+
* // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,
|
|
3515
|
+
* // the last chunk contains the remaining elements.
|
|
3516
|
+
* // The result is `[[1, 2], [3, 4], [5]]`.
|
|
3517
|
+
*
|
|
3518
|
+
* @category splitting
|
|
3519
|
+
* @since 2.0.0
|
|
3520
|
+
*/
|
|
1794
3521
|
<A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>
|
|
3522
|
+
/**
|
|
3523
|
+
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
3524
|
+
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
3525
|
+
* definition of `chunksOf`; it satisfies the property that
|
|
3526
|
+
*
|
|
3527
|
+
* ```ts
|
|
3528
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
3529
|
+
* ```
|
|
3530
|
+
*
|
|
3531
|
+
* whenever `n` evenly divides the length of `self`.
|
|
3532
|
+
*
|
|
3533
|
+
* @example
|
|
3534
|
+
* import { Array } from "effect"
|
|
3535
|
+
*
|
|
3536
|
+
* const numbers = [1, 2, 3, 4, 5]
|
|
3537
|
+
* const result = Array.chunksOf(numbers, 2)
|
|
3538
|
+
* assert.deepStrictEqual(result, [[1, 2], [3, 4], [5]])
|
|
3539
|
+
*
|
|
3540
|
+
* // Explanation:
|
|
3541
|
+
* // The `chunksOf` function takes an array of numbers `[1, 2, 3, 4, 5]` and a number `2`.
|
|
3542
|
+
* // It splits the array into chunks of length 2. Since the array length is not evenly divisible by 2,
|
|
3543
|
+
* // the last chunk contains the remaining elements.
|
|
3544
|
+
* // The result is `[[1, 2], [3, 4], [5]]`.
|
|
3545
|
+
*
|
|
3546
|
+
* @category splitting
|
|
3547
|
+
* @since 2.0.0
|
|
3548
|
+
*/
|
|
1795
3549
|
<A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>
|
|
1796
3550
|
} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {
|
|
1797
3551
|
const input = fromIterable(self)
|
|
@@ -1814,8 +3568,35 @@ export const chunksOf: {
|
|
|
1814
3568
|
* @since 2.0.0
|
|
1815
3569
|
*/
|
|
1816
3570
|
export const groupWith: {
|
|
3571
|
+
/**
|
|
3572
|
+
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.
|
|
3573
|
+
*
|
|
3574
|
+
* @example
|
|
3575
|
+
* import { Array } from "effect"
|
|
3576
|
+
*
|
|
3577
|
+
* const result = Array.groupWith(["a", "a", "b", "b", "b", "c", "a"], (x, y) => x === y)
|
|
3578
|
+
* assert.deepStrictEqual(result, [["a", "a"], ["b", "b", "b"], ["c"], ["a"]])
|
|
3579
|
+
*
|
|
3580
|
+
* @category grouping
|
|
3581
|
+
* @since 2.0.0
|
|
3582
|
+
*/
|
|
1817
3583
|
<A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>
|
|
1818
|
-
|
|
3584
|
+
/**
|
|
3585
|
+
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.
|
|
3586
|
+
*
|
|
3587
|
+
* @example
|
|
3588
|
+
* import { Array } from "effect"
|
|
3589
|
+
*
|
|
3590
|
+
* const result = Array.groupWith(["a", "a", "b", "b", "b", "c", "a"], (x, y) => x === y)
|
|
3591
|
+
* assert.deepStrictEqual(result, [["a", "a"], ["b", "b", "b"], ["c"], ["a"]])
|
|
3592
|
+
*
|
|
3593
|
+
* @category grouping
|
|
3594
|
+
* @since 2.0.0
|
|
3595
|
+
*/
|
|
3596
|
+
<A>(
|
|
3597
|
+
self: NonEmptyReadonlyArray<A>,
|
|
3598
|
+
isEquivalent: (self: A, that: A) => boolean
|
|
3599
|
+
): NonEmptyArray<NonEmptyArray<A>>
|
|
1819
3600
|
} = dual(
|
|
1820
3601
|
2,
|
|
1821
3602
|
<A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>
|
|
@@ -1873,9 +3654,51 @@ export const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmpt
|
|
|
1873
3654
|
* @since 2.0.0
|
|
1874
3655
|
*/
|
|
1875
3656
|
export const groupBy: {
|
|
3657
|
+
/**
|
|
3658
|
+
* Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
|
|
3659
|
+
* function on each element, and grouping the results according to values returned
|
|
3660
|
+
*
|
|
3661
|
+
* @example
|
|
3662
|
+
* import { Array } from "effect"
|
|
3663
|
+
*
|
|
3664
|
+
* const people = [
|
|
3665
|
+
* { name: "Alice", group: "A" },
|
|
3666
|
+
* { name: "Bob", group: "B" },
|
|
3667
|
+
* { name: "Charlie", group: "A" }
|
|
3668
|
+
* ]
|
|
3669
|
+
* const result = Array.groupBy(people, person => person.group)
|
|
3670
|
+
* assert.deepStrictEqual(result, {
|
|
3671
|
+
* A: [{ name: "Alice", group: "A" }, { name: "Charlie", group: "A" }],
|
|
3672
|
+
* B: [{ name: "Bob", group: "B" }]
|
|
3673
|
+
* })
|
|
3674
|
+
*
|
|
3675
|
+
* @category grouping
|
|
3676
|
+
* @since 2.0.0
|
|
3677
|
+
*/
|
|
1876
3678
|
<A, K extends string | symbol>(
|
|
1877
3679
|
f: (a: A) => K
|
|
1878
3680
|
): (self: Iterable<A>) => Record<Record.ReadonlyRecord.NonLiteralKey<K>, NonEmptyArray<A>>
|
|
3681
|
+
/**
|
|
3682
|
+
* Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
|
|
3683
|
+
* function on each element, and grouping the results according to values returned
|
|
3684
|
+
*
|
|
3685
|
+
* @example
|
|
3686
|
+
* import { Array } from "effect"
|
|
3687
|
+
*
|
|
3688
|
+
* const people = [
|
|
3689
|
+
* { name: "Alice", group: "A" },
|
|
3690
|
+
* { name: "Bob", group: "B" },
|
|
3691
|
+
* { name: "Charlie", group: "A" }
|
|
3692
|
+
* ]
|
|
3693
|
+
* const result = Array.groupBy(people, person => person.group)
|
|
3694
|
+
* assert.deepStrictEqual(result, {
|
|
3695
|
+
* A: [{ name: "Alice", group: "A" }, { name: "Charlie", group: "A" }],
|
|
3696
|
+
* B: [{ name: "Bob", group: "B" }]
|
|
3697
|
+
* })
|
|
3698
|
+
*
|
|
3699
|
+
* @category grouping
|
|
3700
|
+
* @since 2.0.0
|
|
3701
|
+
*/
|
|
1879
3702
|
<A, K extends string | symbol>(
|
|
1880
3703
|
self: Iterable<A>,
|
|
1881
3704
|
f: (a: A) => K
|
|
@@ -1910,21 +3733,77 @@ export const groupBy: {
|
|
|
1910
3733
|
* @since 2.0.0
|
|
1911
3734
|
*/
|
|
1912
3735
|
export const unionWith: {
|
|
3736
|
+
/**
|
|
3737
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
3738
|
+
*
|
|
3739
|
+
* @example
|
|
3740
|
+
* import { Array } from "effect"
|
|
3741
|
+
*
|
|
3742
|
+
* const array1 = [1, 2]
|
|
3743
|
+
* const array2 = [2, 3]
|
|
3744
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
3745
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
3746
|
+
*
|
|
3747
|
+
* @since 2.0.0
|
|
3748
|
+
*/
|
|
1913
3749
|
<S extends Iterable<any>, T extends Iterable<any>>(
|
|
1914
3750
|
that: T,
|
|
1915
3751
|
isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<T>) => boolean
|
|
1916
3752
|
): (self: S) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
|
|
3753
|
+
/**
|
|
3754
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
3755
|
+
*
|
|
3756
|
+
* @example
|
|
3757
|
+
* import { Array } from "effect"
|
|
3758
|
+
*
|
|
3759
|
+
* const array1 = [1, 2]
|
|
3760
|
+
* const array2 = [2, 3]
|
|
3761
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
3762
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
3763
|
+
*
|
|
3764
|
+
* @since 2.0.0
|
|
3765
|
+
*/
|
|
1917
3766
|
<A, B>(
|
|
1918
3767
|
self: NonEmptyReadonlyArray<A>,
|
|
1919
3768
|
that: Iterable<B>,
|
|
1920
3769
|
isEquivalent: (self: A, that: B) => boolean
|
|
1921
3770
|
): NonEmptyArray<A | B>
|
|
3771
|
+
/**
|
|
3772
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
3773
|
+
*
|
|
3774
|
+
* @example
|
|
3775
|
+
* import { Array } from "effect"
|
|
3776
|
+
*
|
|
3777
|
+
* const array1 = [1, 2]
|
|
3778
|
+
* const array2 = [2, 3]
|
|
3779
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
3780
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
3781
|
+
*
|
|
3782
|
+
* @since 2.0.0
|
|
3783
|
+
*/
|
|
1922
3784
|
<A, B>(
|
|
1923
3785
|
self: Iterable<A>,
|
|
1924
3786
|
that: NonEmptyReadonlyArray<B>,
|
|
1925
3787
|
isEquivalent: (self: A, that: B) => boolean
|
|
1926
3788
|
): NonEmptyArray<A | B>
|
|
1927
|
-
|
|
3789
|
+
/**
|
|
3790
|
+
* Calculates the union of two arrays using the provided equivalence relation.
|
|
3791
|
+
*
|
|
3792
|
+
* @example
|
|
3793
|
+
* import { Array } from "effect"
|
|
3794
|
+
*
|
|
3795
|
+
* const array1 = [1, 2]
|
|
3796
|
+
* const array2 = [2, 3]
|
|
3797
|
+
* const union = Array.unionWith(array1, array2, (a, b) => a === b)
|
|
3798
|
+
* assert.deepStrictEqual(union, [1, 2, 3])
|
|
3799
|
+
*
|
|
3800
|
+
* @since 2.0.0
|
|
3801
|
+
*/
|
|
3802
|
+
<A, B>(
|
|
3803
|
+
self: Iterable<A>,
|
|
3804
|
+
that: Iterable<B>,
|
|
3805
|
+
isEquivalent: (self: A, that: B) => boolean
|
|
3806
|
+
): Array<A | B>
|
|
1928
3807
|
} = dual(3, <A>(self: Iterable<A>, that: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {
|
|
1929
3808
|
const a = fromIterable(self)
|
|
1930
3809
|
const b = fromIterable(that)
|
|
@@ -1952,13 +3831,63 @@ export const unionWith: {
|
|
|
1952
3831
|
* @since 2.0.0
|
|
1953
3832
|
*/
|
|
1954
3833
|
export const union: {
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
3834
|
+
/**
|
|
3835
|
+
* Creates a union of two arrays, removing duplicates.
|
|
3836
|
+
*
|
|
3837
|
+
* @example
|
|
3838
|
+
* import { Array } from "effect"
|
|
3839
|
+
*
|
|
3840
|
+
* const array1 = [1, 2]
|
|
3841
|
+
* const array2 = [2, 3]
|
|
3842
|
+
* const result = Array.union(array1, array2)
|
|
3843
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
3844
|
+
*
|
|
3845
|
+
* @since 2.0.0
|
|
3846
|
+
*/
|
|
3847
|
+
<T extends Iterable<any>>(that: T): <S extends Iterable<any>>(
|
|
1958
3848
|
self: S
|
|
1959
3849
|
) => ReadonlyArray.OrNonEmpty<S, T, ReadonlyArray.Infer<S> | ReadonlyArray.Infer<T>>
|
|
3850
|
+
/**
|
|
3851
|
+
* Creates a union of two arrays, removing duplicates.
|
|
3852
|
+
*
|
|
3853
|
+
* @example
|
|
3854
|
+
* import { Array } from "effect"
|
|
3855
|
+
*
|
|
3856
|
+
* const array1 = [1, 2]
|
|
3857
|
+
* const array2 = [2, 3]
|
|
3858
|
+
* const result = Array.union(array1, array2)
|
|
3859
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
3860
|
+
*
|
|
3861
|
+
* @since 2.0.0
|
|
3862
|
+
*/
|
|
1960
3863
|
<A, B>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<B>): NonEmptyArray<A | B>
|
|
3864
|
+
/**
|
|
3865
|
+
* Creates a union of two arrays, removing duplicates.
|
|
3866
|
+
*
|
|
3867
|
+
* @example
|
|
3868
|
+
* import { Array } from "effect"
|
|
3869
|
+
*
|
|
3870
|
+
* const array1 = [1, 2]
|
|
3871
|
+
* const array2 = [2, 3]
|
|
3872
|
+
* const result = Array.union(array1, array2)
|
|
3873
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
3874
|
+
*
|
|
3875
|
+
* @since 2.0.0
|
|
3876
|
+
*/
|
|
1961
3877
|
<A, B>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>
|
|
3878
|
+
/**
|
|
3879
|
+
* Creates a union of two arrays, removing duplicates.
|
|
3880
|
+
*
|
|
3881
|
+
* @example
|
|
3882
|
+
* import { Array } from "effect"
|
|
3883
|
+
*
|
|
3884
|
+
* const array1 = [1, 2]
|
|
3885
|
+
* const array2 = [2, 3]
|
|
3886
|
+
* const result = Array.union(array1, array2)
|
|
3887
|
+
* assert.deepStrictEqual(result, [1, 2, 3])
|
|
3888
|
+
*
|
|
3889
|
+
* @since 2.0.0
|
|
3890
|
+
*/
|
|
1962
3891
|
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>
|
|
1963
3892
|
} = dual(2, <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => unionWith(self, that, _equivalence))
|
|
1964
3893
|
|
|
@@ -2003,7 +3932,35 @@ export const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean)
|
|
|
2003
3932
|
* @since 2.0.0
|
|
2004
3933
|
*/
|
|
2005
3934
|
export const intersection: {
|
|
3935
|
+
/**
|
|
3936
|
+
* Creates an `Array` of unique values that are included in all given `Iterable`s.
|
|
3937
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
3938
|
+
*
|
|
3939
|
+
* @example
|
|
3940
|
+
* import { Array } from "effect"
|
|
3941
|
+
*
|
|
3942
|
+
* const array1 = [1, 2, 3]
|
|
3943
|
+
* const array2 = [3, 4, 1]
|
|
3944
|
+
* const result = Array.intersection(array1, array2)
|
|
3945
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
3946
|
+
*
|
|
3947
|
+
* @since 2.0.0
|
|
3948
|
+
*/
|
|
2006
3949
|
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>
|
|
3950
|
+
/**
|
|
3951
|
+
* Creates an `Array` of unique values that are included in all given `Iterable`s.
|
|
3952
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
3953
|
+
*
|
|
3954
|
+
* @example
|
|
3955
|
+
* import { Array } from "effect"
|
|
3956
|
+
*
|
|
3957
|
+
* const array1 = [1, 2, 3]
|
|
3958
|
+
* const array2 = [3, 4, 1]
|
|
3959
|
+
* const result = Array.intersection(array1, array2)
|
|
3960
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
3961
|
+
*
|
|
3962
|
+
* @since 2.0.0
|
|
3963
|
+
*/
|
|
2007
3964
|
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>
|
|
2008
3965
|
} = intersectionWith(_equivalence)
|
|
2009
3966
|
|
|
@@ -2047,7 +4004,35 @@ export const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean):
|
|
|
2047
4004
|
* @since 2.0.0
|
|
2048
4005
|
*/
|
|
2049
4006
|
export const difference: {
|
|
4007
|
+
/**
|
|
4008
|
+
* Creates a `Array` of values not included in the other given `Iterable`.
|
|
4009
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
4010
|
+
*
|
|
4011
|
+
* @example
|
|
4012
|
+
* import { Array } from "effect"
|
|
4013
|
+
*
|
|
4014
|
+
* const array1 = [1, 2, 3]
|
|
4015
|
+
* const array2 = [2, 3, 4]
|
|
4016
|
+
* const difference = Array.difference(array1, array2)
|
|
4017
|
+
* assert.deepStrictEqual(difference, [1])
|
|
4018
|
+
*
|
|
4019
|
+
* @since 2.0.0
|
|
4020
|
+
*/
|
|
2050
4021
|
<A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>
|
|
4022
|
+
/**
|
|
4023
|
+
* Creates a `Array` of values not included in the other given `Iterable`.
|
|
4024
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
4025
|
+
*
|
|
4026
|
+
* @example
|
|
4027
|
+
* import { Array } from "effect"
|
|
4028
|
+
*
|
|
4029
|
+
* const array1 = [1, 2, 3]
|
|
4030
|
+
* const array2 = [2, 3, 4]
|
|
4031
|
+
* const difference = Array.difference(array1, array2)
|
|
4032
|
+
* assert.deepStrictEqual(difference, [1])
|
|
4033
|
+
*
|
|
4034
|
+
* @since 2.0.0
|
|
4035
|
+
*/
|
|
2051
4036
|
<A>(self: Iterable<A>, that: Iterable<A>): Array<A>
|
|
2052
4037
|
} = differenceWith(_equivalence)
|
|
2053
4038
|
|
|
@@ -2118,9 +4103,17 @@ export declare namespace ReadonlyArray {
|
|
|
2118
4103
|
* @since 2.0.0
|
|
2119
4104
|
*/
|
|
2120
4105
|
export const map: {
|
|
4106
|
+
/**
|
|
4107
|
+
* @category mapping
|
|
4108
|
+
* @since 2.0.0
|
|
4109
|
+
*/
|
|
2121
4110
|
<S extends ReadonlyArray<any>, B>(
|
|
2122
4111
|
f: (a: ReadonlyArray.Infer<S>, i: number) => B
|
|
2123
4112
|
): (self: S) => ReadonlyArray.With<S, B>
|
|
4113
|
+
/**
|
|
4114
|
+
* @category mapping
|
|
4115
|
+
* @since 2.0.0
|
|
4116
|
+
*/
|
|
2124
4117
|
<S extends ReadonlyArray<any>, B>(self: S, f: (a: ReadonlyArray.Infer<S>, i: number) => B): ReadonlyArray.With<S, B>
|
|
2125
4118
|
} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))
|
|
2126
4119
|
|
|
@@ -2131,10 +4124,31 @@ export const map: {
|
|
|
2131
4124
|
* @since 2.0.0
|
|
2132
4125
|
*/
|
|
2133
4126
|
export const flatMap: {
|
|
2134
|
-
|
|
2135
|
-
|
|
4127
|
+
/**
|
|
4128
|
+
* Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.
|
|
4129
|
+
*
|
|
4130
|
+
* @category sequencing
|
|
4131
|
+
* @since 2.0.0
|
|
4132
|
+
*/
|
|
4133
|
+
<S extends ReadonlyArray<any>, T extends ReadonlyArray<any>>(
|
|
4134
|
+
f: (a: ReadonlyArray.Infer<S>, i: number) => T
|
|
2136
4135
|
): (self: S) => ReadonlyArray.AndNonEmpty<S, T, ReadonlyArray.Infer<T>>
|
|
2137
|
-
|
|
4136
|
+
/**
|
|
4137
|
+
* Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.
|
|
4138
|
+
*
|
|
4139
|
+
* @category sequencing
|
|
4140
|
+
* @since 2.0.0
|
|
4141
|
+
*/
|
|
4142
|
+
<A, B>(
|
|
4143
|
+
self: NonEmptyReadonlyArray<A>,
|
|
4144
|
+
f: (a: A, i: number) => NonEmptyReadonlyArray<B>
|
|
4145
|
+
): NonEmptyArray<B>
|
|
4146
|
+
/**
|
|
4147
|
+
* Applies a function to each element in an array and returns a new array containing the concatenated mapped elements.
|
|
4148
|
+
*
|
|
4149
|
+
* @category sequencing
|
|
4150
|
+
* @since 2.0.0
|
|
4151
|
+
*/
|
|
2138
4152
|
<A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>
|
|
2139
4153
|
} = dual(
|
|
2140
4154
|
2,
|
|
@@ -2190,7 +4204,39 @@ export const flatten: <S extends ReadonlyArray<ReadonlyArray<any>>>(self: S) =>
|
|
|
2190
4204
|
* @since 2.0.0
|
|
2191
4205
|
*/
|
|
2192
4206
|
export const filterMap: {
|
|
4207
|
+
/**
|
|
4208
|
+
* Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.
|
|
4209
|
+
* This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.
|
|
4210
|
+
*
|
|
4211
|
+
* @example
|
|
4212
|
+
* import { Array, Option } from "effect";
|
|
4213
|
+
*
|
|
4214
|
+
* const data = [1, 2, 3, 4, 5];
|
|
4215
|
+
* const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
4216
|
+
* const result = Array.filterMap(data, evenSquares);
|
|
4217
|
+
*
|
|
4218
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
4219
|
+
*
|
|
4220
|
+
* @category filtering
|
|
4221
|
+
* @since 2.0.0
|
|
4222
|
+
*/
|
|
2193
4223
|
<A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>
|
|
4224
|
+
/**
|
|
4225
|
+
* Applies a function to each element of the `Iterable` and filters based on the result, keeping the transformed values where the function returns `Some`.
|
|
4226
|
+
* This method combines filtering and mapping functionalities, allowing transformations and filtering of elements based on a single function pass.
|
|
4227
|
+
*
|
|
4228
|
+
* @example
|
|
4229
|
+
* import { Array, Option } from "effect";
|
|
4230
|
+
*
|
|
4231
|
+
* const data = [1, 2, 3, 4, 5];
|
|
4232
|
+
* const evenSquares = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
4233
|
+
* const result = Array.filterMap(data, evenSquares);
|
|
4234
|
+
*
|
|
4235
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
4236
|
+
*
|
|
4237
|
+
* @category filtering
|
|
4238
|
+
* @since 2.0.0
|
|
4239
|
+
*/
|
|
2194
4240
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>
|
|
2195
4241
|
} = dual(
|
|
2196
4242
|
2,
|
|
@@ -2225,7 +4271,41 @@ export const filterMap: {
|
|
|
2225
4271
|
* @since 2.0.0
|
|
2226
4272
|
*/
|
|
2227
4273
|
export const filterMapWhile: {
|
|
4274
|
+
/**
|
|
4275
|
+
* Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.
|
|
4276
|
+
* This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.
|
|
4277
|
+
* This is useful when you need to transform an array but only up to the point where a certain condition holds true.
|
|
4278
|
+
*
|
|
4279
|
+
* @example
|
|
4280
|
+
* import { Array, Option } from "effect";
|
|
4281
|
+
*
|
|
4282
|
+
* const data = [2, 4, 5];
|
|
4283
|
+
* const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
4284
|
+
* const result = Array.filterMapWhile(data, toSquareTillOdd);
|
|
4285
|
+
*
|
|
4286
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
4287
|
+
*
|
|
4288
|
+
* @category filtering
|
|
4289
|
+
* @since 2.0.0
|
|
4290
|
+
*/
|
|
2228
4291
|
<A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>
|
|
4292
|
+
/**
|
|
4293
|
+
* Applies a function to each element of the array and filters based on the result, stopping when a condition is not met.
|
|
4294
|
+
* This method combines filtering and mapping in a single pass, and short-circuits, i.e., stops processing, as soon as the function returns `None`.
|
|
4295
|
+
* This is useful when you need to transform an array but only up to the point where a certain condition holds true.
|
|
4296
|
+
*
|
|
4297
|
+
* @example
|
|
4298
|
+
* import { Array, Option } from "effect";
|
|
4299
|
+
*
|
|
4300
|
+
* const data = [2, 4, 5];
|
|
4301
|
+
* const toSquareTillOdd = (x: number) => x % 2 === 0 ? Option.some(x * x) : Option.none();
|
|
4302
|
+
* const result = Array.filterMapWhile(data, toSquareTillOdd);
|
|
4303
|
+
*
|
|
4304
|
+
* assert.deepStrictEqual(result, [4, 16]);
|
|
4305
|
+
*
|
|
4306
|
+
* @category filtering
|
|
4307
|
+
* @since 2.0.0
|
|
4308
|
+
*/
|
|
2229
4309
|
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>
|
|
2230
4310
|
} = dual(2, <A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>) => {
|
|
2231
4311
|
let i = 0
|
|
@@ -2266,7 +4346,53 @@ export const filterMapWhile: {
|
|
|
2266
4346
|
* @since 2.0.0
|
|
2267
4347
|
*/
|
|
2268
4348
|
export const partitionMap: {
|
|
4349
|
+
/**
|
|
4350
|
+
* Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.
|
|
4351
|
+
* This function is particularly useful for operations where each element can result in two possible types,
|
|
4352
|
+
* and you want to separate these types into different collections. For instance, separating validation results
|
|
4353
|
+
* into successes and failures.
|
|
4354
|
+
*
|
|
4355
|
+
* @example
|
|
4356
|
+
* import { Array, Either } from "effect";
|
|
4357
|
+
*
|
|
4358
|
+
* const data = [1, 2, 3, 4, 5]
|
|
4359
|
+
* const isEven = (x: number) => x % 2 === 0
|
|
4360
|
+
* const partitioned = Array.partitionMap(data, x =>
|
|
4361
|
+
* isEven(x) ? Either.right(x) : Either.left(x)
|
|
4362
|
+
* )
|
|
4363
|
+
*
|
|
4364
|
+
* assert.deepStrictEqual(partitioned, [
|
|
4365
|
+
* [1, 3, 5],
|
|
4366
|
+
* [2, 4]
|
|
4367
|
+
* ])
|
|
4368
|
+
*
|
|
4369
|
+
* @category filtering
|
|
4370
|
+
* @since 2.0.0
|
|
4371
|
+
*/
|
|
2269
4372
|
<A, B, C>(f: (a: A, i: number) => array_<C, B>): (self: Iterable<A>) => [left: Array<B>, right: Array<C>]
|
|
4373
|
+
/**
|
|
4374
|
+
* Applies a function to each element of the `Iterable`, categorizing the results into two separate arrays.
|
|
4375
|
+
* This function is particularly useful for operations where each element can result in two possible types,
|
|
4376
|
+
* and you want to separate these types into different collections. For instance, separating validation results
|
|
4377
|
+
* into successes and failures.
|
|
4378
|
+
*
|
|
4379
|
+
* @example
|
|
4380
|
+
* import { Array, Either } from "effect";
|
|
4381
|
+
*
|
|
4382
|
+
* const data = [1, 2, 3, 4, 5]
|
|
4383
|
+
* const isEven = (x: number) => x % 2 === 0
|
|
4384
|
+
* const partitioned = Array.partitionMap(data, x =>
|
|
4385
|
+
* isEven(x) ? Either.right(x) : Either.left(x)
|
|
4386
|
+
* )
|
|
4387
|
+
*
|
|
4388
|
+
* assert.deepStrictEqual(partitioned, [
|
|
4389
|
+
* [1, 3, 5],
|
|
4390
|
+
* [2, 4]
|
|
4391
|
+
* ])
|
|
4392
|
+
*
|
|
4393
|
+
* @category filtering
|
|
4394
|
+
* @since 2.0.0
|
|
4395
|
+
*/
|
|
2270
4396
|
<A, B, C>(self: Iterable<A>, f: (a: A, i: number) => array_<C, B>): [left: Array<B>, right: Array<C>]
|
|
2271
4397
|
} = dual(
|
|
2272
4398
|
2,
|
|
@@ -2362,9 +4488,25 @@ export const getRights = <T extends Iterable<array_<any, any>>>(
|
|
|
2362
4488
|
* @since 2.0.0
|
|
2363
4489
|
*/
|
|
2364
4490
|
export const filter: {
|
|
4491
|
+
/**
|
|
4492
|
+
* @category filtering
|
|
4493
|
+
* @since 2.0.0
|
|
4494
|
+
*/
|
|
2365
4495
|
<A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (self: Iterable<A>) => Array<B>
|
|
4496
|
+
/**
|
|
4497
|
+
* @category filtering
|
|
4498
|
+
* @since 2.0.0
|
|
4499
|
+
*/
|
|
2366
4500
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: Iterable<A>) => Array<A>
|
|
4501
|
+
/**
|
|
4502
|
+
* @category filtering
|
|
4503
|
+
* @since 2.0.0
|
|
4504
|
+
*/
|
|
2367
4505
|
<A, B extends A>(self: Iterable<A>, refinement: (a: A, i: number) => a is B): Array<B>
|
|
4506
|
+
/**
|
|
4507
|
+
* @category filtering
|
|
4508
|
+
* @since 2.0.0
|
|
4509
|
+
*/
|
|
2368
4510
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): Array<A>
|
|
2369
4511
|
} = dual(
|
|
2370
4512
|
2,
|
|
@@ -2387,16 +4529,40 @@ export const filter: {
|
|
|
2387
4529
|
* @since 2.0.0
|
|
2388
4530
|
*/
|
|
2389
4531
|
export const partition: {
|
|
4532
|
+
/**
|
|
4533
|
+
* Separate elements based on a predicate that also exposes the index of the element.
|
|
4534
|
+
*
|
|
4535
|
+
* @category filtering
|
|
4536
|
+
* @since 2.0.0
|
|
4537
|
+
*/
|
|
2390
4538
|
<A, B extends A>(refinement: (a: NoInfer<A>, i: number) => a is B): (
|
|
2391
4539
|
self: Iterable<A>
|
|
2392
4540
|
) => [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]
|
|
4541
|
+
/**
|
|
4542
|
+
* Separate elements based on a predicate that also exposes the index of the element.
|
|
4543
|
+
*
|
|
4544
|
+
* @category filtering
|
|
4545
|
+
* @since 2.0.0
|
|
4546
|
+
*/
|
|
2393
4547
|
<A>(
|
|
2394
4548
|
predicate: (a: NoInfer<A>, i: number) => boolean
|
|
2395
4549
|
): (self: Iterable<A>) => [excluded: Array<A>, satisfying: Array<A>]
|
|
4550
|
+
/**
|
|
4551
|
+
* Separate elements based on a predicate that also exposes the index of the element.
|
|
4552
|
+
*
|
|
4553
|
+
* @category filtering
|
|
4554
|
+
* @since 2.0.0
|
|
4555
|
+
*/
|
|
2396
4556
|
<A, B extends A>(
|
|
2397
4557
|
self: Iterable<A>,
|
|
2398
4558
|
refinement: (a: A, i: number) => a is B
|
|
2399
4559
|
): [excluded: Array<Exclude<A, B>>, satisfying: Array<B>]
|
|
4560
|
+
/**
|
|
4561
|
+
* Separate elements based on a predicate that also exposes the index of the element.
|
|
4562
|
+
*
|
|
4563
|
+
* @category filtering
|
|
4564
|
+
* @since 2.0.0
|
|
4565
|
+
*/
|
|
2400
4566
|
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [excluded: Array<A>, satisfying: Array<A>]
|
|
2401
4567
|
} = dual(
|
|
2402
4568
|
2,
|
|
@@ -2448,7 +4614,33 @@ export const separate: <T extends Iterable<array_<any, any>>>(
|
|
|
2448
4614
|
* @since 2.0.0
|
|
2449
4615
|
*/
|
|
2450
4616
|
export const reduce: {
|
|
4617
|
+
/**
|
|
4618
|
+
* Reduces an array from the left.
|
|
4619
|
+
*
|
|
4620
|
+
* @example
|
|
4621
|
+
* import { Array } from "effect"
|
|
4622
|
+
*
|
|
4623
|
+
* const numbers = [1, 2, 3]
|
|
4624
|
+
* const result = Array.reduce(numbers, 0, (acc, n) => acc + n)
|
|
4625
|
+
* assert.deepStrictEqual(result, 6)
|
|
4626
|
+
*
|
|
4627
|
+
* @category folding
|
|
4628
|
+
* @since 2.0.0
|
|
4629
|
+
*/
|
|
2451
4630
|
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B
|
|
4631
|
+
/**
|
|
4632
|
+
* Reduces an array from the left.
|
|
4633
|
+
*
|
|
4634
|
+
* @example
|
|
4635
|
+
* import { Array } from "effect"
|
|
4636
|
+
*
|
|
4637
|
+
* const numbers = [1, 2, 3]
|
|
4638
|
+
* const result = Array.reduce(numbers, 0, (acc, n) => acc + n)
|
|
4639
|
+
* assert.deepStrictEqual(result, 6)
|
|
4640
|
+
*
|
|
4641
|
+
* @category folding
|
|
4642
|
+
* @since 2.0.0
|
|
4643
|
+
*/
|
|
2452
4644
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
2453
4645
|
} = dual(
|
|
2454
4646
|
3,
|
|
@@ -2470,7 +4662,33 @@ export const reduce: {
|
|
|
2470
4662
|
* @since 2.0.0
|
|
2471
4663
|
*/
|
|
2472
4664
|
export const reduceRight: {
|
|
4665
|
+
/**
|
|
4666
|
+
* Reduces an array from the right.
|
|
4667
|
+
*
|
|
4668
|
+
* @example
|
|
4669
|
+
* import { Array } from "effect"
|
|
4670
|
+
*
|
|
4671
|
+
* const numbers = [1, 2, 3]
|
|
4672
|
+
* const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)
|
|
4673
|
+
* assert.deepStrictEqual(result, 6)
|
|
4674
|
+
*
|
|
4675
|
+
* @category folding
|
|
4676
|
+
* @since 2.0.0
|
|
4677
|
+
*/
|
|
2473
4678
|
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B
|
|
4679
|
+
/**
|
|
4680
|
+
* Reduces an array from the right.
|
|
4681
|
+
*
|
|
4682
|
+
* @example
|
|
4683
|
+
* import { Array } from "effect"
|
|
4684
|
+
*
|
|
4685
|
+
* const numbers = [1, 2, 3]
|
|
4686
|
+
* const result = Array.reduceRight(numbers, 0, (acc, n) => acc + n)
|
|
4687
|
+
* assert.deepStrictEqual(result, 6)
|
|
4688
|
+
*
|
|
4689
|
+
* @category folding
|
|
4690
|
+
* @since 2.0.0
|
|
4691
|
+
*/
|
|
2474
4692
|
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
2475
4693
|
} = dual(
|
|
2476
4694
|
3,
|
|
@@ -2494,6 +4712,20 @@ export const reduceRight: {
|
|
|
2494
4712
|
*/
|
|
2495
4713
|
export const liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.
|
|
2496
4714
|
<A, B extends A>(refinement: Refinement<A, B>): (a: A) => Array<B>
|
|
4715
|
+
/**
|
|
4716
|
+
* Lifts a predicate into an array.
|
|
4717
|
+
*
|
|
4718
|
+
* @example
|
|
4719
|
+
* import { Array } from "effect"
|
|
4720
|
+
*
|
|
4721
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
4722
|
+
* const to = Array.liftPredicate(isEven)
|
|
4723
|
+
* assert.deepStrictEqual(to(1), [])
|
|
4724
|
+
* assert.deepStrictEqual(to(2), [2])
|
|
4725
|
+
*
|
|
4726
|
+
* @category lifting
|
|
4727
|
+
* @since 2.0.0
|
|
4728
|
+
*/
|
|
2497
4729
|
<A>(predicate: Predicate<A>): <B extends A>(b: B) => Array<B>
|
|
2498
4730
|
} = <A>(predicate: Predicate<A>) => <B extends A>(b: B): Array<B> => predicate(b) ? [b] : []
|
|
2499
4731
|
|
|
@@ -2540,7 +4772,43 @@ export const liftNullable = <A extends Array<unknown>, B>(
|
|
|
2540
4772
|
* @since 2.0.0
|
|
2541
4773
|
*/
|
|
2542
4774
|
export const flatMapNullable: {
|
|
4775
|
+
/**
|
|
4776
|
+
* Maps over an array and flattens the result, removing null and undefined values.
|
|
4777
|
+
*
|
|
4778
|
+
* @example
|
|
4779
|
+
* import { Array } from "effect"
|
|
4780
|
+
*
|
|
4781
|
+
* const numbers = [1, 2, 3]
|
|
4782
|
+
* const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))
|
|
4783
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
4784
|
+
*
|
|
4785
|
+
* // Explanation:
|
|
4786
|
+
* // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers
|
|
4787
|
+
* // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened
|
|
4788
|
+
* // to remove null values, resulting in [1, 3].
|
|
4789
|
+
*
|
|
4790
|
+
* @category sequencing
|
|
4791
|
+
* @since 2.0.0
|
|
4792
|
+
*/
|
|
2543
4793
|
<A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>
|
|
4794
|
+
/**
|
|
4795
|
+
* Maps over an array and flattens the result, removing null and undefined values.
|
|
4796
|
+
*
|
|
4797
|
+
* @example
|
|
4798
|
+
* import { Array } from "effect"
|
|
4799
|
+
*
|
|
4800
|
+
* const numbers = [1, 2, 3]
|
|
4801
|
+
* const result = Array.flatMapNullable(numbers, n => (n % 2 === 0 ? null : n))
|
|
4802
|
+
* assert.deepStrictEqual(result, [1, 3])
|
|
4803
|
+
*
|
|
4804
|
+
* // Explanation:
|
|
4805
|
+
* // The array of numbers [1, 2, 3] is mapped with a function that returns null for even numbers
|
|
4806
|
+
* // and the number itself for odd numbers. The resulting array [1, null, 3] is then flattened
|
|
4807
|
+
* // to remove null values, resulting in [1, 3].
|
|
4808
|
+
*
|
|
4809
|
+
* @category sequencing
|
|
4810
|
+
* @since 2.0.0
|
|
4811
|
+
*/
|
|
2544
4812
|
<A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>
|
|
2545
4813
|
} = dual(
|
|
2546
4814
|
2,
|
|
@@ -2590,11 +4858,35 @@ export const liftEither = <A extends Array<unknown>, E, B>(
|
|
|
2590
4858
|
* @since 2.0.0
|
|
2591
4859
|
*/
|
|
2592
4860
|
export const every: {
|
|
4861
|
+
/**
|
|
4862
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
4863
|
+
*
|
|
4864
|
+
* @category elements
|
|
4865
|
+
* @since 2.0.0
|
|
4866
|
+
*/
|
|
2593
4867
|
<A, B extends A>(
|
|
2594
4868
|
refinement: (a: NoInfer<A>, i: number) => a is B
|
|
2595
4869
|
): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>
|
|
4870
|
+
/**
|
|
4871
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
4872
|
+
*
|
|
4873
|
+
* @category elements
|
|
4874
|
+
* @since 2.0.0
|
|
4875
|
+
*/
|
|
2596
4876
|
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => boolean
|
|
4877
|
+
/**
|
|
4878
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
4879
|
+
*
|
|
4880
|
+
* @category elements
|
|
4881
|
+
* @since 2.0.0
|
|
4882
|
+
*/
|
|
2597
4883
|
<A, B extends A>(self: ReadonlyArray<A>, refinement: (a: A, i: number) => a is B): self is ReadonlyArray<B>
|
|
4884
|
+
/**
|
|
4885
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
4886
|
+
*
|
|
4887
|
+
* @category elements
|
|
4888
|
+
* @since 2.0.0
|
|
4889
|
+
*/
|
|
2598
4890
|
<A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): boolean
|
|
2599
4891
|
} = dual(
|
|
2600
4892
|
2,
|
|
@@ -2609,9 +4901,19 @@ export const every: {
|
|
|
2609
4901
|
* @since 2.0.0
|
|
2610
4902
|
*/
|
|
2611
4903
|
export const some: {
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
4904
|
+
/**
|
|
4905
|
+
* Check if a predicate holds true for some `ReadonlyArray` element.
|
|
4906
|
+
*
|
|
4907
|
+
* @category elements
|
|
4908
|
+
* @since 2.0.0
|
|
4909
|
+
*/
|
|
4910
|
+
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A>
|
|
4911
|
+
/**
|
|
4912
|
+
* Check if a predicate holds true for some `ReadonlyArray` element.
|
|
4913
|
+
*
|
|
4914
|
+
* @category elements
|
|
4915
|
+
* @since 2.0.0
|
|
4916
|
+
*/
|
|
2615
4917
|
<A>(self: ReadonlyArray<A>, predicate: (a: A, i: number) => boolean): self is NonEmptyReadonlyArray<A>
|
|
2616
4918
|
} = dual(
|
|
2617
4919
|
2,
|
|
@@ -2638,7 +4940,43 @@ export const some: {
|
|
|
2638
4940
|
* @since 2.0.0
|
|
2639
4941
|
*/
|
|
2640
4942
|
export const extend: {
|
|
4943
|
+
/**
|
|
4944
|
+
* Extends an array with a function that maps each subarray to a value.
|
|
4945
|
+
*
|
|
4946
|
+
* @example
|
|
4947
|
+
* import { Array } from "effect"
|
|
4948
|
+
*
|
|
4949
|
+
* const numbers = [1, 2, 3]
|
|
4950
|
+
* const result = Array.extend(numbers, as => as.length)
|
|
4951
|
+
* assert.deepStrictEqual(result, [3, 2, 1])
|
|
4952
|
+
*
|
|
4953
|
+
* // Explanation:
|
|
4954
|
+
* // The function maps each subarray starting from each element to its length.
|
|
4955
|
+
* // The subarrays are: [1, 2, 3], [2, 3], [3].
|
|
4956
|
+
* // The lengths are: 3, 2, 1.
|
|
4957
|
+
* // Therefore, the result is [3, 2, 1].
|
|
4958
|
+
*
|
|
4959
|
+
* @since 2.0.0
|
|
4960
|
+
*/
|
|
2641
4961
|
<A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>
|
|
4962
|
+
/**
|
|
4963
|
+
* Extends an array with a function that maps each subarray to a value.
|
|
4964
|
+
*
|
|
4965
|
+
* @example
|
|
4966
|
+
* import { Array } from "effect"
|
|
4967
|
+
*
|
|
4968
|
+
* const numbers = [1, 2, 3]
|
|
4969
|
+
* const result = Array.extend(numbers, as => as.length)
|
|
4970
|
+
* assert.deepStrictEqual(result, [3, 2, 1])
|
|
4971
|
+
*
|
|
4972
|
+
* // Explanation:
|
|
4973
|
+
* // The function maps each subarray starting from each element to its length.
|
|
4974
|
+
* // The subarrays are: [1, 2, 3], [2, 3], [3].
|
|
4975
|
+
* // The lengths are: 3, 2, 1.
|
|
4976
|
+
* // Therefore, the result is [3, 2, 1].
|
|
4977
|
+
*
|
|
4978
|
+
* @since 2.0.0
|
|
4979
|
+
*/
|
|
2642
4980
|
<A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>
|
|
2643
4981
|
} = dual(
|
|
2644
4982
|
2,
|
|
@@ -2657,7 +4995,29 @@ export const extend: {
|
|
|
2657
4995
|
* @since 2.0.0
|
|
2658
4996
|
*/
|
|
2659
4997
|
export const min: {
|
|
4998
|
+
/**
|
|
4999
|
+
* Finds the minimum element in an array based on a comparator.
|
|
5000
|
+
*
|
|
5001
|
+
* @example
|
|
5002
|
+
* import { Array, Order } from "effect"
|
|
5003
|
+
*
|
|
5004
|
+
* const min = Array.min([3, 1, 2], Order.number)
|
|
5005
|
+
* assert.deepStrictEqual(min, 1)
|
|
5006
|
+
*
|
|
5007
|
+
* @since 2.0.0
|
|
5008
|
+
*/
|
|
2660
5009
|
<A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A
|
|
5010
|
+
/**
|
|
5011
|
+
* Finds the minimum element in an array based on a comparator.
|
|
5012
|
+
*
|
|
5013
|
+
* @example
|
|
5014
|
+
* import { Array, Order } from "effect"
|
|
5015
|
+
*
|
|
5016
|
+
* const min = Array.min([3, 1, 2], Order.number)
|
|
5017
|
+
* assert.deepStrictEqual(min, 1)
|
|
5018
|
+
*
|
|
5019
|
+
* @since 2.0.0
|
|
5020
|
+
*/
|
|
2661
5021
|
<A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A
|
|
2662
5022
|
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))
|
|
2663
5023
|
|
|
@@ -2673,7 +5033,29 @@ export const min: {
|
|
|
2673
5033
|
* @since 2.0.0
|
|
2674
5034
|
*/
|
|
2675
5035
|
export const max: {
|
|
5036
|
+
/**
|
|
5037
|
+
* Finds the maximum element in an array based on a comparator.
|
|
5038
|
+
*
|
|
5039
|
+
* @example
|
|
5040
|
+
* import { Array, Order } from "effect"
|
|
5041
|
+
*
|
|
5042
|
+
* const max = Array.max([3, 1, 2], Order.number)
|
|
5043
|
+
* assert.deepStrictEqual(max, 3)
|
|
5044
|
+
*
|
|
5045
|
+
* @since 2.0.0
|
|
5046
|
+
*/
|
|
2676
5047
|
<A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A
|
|
5048
|
+
/**
|
|
5049
|
+
* Finds the maximum element in an array based on a comparator.
|
|
5050
|
+
*
|
|
5051
|
+
* @example
|
|
5052
|
+
* import { Array, Order } from "effect"
|
|
5053
|
+
*
|
|
5054
|
+
* const max = Array.max([3, 1, 2], Order.number)
|
|
5055
|
+
* assert.deepStrictEqual(max, 3)
|
|
5056
|
+
*
|
|
5057
|
+
* @since 2.0.0
|
|
5058
|
+
*/
|
|
2677
5059
|
<A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A
|
|
2678
5060
|
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))
|
|
2679
5061
|
|
|
@@ -2734,7 +5116,29 @@ export const getEquivalence: <A>(
|
|
|
2734
5116
|
* @since 2.0.0
|
|
2735
5117
|
*/
|
|
2736
5118
|
export const forEach: {
|
|
5119
|
+
/**
|
|
5120
|
+
* Performs a side-effect for each element of the `Iterable`.
|
|
5121
|
+
*
|
|
5122
|
+
* @example
|
|
5123
|
+
* import { Array } from "effect"
|
|
5124
|
+
*
|
|
5125
|
+
* const numbers = [1, 2, 3]
|
|
5126
|
+
* Array.forEach(numbers, n => console.log(n)) // 1, 2, 3
|
|
5127
|
+
*
|
|
5128
|
+
* @since 2.0.0
|
|
5129
|
+
*/
|
|
2737
5130
|
<A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void
|
|
5131
|
+
/**
|
|
5132
|
+
* Performs a side-effect for each element of the `Iterable`.
|
|
5133
|
+
*
|
|
5134
|
+
* @example
|
|
5135
|
+
* import { Array } from "effect"
|
|
5136
|
+
*
|
|
5137
|
+
* const numbers = [1, 2, 3]
|
|
5138
|
+
* Array.forEach(numbers, n => console.log(n)) // 1, 2, 3
|
|
5139
|
+
*
|
|
5140
|
+
* @since 2.0.0
|
|
5141
|
+
*/
|
|
2738
5142
|
<A>(self: Iterable<A>, f: (a: A, i: number) => void): void
|
|
2739
5143
|
} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))
|
|
2740
5144
|
|
|
@@ -2752,10 +5156,52 @@ export const forEach: {
|
|
|
2752
5156
|
* @since 2.0.0
|
|
2753
5157
|
*/
|
|
2754
5158
|
export const dedupeWith: {
|
|
5159
|
+
/**
|
|
5160
|
+
* Remove duplicates from an `Iterable` using the provided `isEquivalent` function,
|
|
5161
|
+
* preserving the order of the first occurrence of each element.
|
|
5162
|
+
*
|
|
5163
|
+
* @example
|
|
5164
|
+
* import { Array } from "effect"
|
|
5165
|
+
*
|
|
5166
|
+
* const numbers = [1, 2, 2, 3, 3, 3]
|
|
5167
|
+
* const unique = Array.dedupeWith(numbers, (a, b) => a === b)
|
|
5168
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5169
|
+
*
|
|
5170
|
+
* @since 2.0.0
|
|
5171
|
+
*/
|
|
2755
5172
|
<S extends Iterable<any>>(
|
|
2756
5173
|
isEquivalent: (self: ReadonlyArray.Infer<S>, that: ReadonlyArray.Infer<S>) => boolean
|
|
2757
5174
|
): (self: S) => ReadonlyArray.With<S, ReadonlyArray.Infer<S>>
|
|
2758
|
-
|
|
5175
|
+
/**
|
|
5176
|
+
* Remove duplicates from an `Iterable` using the provided `isEquivalent` function,
|
|
5177
|
+
* preserving the order of the first occurrence of each element.
|
|
5178
|
+
*
|
|
5179
|
+
* @example
|
|
5180
|
+
* import { Array } from "effect"
|
|
5181
|
+
*
|
|
5182
|
+
* const numbers = [1, 2, 2, 3, 3, 3]
|
|
5183
|
+
* const unique = Array.dedupeWith(numbers, (a, b) => a === b)
|
|
5184
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5185
|
+
*
|
|
5186
|
+
* @since 2.0.0
|
|
5187
|
+
*/
|
|
5188
|
+
<A>(
|
|
5189
|
+
self: NonEmptyReadonlyArray<A>,
|
|
5190
|
+
isEquivalent: (self: A, that: A) => boolean
|
|
5191
|
+
): NonEmptyArray<A>
|
|
5192
|
+
/**
|
|
5193
|
+
* Remove duplicates from an `Iterable` using the provided `isEquivalent` function,
|
|
5194
|
+
* preserving the order of the first occurrence of each element.
|
|
5195
|
+
*
|
|
5196
|
+
* @example
|
|
5197
|
+
* import { Array } from "effect"
|
|
5198
|
+
*
|
|
5199
|
+
* const numbers = [1, 2, 2, 3, 3, 3]
|
|
5200
|
+
* const unique = Array.dedupeWith(numbers, (a, b) => a === b)
|
|
5201
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5202
|
+
*
|
|
5203
|
+
* @since 2.0.0
|
|
5204
|
+
*/
|
|
2759
5205
|
<A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>
|
|
2760
5206
|
} = dual(
|
|
2761
5207
|
2,
|
|
@@ -2799,7 +5245,31 @@ export const dedupe = <S extends Iterable<any> | NonEmptyReadonlyArray<any>>(
|
|
|
2799
5245
|
* @since 2.0.0
|
|
2800
5246
|
*/
|
|
2801
5247
|
export const dedupeAdjacentWith: {
|
|
5248
|
+
/**
|
|
5249
|
+
* Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.
|
|
5250
|
+
*
|
|
5251
|
+
* @example
|
|
5252
|
+
* import { Array } from "effect"
|
|
5253
|
+
*
|
|
5254
|
+
* const numbers = [1, 1, 2, 2, 3, 3]
|
|
5255
|
+
* const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)
|
|
5256
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5257
|
+
*
|
|
5258
|
+
* @since 2.0.0
|
|
5259
|
+
*/
|
|
2802
5260
|
<A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>
|
|
5261
|
+
/**
|
|
5262
|
+
* Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.
|
|
5263
|
+
*
|
|
5264
|
+
* @example
|
|
5265
|
+
* import { Array } from "effect"
|
|
5266
|
+
*
|
|
5267
|
+
* const numbers = [1, 1, 2, 2, 3, 3]
|
|
5268
|
+
* const unique = Array.dedupeAdjacentWith(numbers, (a, b) => a === b)
|
|
5269
|
+
* assert.deepStrictEqual(unique, [1, 2, 3])
|
|
5270
|
+
*
|
|
5271
|
+
* @since 2.0.0
|
|
5272
|
+
*/
|
|
2803
5273
|
<A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>
|
|
2804
5274
|
} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {
|
|
2805
5275
|
const out: Array<A> = []
|
|
@@ -2841,7 +5311,33 @@ export const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacent
|
|
|
2841
5311
|
* @category folding
|
|
2842
5312
|
*/
|
|
2843
5313
|
export const join: {
|
|
5314
|
+
/**
|
|
5315
|
+
* Joins the elements together with "sep" in the middle.
|
|
5316
|
+
*
|
|
5317
|
+
* @example
|
|
5318
|
+
* import { Array } from "effect"
|
|
5319
|
+
*
|
|
5320
|
+
* const strings = ["a", "b", "c"]
|
|
5321
|
+
* const joined = Array.join(strings, "-")
|
|
5322
|
+
* assert.deepStrictEqual(joined, "a-b-c")
|
|
5323
|
+
*
|
|
5324
|
+
* @since 2.0.0
|
|
5325
|
+
* @category folding
|
|
5326
|
+
*/
|
|
2844
5327
|
(sep: string): (self: Iterable<string>) => string
|
|
5328
|
+
/**
|
|
5329
|
+
* Joins the elements together with "sep" in the middle.
|
|
5330
|
+
*
|
|
5331
|
+
* @example
|
|
5332
|
+
* import { Array } from "effect"
|
|
5333
|
+
*
|
|
5334
|
+
* const strings = ["a", "b", "c"]
|
|
5335
|
+
* const joined = Array.join(strings, "-")
|
|
5336
|
+
* assert.deepStrictEqual(joined, "a-b-c")
|
|
5337
|
+
*
|
|
5338
|
+
* @since 2.0.0
|
|
5339
|
+
* @category folding
|
|
5340
|
+
*/
|
|
2845
5341
|
(self: Iterable<string>, sep: string): string
|
|
2846
5342
|
} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))
|
|
2847
5343
|
|
|
@@ -2859,11 +5355,41 @@ export const join: {
|
|
|
2859
5355
|
* @category folding
|
|
2860
5356
|
*/
|
|
2861
5357
|
export const mapAccum: {
|
|
2862
|
-
|
|
5358
|
+
/**
|
|
5359
|
+
* Statefully maps over the chunk, producing new elements of type `B`.
|
|
5360
|
+
*
|
|
5361
|
+
* @example
|
|
5362
|
+
* import { Array } from "effect"
|
|
5363
|
+
*
|
|
5364
|
+
* const numbers = [1, 2, 3]
|
|
5365
|
+
* const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])
|
|
5366
|
+
* assert.deepStrictEqual(result, [6, [1, 3, 6]])
|
|
5367
|
+
*
|
|
5368
|
+
* @since 2.0.0
|
|
5369
|
+
* @category folding
|
|
5370
|
+
*/
|
|
5371
|
+
<S, A, B, I extends Iterable<A> = Iterable<A>>(
|
|
2863
5372
|
s: S,
|
|
2864
|
-
f: (s: S, a:
|
|
2865
|
-
): (self:
|
|
2866
|
-
|
|
5373
|
+
f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]
|
|
5374
|
+
): (self: I) => [state: S, mappedArray: ReadonlyArray.With<I, B>]
|
|
5375
|
+
/**
|
|
5376
|
+
* Statefully maps over the chunk, producing new elements of type `B`.
|
|
5377
|
+
*
|
|
5378
|
+
* @example
|
|
5379
|
+
* import { Array } from "effect"
|
|
5380
|
+
*
|
|
5381
|
+
* const numbers = [1, 2, 3]
|
|
5382
|
+
* const result = Array.mapAccum(numbers, 0, (acc, n) => [acc + n, acc + n])
|
|
5383
|
+
* assert.deepStrictEqual(result, [6, [1, 3, 6]])
|
|
5384
|
+
*
|
|
5385
|
+
* @since 2.0.0
|
|
5386
|
+
* @category folding
|
|
5387
|
+
*/
|
|
5388
|
+
<S, A, B, I extends Iterable<A> = Iterable<A>>(
|
|
5389
|
+
self: I,
|
|
5390
|
+
s: S,
|
|
5391
|
+
f: (s: S, a: ReadonlyArray.Infer<I>, i: number) => readonly [S, B]
|
|
5392
|
+
): [state: S, mappedArray: ReadonlyArray.With<I, B>]
|
|
2867
5393
|
} = dual(
|
|
2868
5394
|
3,
|
|
2869
5395
|
<S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A, i: number) => [S, B]): [state: S, mappedArray: Array<B>] => {
|
|
@@ -2895,7 +5421,35 @@ export const mapAccum: {
|
|
|
2895
5421
|
* @category elements
|
|
2896
5422
|
*/
|
|
2897
5423
|
export const cartesianWith: {
|
|
5424
|
+
/**
|
|
5425
|
+
* Zips this chunk crosswise with the specified chunk using the specified combiner.
|
|
5426
|
+
*
|
|
5427
|
+
* @example
|
|
5428
|
+
* import { Array } from "effect"
|
|
5429
|
+
*
|
|
5430
|
+
* const array1 = [1, 2]
|
|
5431
|
+
* const array2 = ["a", "b"]
|
|
5432
|
+
* const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)
|
|
5433
|
+
* assert.deepStrictEqual(product, ["1-a", "1-b", "2-a", "2-b"])
|
|
5434
|
+
*
|
|
5435
|
+
* @since 2.0.0
|
|
5436
|
+
* @category elements
|
|
5437
|
+
*/
|
|
2898
5438
|
<A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>
|
|
5439
|
+
/**
|
|
5440
|
+
* Zips this chunk crosswise with the specified chunk using the specified combiner.
|
|
5441
|
+
*
|
|
5442
|
+
* @example
|
|
5443
|
+
* import { Array } from "effect"
|
|
5444
|
+
*
|
|
5445
|
+
* const array1 = [1, 2]
|
|
5446
|
+
* const array2 = ["a", "b"]
|
|
5447
|
+
* const product = Array.cartesianWith(array1, array2, (a, b) => `${a}-${b}`)
|
|
5448
|
+
* assert.deepStrictEqual(product, ["1-a", "1-b", "2-a", "2-b"])
|
|
5449
|
+
*
|
|
5450
|
+
* @since 2.0.0
|
|
5451
|
+
* @category elements
|
|
5452
|
+
*/
|
|
2899
5453
|
<A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>
|
|
2900
5454
|
} = dual(
|
|
2901
5455
|
3,
|
|
@@ -2918,7 +5472,35 @@ export const cartesianWith: {
|
|
|
2918
5472
|
* @category elements
|
|
2919
5473
|
*/
|
|
2920
5474
|
export const cartesian: {
|
|
5475
|
+
/**
|
|
5476
|
+
* Zips this chunk crosswise with the specified chunk.
|
|
5477
|
+
*
|
|
5478
|
+
* @example
|
|
5479
|
+
* import { Array } from "effect"
|
|
5480
|
+
*
|
|
5481
|
+
* const array1 = [1, 2]
|
|
5482
|
+
* const array2 = ["a", "b"]
|
|
5483
|
+
* const product = Array.cartesian(array1, array2)
|
|
5484
|
+
* assert.deepStrictEqual(product, [[1, "a"], [1, "b"], [2, "a"], [2, "b"]])
|
|
5485
|
+
*
|
|
5486
|
+
* @since 2.0.0
|
|
5487
|
+
* @category elements
|
|
5488
|
+
*/
|
|
2921
5489
|
<B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>
|
|
5490
|
+
/**
|
|
5491
|
+
* Zips this chunk crosswise with the specified chunk.
|
|
5492
|
+
*
|
|
5493
|
+
* @example
|
|
5494
|
+
* import { Array } from "effect"
|
|
5495
|
+
*
|
|
5496
|
+
* const array1 = [1, 2]
|
|
5497
|
+
* const array2 = ["a", "b"]
|
|
5498
|
+
* const product = Array.cartesian(array1, array2)
|
|
5499
|
+
* assert.deepStrictEqual(product, [[1, "a"], [1, "b"], [2, "a"], [2, "b"]])
|
|
5500
|
+
*
|
|
5501
|
+
* @since 2.0.0
|
|
5502
|
+
* @category elements
|
|
5503
|
+
*/
|
|
2922
5504
|
<A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>
|
|
2923
5505
|
} = dual(
|
|
2924
5506
|
2,
|
|
@@ -3018,12 +5600,95 @@ export const Do: ReadonlyArray<{}> = of({})
|
|
|
3018
5600
|
* @since 3.2.0
|
|
3019
5601
|
*/
|
|
3020
5602
|
export const bind: {
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
5603
|
+
/**
|
|
5604
|
+
* 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.
|
|
5605
|
+
*
|
|
5606
|
+
* It can be used to simulate "array comprehension".
|
|
5607
|
+
* 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.
|
|
5608
|
+
*
|
|
5609
|
+
* Here's how the do simulation works:
|
|
5610
|
+
*
|
|
5611
|
+
* 1. Start the do simulation using the `Do` value
|
|
5612
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
5613
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
5614
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
5615
|
+
* 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
|
|
5616
|
+
*
|
|
5617
|
+
* @see {@link bindTo}
|
|
5618
|
+
* @see {@link Do}
|
|
5619
|
+
* @see {@link let_ let}
|
|
5620
|
+
*
|
|
5621
|
+
* @example
|
|
5622
|
+
* import { Array as Arr, pipe } from "effect"
|
|
5623
|
+
* const doResult = pipe(
|
|
5624
|
+
* Arr.Do,
|
|
5625
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
5626
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
5627
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
5628
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
5629
|
+
* )
|
|
5630
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
5631
|
+
*
|
|
5632
|
+
* // equivalent
|
|
5633
|
+
* const x = [1, 3, 5],
|
|
5634
|
+
* y = [2, 4, 6],
|
|
5635
|
+
* result = [];
|
|
5636
|
+
* for(let i = 0; i < x.length; i++) {
|
|
5637
|
+
* for(let j = 0; j < y.length; j++) {
|
|
5638
|
+
* const _x = x[i], _y = y[j];
|
|
5639
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
5640
|
+
* }
|
|
5641
|
+
* }
|
|
5642
|
+
*
|
|
5643
|
+
* @category do notation
|
|
5644
|
+
* @since 3.2.0
|
|
5645
|
+
*/
|
|
5646
|
+
<A extends object, N extends string, B>(tag: Exclude<N, keyof A>, f: (a: A) => ReadonlyArray<B>): (
|
|
3025
5647
|
self: ReadonlyArray<A>
|
|
3026
5648
|
) => Array<{ [K in N | keyof A]: K extends keyof A ? A[K] : B }>
|
|
5649
|
+
/**
|
|
5650
|
+
* 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.
|
|
5651
|
+
*
|
|
5652
|
+
* It can be used to simulate "array comprehension".
|
|
5653
|
+
* 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.
|
|
5654
|
+
*
|
|
5655
|
+
* Here's how the do simulation works:
|
|
5656
|
+
*
|
|
5657
|
+
* 1. Start the do simulation using the `Do` value
|
|
5658
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
5659
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
5660
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
5661
|
+
* 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
|
|
5662
|
+
*
|
|
5663
|
+
* @see {@link bindTo}
|
|
5664
|
+
* @see {@link Do}
|
|
5665
|
+
* @see {@link let_ let}
|
|
5666
|
+
*
|
|
5667
|
+
* @example
|
|
5668
|
+
* import { Array as Arr, pipe } from "effect"
|
|
5669
|
+
* const doResult = pipe(
|
|
5670
|
+
* Arr.Do,
|
|
5671
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
5672
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
5673
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
5674
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
5675
|
+
* )
|
|
5676
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
5677
|
+
*
|
|
5678
|
+
* // equivalent
|
|
5679
|
+
* const x = [1, 3, 5],
|
|
5680
|
+
* y = [2, 4, 6],
|
|
5681
|
+
* result = [];
|
|
5682
|
+
* for(let i = 0; i < x.length; i++) {
|
|
5683
|
+
* for(let j = 0; j < y.length; j++) {
|
|
5684
|
+
* const _x = x[i], _y = y[j];
|
|
5685
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
5686
|
+
* }
|
|
5687
|
+
* }
|
|
5688
|
+
*
|
|
5689
|
+
* @category do notation
|
|
5690
|
+
* @since 3.2.0
|
|
5691
|
+
*/
|
|
3027
5692
|
<A extends object, N extends string, B>(
|
|
3028
5693
|
self: ReadonlyArray<A>,
|
|
3029
5694
|
tag: Exclude<N, keyof A>,
|
|
@@ -3075,7 +5740,93 @@ export const bind: {
|
|
|
3075
5740
|
* @since 3.2.0
|
|
3076
5741
|
*/
|
|
3077
5742
|
export const bindTo: {
|
|
5743
|
+
/**
|
|
5744
|
+
* 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.
|
|
5745
|
+
*
|
|
5746
|
+
* It can be used to simulate "array comprehension".
|
|
5747
|
+
* 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.
|
|
5748
|
+
*
|
|
5749
|
+
* Here's how the do simulation works:
|
|
5750
|
+
*
|
|
5751
|
+
* 1. Start the do simulation using the `Do` value
|
|
5752
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
5753
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
5754
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
5755
|
+
* 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
|
|
5756
|
+
*
|
|
5757
|
+
* @see {@link bindTo}
|
|
5758
|
+
* @see {@link Do}
|
|
5759
|
+
* @see {@link let_ let}
|
|
5760
|
+
*
|
|
5761
|
+
* @example
|
|
5762
|
+
* import { Array as Arr, pipe } from "effect"
|
|
5763
|
+
* const doResult = pipe(
|
|
5764
|
+
* Arr.Do,
|
|
5765
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
5766
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
5767
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
5768
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
5769
|
+
* )
|
|
5770
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
5771
|
+
*
|
|
5772
|
+
* // equivalent
|
|
5773
|
+
* const x = [1, 3, 5],
|
|
5774
|
+
* y = [2, 4, 6],
|
|
5775
|
+
* result = [];
|
|
5776
|
+
* for(let i = 0; i < x.length; i++) {
|
|
5777
|
+
* for(let j = 0; j < y.length; j++) {
|
|
5778
|
+
* const _x = x[i], _y = y[j];
|
|
5779
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
5780
|
+
* }
|
|
5781
|
+
* }
|
|
5782
|
+
*
|
|
5783
|
+
* @category do notation
|
|
5784
|
+
* @since 3.2.0
|
|
5785
|
+
*/
|
|
3078
5786
|
<N extends string>(tag: N): <A>(self: ReadonlyArray<A>) => Array<{ [K in N]: A }>
|
|
5787
|
+
/**
|
|
5788
|
+
* 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.
|
|
5789
|
+
*
|
|
5790
|
+
* It can be used to simulate "array comprehension".
|
|
5791
|
+
* 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.
|
|
5792
|
+
*
|
|
5793
|
+
* Here's how the do simulation works:
|
|
5794
|
+
*
|
|
5795
|
+
* 1. Start the do simulation using the `Do` value
|
|
5796
|
+
* 2. Within the do simulation scope, you can use the `bind` function to define variables and bind them to `Array` values
|
|
5797
|
+
* 3. You can accumulate multiple `bind` statements to define multiple variables within the scope
|
|
5798
|
+
* 4. Inside the do simulation scope, you can also use the `let` function to define variables and bind them to simple values
|
|
5799
|
+
* 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
|
|
5800
|
+
*
|
|
5801
|
+
* @see {@link bindTo}
|
|
5802
|
+
* @see {@link Do}
|
|
5803
|
+
* @see {@link let_ let}
|
|
5804
|
+
*
|
|
5805
|
+
* @example
|
|
5806
|
+
* import { Array as Arr, pipe } from "effect"
|
|
5807
|
+
* const doResult = pipe(
|
|
5808
|
+
* Arr.Do,
|
|
5809
|
+
* Arr.bind("x", () => [1, 3, 5]),
|
|
5810
|
+
* Arr.bind("y", () => [2, 4, 6]),
|
|
5811
|
+
* Arr.filter(({ x, y }) => x < y), // condition
|
|
5812
|
+
* Arr.map(({ x, y }) => [x, y] as const) // transformation
|
|
5813
|
+
* )
|
|
5814
|
+
* assert.deepStrictEqual(doResult, [[1, 2], [1, 4], [1, 6], [3, 4], [3, 6], [5, 6]])
|
|
5815
|
+
*
|
|
5816
|
+
* // equivalent
|
|
5817
|
+
* const x = [1, 3, 5],
|
|
5818
|
+
* y = [2, 4, 6],
|
|
5819
|
+
* result = [];
|
|
5820
|
+
* for(let i = 0; i < x.length; i++) {
|
|
5821
|
+
* for(let j = 0; j < y.length; j++) {
|
|
5822
|
+
* const _x = x[i], _y = y[j];
|
|
5823
|
+
* if(_x < _y) result.push([_x, _y] as const)
|
|
5824
|
+
* }
|
|
5825
|
+
* }
|
|
5826
|
+
*
|
|
5827
|
+
* @category do notation
|
|
5828
|
+
* @since 3.2.0
|
|
5829
|
+
*/
|
|
3079
5830
|
<A, N extends string>(self: ReadonlyArray<A>, tag: N): Array<{ [K in N]: A }>
|
|
3080
5831
|
} = doNotation.bindTo<ReadonlyArrayTypeLambda>(map) as any
|
|
3081
5832
|
|