effect 2.0.0-next.44 → 2.0.0-next.46
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/Bigint/dist/effect-Bigint.cjs.dev.js +125 -1
- package/Bigint/dist/effect-Bigint.cjs.mjs +6 -1
- package/Bigint/dist/effect-Bigint.cjs.prod.js +125 -1
- package/Bigint/dist/effect-Bigint.esm.js +111 -2
- package/Boolean/dist/effect-Boolean.cjs.dev.js +1 -1
- package/Boolean/dist/effect-Boolean.cjs.prod.js +1 -1
- package/Boolean/dist/effect-Boolean.esm.js +1 -1
- package/Brand/dist/effect-Brand.cjs.dev.js +3 -3
- package/Brand/dist/effect-Brand.cjs.prod.js +3 -3
- package/Cache/dist/effect-Cache.cjs.dev.js +32 -32
- package/Cache/dist/effect-Cache.cjs.prod.js +32 -32
- package/Cause/dist/effect-Cause.cjs.dev.js +17 -17
- package/Cause/dist/effect-Cause.cjs.mjs +1 -1
- package/Cause/dist/effect-Cause.cjs.prod.js +17 -17
- package/Cause/dist/effect-Cause.esm.js +4 -4
- package/Channel/dist/effect-Channel.cjs.dev.js +50 -50
- package/Channel/dist/effect-Channel.cjs.mjs +3 -3
- package/Channel/dist/effect-Channel.cjs.prod.js +50 -50
- package/Channel/dist/effect-Channel.esm.js +8 -8
- package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.dev.js +36 -36
- package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.prod.js +36 -36
- package/Chunk/dist/effect-Chunk.cjs.dev.js +3 -3
- package/Chunk/dist/effect-Chunk.cjs.prod.js +3 -3
- package/Clock/dist/effect-Clock.cjs.dev.js +16 -16
- package/Clock/dist/effect-Clock.cjs.prod.js +16 -16
- package/Config/dist/effect-Config.cjs.dev.js +11 -11
- package/Config/dist/effect-Config.cjs.prod.js +11 -11
- package/ConfigError/dist/effect-ConfigError.cjs.dev.js +4 -4
- package/ConfigError/dist/effect-ConfigError.cjs.prod.js +4 -4
- package/ConfigProvider/dist/effect-ConfigProvider.cjs.dev.js +17 -17
- package/ConfigProvider/dist/effect-ConfigProvider.cjs.prod.js +17 -17
- package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.dev.js +5 -5
- package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.prod.js +5 -5
- package/ConfigSecret/dist/effect-ConfigSecret.cjs.dev.js +4 -4
- package/ConfigSecret/dist/effect-ConfigSecret.cjs.prod.js +4 -4
- package/Console/dist/effect-Console.cjs.dev.js +35 -35
- package/Console/dist/effect-Console.cjs.prod.js +35 -35
- package/Context/dist/effect-Context.cjs.dev.js +3 -8
- package/Context/dist/effect-Context.cjs.prod.js +3 -8
- package/Data/dist/effect-Data.cjs.dev.js +141 -54
- package/Data/dist/effect-Data.cjs.mjs +2 -0
- package/Data/dist/effect-Data.cjs.prod.js +141 -54
- package/Data/dist/effect-Data.esm.js +51 -3
- package/DefaultServices/dist/effect-DefaultServices.cjs.dev.js +16 -16
- package/DefaultServices/dist/effect-DefaultServices.cjs.prod.js +16 -16
- package/Deferred/dist/effect-Deferred.cjs.dev.js +8 -8
- package/Deferred/dist/effect-Deferred.cjs.prod.js +8 -8
- package/Differ/dist/effect-Differ.cjs.dev.js +11 -11
- package/Differ/dist/effect-Differ.cjs.prod.js +11 -11
- package/Duration/dist/effect-Duration.cjs.dev.js +3 -3
- package/Duration/dist/effect-Duration.cjs.prod.js +3 -3
- package/Effect/dist/effect-Effect.cjs.dev.js +44 -44
- package/Effect/dist/effect-Effect.cjs.prod.js +44 -44
- package/Effectable/dist/effect-Effectable.cjs.dev.js +24 -14
- package/Effectable/dist/effect-Effectable.cjs.mjs +5 -4
- package/Effectable/dist/effect-Effectable.cjs.prod.js +24 -14
- package/Effectable/dist/effect-Effectable.esm.js +15 -5
- package/Either/dist/effect-Either.cjs.dev.js +3 -3
- package/Either/dist/effect-Either.cjs.prod.js +3 -3
- package/Encoding/dist/effect-Encoding.cjs.dev.js +3 -3
- package/Encoding/dist/effect-Encoding.cjs.prod.js +3 -3
- package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.dev.js +2 -2
- package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.prod.js +2 -2
- package/Exit/dist/effect-Exit.cjs.dev.js +8 -8
- package/Exit/dist/effect-Exit.cjs.prod.js +8 -8
- package/Fiber/dist/effect-Fiber.cjs.dev.js +29 -29
- package/Fiber/dist/effect-Fiber.cjs.prod.js +29 -29
- package/FiberId/dist/effect-FiberId.cjs.dev.js +5 -5
- package/FiberId/dist/effect-FiberId.cjs.prod.js +5 -5
- package/FiberRef/dist/effect-FiberRef.cjs.dev.js +29 -29
- package/FiberRef/dist/effect-FiberRef.cjs.prod.js +29 -29
- package/FiberRefs/dist/effect-FiberRefs.cjs.dev.js +9 -9
- package/FiberRefs/dist/effect-FiberRefs.cjs.prod.js +9 -9
- package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.dev.js +10 -10
- package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.prod.js +10 -10
- package/GroupBy/dist/effect-GroupBy.cjs.dev.js +42 -42
- package/GroupBy/dist/effect-GroupBy.cjs.prod.js +42 -42
- package/HashMap/dist/effect-HashMap.cjs.dev.js +20 -20
- package/HashMap/dist/effect-HashMap.cjs.prod.js +20 -20
- package/HashSet/dist/effect-HashSet.cjs.dev.js +20 -20
- package/HashSet/dist/effect-HashSet.cjs.prod.js +20 -20
- package/KeyedPool/dist/effect-KeyedPool.cjs.dev.js +33 -33
- package/KeyedPool/dist/effect-KeyedPool.cjs.prod.js +33 -33
- package/Layer/dist/effect-Layer.cjs.dev.js +32 -32
- package/Layer/dist/effect-Layer.cjs.prod.js +32 -32
- package/List/dist/effect-List.cjs.dev.js +3 -3
- package/List/dist/effect-List.cjs.prod.js +3 -3
- package/LogLevel/dist/effect-LogLevel.cjs.dev.js +8 -8
- package/LogLevel/dist/effect-LogLevel.cjs.prod.js +8 -8
- package/Logger/dist/effect-Logger.cjs.dev.js +33 -33
- package/Logger/dist/effect-Logger.cjs.prod.js +33 -33
- package/Metric/dist/effect-Metric.cjs.dev.js +27 -27
- package/Metric/dist/effect-Metric.cjs.prod.js +27 -27
- package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.dev.js +4 -4
- package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.prod.js +4 -4
- package/MetricHook/dist/effect-MetricHook.cjs.dev.js +6 -6
- package/MetricHook/dist/effect-MetricHook.cjs.prod.js +6 -6
- package/MetricKey/dist/effect-MetricKey.cjs.dev.js +6 -6
- package/MetricKey/dist/effect-MetricKey.cjs.prod.js +6 -6
- package/MetricKeyType/dist/effect-MetricKeyType.cjs.dev.js +4 -4
- package/MetricKeyType/dist/effect-MetricKeyType.cjs.prod.js +4 -4
- package/MetricPolling/dist/effect-MetricPolling.cjs.dev.js +30 -30
- package/MetricPolling/dist/effect-MetricPolling.cjs.prod.js +30 -30
- package/MetricRegistry/dist/effect-MetricRegistry.cjs.dev.js +8 -8
- package/MetricRegistry/dist/effect-MetricRegistry.cjs.prod.js +8 -8
- package/MetricState/dist/effect-MetricState.cjs.dev.js +1 -1
- package/MetricState/dist/effect-MetricState.cjs.prod.js +1 -1
- package/MutableHashMap/dist/effect-MutableHashMap.cjs.dev.js +4 -4
- package/MutableHashMap/dist/effect-MutableHashMap.cjs.prod.js +4 -4
- package/MutableHashSet/dist/effect-MutableHashSet.cjs.dev.js +4 -4
- package/MutableHashSet/dist/effect-MutableHashSet.cjs.prod.js +4 -4
- package/MutableQueue/dist/effect-MutableQueue.cjs.dev.js +3 -3
- package/MutableQueue/dist/effect-MutableQueue.cjs.prod.js +3 -3
- package/Number/dist/effect-Number.cjs.dev.js +1 -1
- package/Number/dist/effect-Number.cjs.prod.js +1 -1
- package/Number/dist/effect-Number.esm.js +1 -1
- package/Option/dist/effect-Option.cjs.dev.js +9 -9
- package/Option/dist/effect-Option.cjs.prod.js +9 -9
- package/Pool/dist/effect-Pool.cjs.dev.js +31 -31
- package/Pool/dist/effect-Pool.cjs.prod.js +31 -31
- package/PubSub/dist/effect-PubSub.cjs.d.mts +2 -0
- package/PubSub/dist/effect-PubSub.cjs.d.mts.map +1 -0
- package/PubSub/dist/effect-PubSub.cjs.d.ts +2 -0
- package/PubSub/dist/effect-PubSub.cjs.d.ts.map +1 -0
- package/{Hub/dist/effect-Hub.cjs.dev.js → PubSub/dist/effect-PubSub.cjs.dev.js} +163 -163
- package/PubSub/dist/effect-PubSub.cjs.js +7 -0
- package/{Hub/dist/effect-Hub.cjs.mjs → PubSub/dist/effect-PubSub.cjs.mjs} +1 -1
- package/{Hub/dist/effect-Hub.cjs.prod.js → PubSub/dist/effect-PubSub.cjs.prod.js} +163 -163
- package/{Hub/dist/effect-Hub.esm.js → PubSub/dist/effect-PubSub.esm.js} +15 -15
- package/PubSub/package.json +4 -0
- package/Queue/dist/effect-Queue.cjs.dev.js +28 -28
- package/Queue/dist/effect-Queue.cjs.prod.js +28 -28
- package/README.md +5 -5
- package/Random/dist/effect-Random.cjs.dev.js +16 -16
- package/Random/dist/effect-Random.cjs.prod.js +16 -16
- package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.dev.js +3 -3
- package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.prod.js +3 -3
- package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.dev.js +3 -3
- package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.prod.js +3 -3
- package/RedBlackTree/dist/effect-RedBlackTree.cjs.dev.js +4 -4
- package/RedBlackTree/dist/effect-RedBlackTree.cjs.prod.js +4 -4
- package/Ref/dist/effect-Ref.cjs.dev.js +9 -9
- package/Ref/dist/effect-Ref.cjs.prod.js +9 -9
- package/Reloadable/dist/effect-Reloadable.cjs.dev.js +44 -44
- package/Reloadable/dist/effect-Reloadable.cjs.prod.js +44 -44
- package/Request/dist/effect-Request.cjs.dev.js +29 -29
- package/Request/dist/effect-Request.cjs.prod.js +29 -29
- package/RequestBlock/dist/effect-RequestBlock.cjs.dev.js +36 -36
- package/RequestBlock/dist/effect-RequestBlock.cjs.prod.js +36 -36
- package/RequestResolver/dist/effect-RequestResolver.cjs.dev.js +38 -38
- package/RequestResolver/dist/effect-RequestResolver.cjs.prod.js +38 -38
- package/Resource/dist/effect-Resource.cjs.dev.js +34 -34
- package/Resource/dist/effect-Resource.cjs.prod.js +34 -34
- package/Runtime/dist/effect-Runtime.cjs.dev.js +34 -34
- package/Runtime/dist/effect-Runtime.cjs.prod.js +34 -34
- package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.dev.js +33 -33
- package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.prod.js +33 -33
- package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.dev.js +6 -6
- package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.prod.js +6 -6
- package/STM/dist/effect-STM.cjs.dev.js +48 -48
- package/STM/dist/effect-STM.cjs.prod.js +48 -48
- package/Schedule/dist/effect-Schedule.cjs.dev.js +19 -19
- package/Schedule/dist/effect-Schedule.cjs.prod.js +19 -19
- package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.dev.js +3 -3
- package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.prod.js +3 -3
- package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.dev.js +3 -3
- package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.prod.js +3 -3
- package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.dev.js +3 -3
- package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.prod.js +3 -3
- package/Scheduler/dist/effect-Scheduler.cjs.dev.js +8 -8
- package/Scheduler/dist/effect-Scheduler.cjs.prod.js +8 -8
- package/Scope/dist/effect-Scope.cjs.dev.js +27 -27
- package/Scope/dist/effect-Scope.cjs.prod.js +27 -27
- package/ScopedCache/dist/effect-ScopedCache.cjs.dev.js +78 -61
- package/ScopedCache/dist/effect-ScopedCache.cjs.prod.js +78 -61
- package/ScopedRef/dist/effect-ScopedRef.cjs.dev.js +34 -34
- package/ScopedRef/dist/effect-ScopedRef.cjs.prod.js +34 -34
- package/Sink/dist/effect-Sink.cjs.dev.js +43 -43
- package/Sink/dist/effect-Sink.cjs.mjs +1 -1
- package/Sink/dist/effect-Sink.cjs.prod.js +43 -43
- package/Sink/dist/effect-Sink.esm.js +5 -5
- package/SortedMap/dist/effect-SortedMap.cjs.dev.js +3 -3
- package/SortedMap/dist/effect-SortedMap.cjs.prod.js +3 -3
- package/SortedSet/dist/effect-SortedSet.cjs.dev.js +3 -3
- package/SortedSet/dist/effect-SortedSet.cjs.prod.js +3 -3
- package/Stream/dist/effect-Stream.cjs.dev.js +60 -60
- package/Stream/dist/effect-Stream.cjs.mjs +5 -5
- package/Stream/dist/effect-Stream.cjs.prod.js +60 -60
- package/Stream/dist/effect-Stream.esm.js +15 -15
- package/Streamable/dist/effect-Streamable.cjs.d.mts +2 -0
- package/Streamable/dist/effect-Streamable.cjs.d.mts.map +1 -0
- package/Streamable/dist/effect-Streamable.cjs.d.ts +2 -0
- package/Streamable/dist/effect-Streamable.cjs.d.ts.map +1 -0
- package/Streamable/dist/effect-Streamable.cjs.dev.js +152 -0
- package/Streamable/dist/effect-Streamable.cjs.js +7 -0
- package/Streamable/dist/effect-Streamable.cjs.mjs +3 -0
- package/Streamable/dist/effect-Streamable.cjs.prod.js +152 -0
- package/Streamable/dist/effect-Streamable.esm.js +42 -0
- package/Streamable/package.json +4 -0
- package/String/dist/effect-String.cjs.dev.js +4 -4
- package/String/dist/effect-String.cjs.prod.js +4 -4
- package/String/dist/effect-String.esm.js +1 -1
- package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.dev.js +48 -48
- package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.prod.js +48 -48
- package/Supervisor/dist/effect-Supervisor.cjs.dev.js +34 -34
- package/Supervisor/dist/effect-Supervisor.cjs.prod.js +34 -34
- package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.dev.js +30 -30
- package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.prod.js +30 -30
- package/TArray/dist/effect-TArray.cjs.dev.js +46 -46
- package/TArray/dist/effect-TArray.cjs.prod.js +46 -46
- package/TDeferred/dist/effect-TDeferred.cjs.dev.js +45 -45
- package/TDeferred/dist/effect-TDeferred.cjs.prod.js +45 -45
- package/TMap/dist/effect-TMap.cjs.dev.js +47 -47
- package/TMap/dist/effect-TMap.cjs.prod.js +47 -47
- package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.dev.js +44 -44
- package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.prod.js +44 -44
- package/TPubSub/dist/effect-TPubSub.cjs.d.mts +2 -0
- package/TPubSub/dist/effect-TPubSub.cjs.d.mts.map +1 -0
- package/TPubSub/dist/effect-TPubSub.cjs.d.ts +2 -0
- package/TPubSub/dist/effect-TPubSub.cjs.d.ts.map +1 -0
- package/{THub/dist/effect-THub.cjs.dev.js → TPubSub/dist/effect-TPubSub.cjs.dev.js} +101 -101
- package/TPubSub/dist/effect-TPubSub.cjs.js +7 -0
- package/{THub/dist/effect-THub.cjs.mjs → TPubSub/dist/effect-TPubSub.cjs.mjs} +2 -2
- package/{THub/dist/effect-THub.cjs.prod.js → TPubSub/dist/effect-TPubSub.cjs.prod.js} +101 -101
- package/TPubSub/dist/effect-TPubSub.esm.js +157 -0
- package/TPubSub/package.json +4 -0
- package/TQueue/dist/effect-TQueue.cjs.dev.js +46 -46
- package/TQueue/dist/effect-TQueue.cjs.prod.js +46 -46
- package/TRandom/dist/effect-TRandom.cjs.dev.js +50 -50
- package/TRandom/dist/effect-TRandom.cjs.prod.js +50 -50
- package/TReentrantLock/dist/effect-TReentrantLock.cjs.dev.js +46 -46
- package/TReentrantLock/dist/effect-TReentrantLock.cjs.prod.js +46 -46
- package/TRef/dist/effect-TRef.cjs.dev.js +44 -44
- package/TRef/dist/effect-TRef.cjs.prod.js +44 -44
- package/TSemaphore/dist/effect-TSemaphore.cjs.dev.js +45 -45
- package/TSemaphore/dist/effect-TSemaphore.cjs.prod.js +45 -45
- package/TSet/dist/effect-TSet.cjs.dev.js +47 -47
- package/TSet/dist/effect-TSet.cjs.prod.js +47 -47
- package/Take/dist/effect-Take.cjs.dev.js +36 -36
- package/Take/dist/effect-Take.cjs.prod.js +36 -36
- package/TestAnnotation/dist/effect-TestAnnotation.cjs.dev.js +8 -8
- package/TestAnnotation/dist/effect-TestAnnotation.cjs.prod.js +8 -8
- package/TestAnnotations/dist/effect-TestAnnotations.cjs.dev.js +25 -25
- package/TestAnnotations/dist/effect-TestAnnotations.cjs.prod.js +25 -25
- package/TestClock/dist/effect-TestClock.cjs.dev.js +46 -46
- package/TestClock/dist/effect-TestClock.cjs.prod.js +46 -46
- package/TestConfig/dist/effect-TestConfig.cjs.dev.js +3 -8
- package/TestConfig/dist/effect-TestConfig.cjs.prod.js +3 -8
- package/TestContext/dist/effect-TestContext.cjs.dev.js +37 -37
- package/TestContext/dist/effect-TestContext.cjs.prod.js +37 -37
- package/TestLive/dist/effect-TestLive.cjs.dev.js +17 -17
- package/TestLive/dist/effect-TestLive.cjs.prod.js +17 -17
- package/TestServices/dist/effect-TestServices.cjs.dev.js +42 -42
- package/TestServices/dist/effect-TestServices.cjs.prod.js +42 -42
- package/TestSized/dist/effect-TestSized.cjs.dev.js +11 -11
- package/TestSized/dist/effect-TestSized.cjs.prod.js +11 -11
- package/Tracer/dist/effect-Tracer.cjs.dev.js +16 -16
- package/Tracer/dist/effect-Tracer.cjs.prod.js +16 -16
- package/dist/{Context-01a123ac.cjs.prod.js → Context-9fe5eb16.cjs.prod.js} +5 -5
- package/dist/{Context-593661f6.cjs.dev.js → Context-da73ddfa.cjs.dev.js} +5 -5
- package/dist/{Effectable-2f022879.cjs.dev.js → Effectable-7314aed8.cjs.dev.js} +63 -10
- package/dist/{Effectable-cd8f3a96.cjs.prod.js → Effectable-c4c14a2b.cjs.prod.js} +63 -10
- package/dist/{Either-7a881c7a.cjs.prod.js → Either-d43f082c.cjs.prod.js} +6 -79
- package/dist/{Either-12bbe00c.cjs.dev.js → Either-fa0ef1d9.cjs.dev.js} +6 -79
- package/dist/{ExecutionStrategy-14d3053a.cjs.prod.js → ExecutionStrategy-4808fe5d.cjs.prod.js} +2 -2
- package/dist/{ExecutionStrategy-70f1a920.cjs.dev.js → ExecutionStrategy-7d9d457b.cjs.dev.js} +2 -2
- package/dist/{HashSet-0b4ff1e4.cjs.dev.js → HashSet-5963ad6b.cjs.dev.js} +32 -32
- package/dist/{HashSet-6257b66d.cjs.prod.js → HashSet-ac02a3e1.cjs.prod.js} +32 -32
- package/dist/Option-463b42e6.cjs.dev.js +81 -0
- package/dist/Option-935e5d7c.cjs.prod.js +81 -0
- package/dist/{Ref-a3a4e50d.cjs.prod.js → Ref-4014b526.cjs.prod.js} +1 -1
- package/dist/{Ref-74b592a4.cjs.dev.js → Ref-acdee7ef.cjs.dev.js} +1 -1
- package/dist/{cache-75fbef45.cjs.prod.js → cache-5c7d77e4.cjs.prod.js} +17 -17
- package/dist/{cache-e1ea3923.cjs.dev.js → cache-7eed9d33.cjs.dev.js} +17 -17
- package/dist/{circular-6f16b226.cjs.prod.js → circular-1f481ffb.cjs.prod.js} +33 -33
- package/dist/{circular-f406f9a4.cjs.prod.js → circular-9e10a5a7.cjs.prod.js} +6 -6
- package/dist/{circular-58ff5e9c.cjs.dev.js → circular-c2dbce1a.cjs.dev.js} +33 -33
- package/dist/{circular-30564534.cjs.dev.js → circular-c8b65bdb.cjs.dev.js} +6 -6
- package/dist/{config-80900693.cjs.dev.js → config-3b7935a3.cjs.dev.js} +3 -3
- package/dist/{config-d0ddc159.cjs.prod.js → config-5ba54da1.cjs.prod.js} +3 -3
- package/dist/{configProvider-93617d6d.cjs.prod.js → configProvider-b6b20998.cjs.prod.js} +29 -29
- package/dist/{configProvider-ce43fdbf.cjs.dev.js → configProvider-f34a82f1.cjs.dev.js} +29 -29
- package/dist/{core-0b0539de.cjs.prod.js → core-07202cc0.cjs.prod.js} +711 -726
- package/dist/{core-60ca562a.cjs.prod.js → core-7411d1e1.cjs.prod.js} +3 -3
- package/dist/{core-b4d7b4f5.cjs.dev.js → core-b7401357.cjs.dev.js} +711 -726
- package/dist/{core-13f8a866.cjs.dev.js → core-c5747f88.cjs.dev.js} +3 -3
- package/dist/{core-effect-892f3686.cjs.dev.js → core-effect-1c564d42.cjs.dev.js} +77 -75
- package/dist/{core-effect-c65770cd.cjs.prod.js → core-effect-9201ea63.cjs.prod.js} +77 -75
- package/dist/{dataSource-3ba9e4d3.cjs.dev.js → dataSource-b5eda714.cjs.dev.js} +2 -2
- package/dist/{dataSource-7df3a5f6.cjs.prod.js → dataSource-b83bc277.cjs.prod.js} +2 -2
- package/dist/declarations/src/Bigint.d.ts +92 -1
- package/dist/declarations/src/Bigint.d.ts.map +1 -1
- package/dist/declarations/src/Boolean.d.ts +1 -1
- package/dist/declarations/src/Cause.d.ts +6 -6
- package/dist/declarations/src/Cause.d.ts.map +1 -1
- package/dist/declarations/src/Channel.d.ts +7 -7
- package/dist/declarations/src/Channel.d.ts.map +1 -1
- package/dist/declarations/src/Data.d.ts +30 -0
- package/dist/declarations/src/Data.d.ts.map +1 -1
- package/dist/declarations/src/Effect.d.ts +4 -2
- package/dist/declarations/src/Effect.d.ts.map +1 -1
- package/dist/declarations/src/Effectable.d.ts +14 -4
- package/dist/declarations/src/Effectable.d.ts.map +1 -1
- package/dist/declarations/src/Metric.d.ts +31 -7
- package/dist/declarations/src/Metric.d.ts.map +1 -1
- package/dist/declarations/src/MetricHook.d.ts +7 -4
- package/dist/declarations/src/MetricHook.d.ts.map +1 -1
- package/dist/declarations/src/MetricKey.d.ts +24 -4
- package/dist/declarations/src/MetricKey.d.ts.map +1 -1
- package/dist/declarations/src/MetricKeyType.d.ts +9 -6
- package/dist/declarations/src/MetricKeyType.d.ts.map +1 -1
- package/dist/declarations/src/MetricRegistry.d.ts +2 -2
- package/dist/declarations/src/MetricRegistry.d.ts.map +1 -1
- package/dist/declarations/src/MetricState.d.ts +15 -9
- package/dist/declarations/src/MetricState.d.ts.map +1 -1
- package/dist/declarations/src/Number.d.ts +1 -1
- package/dist/declarations/src/{Hub.d.ts → PubSub.d.ts} +38 -38
- package/dist/declarations/src/PubSub.d.ts.map +1 -0
- package/dist/declarations/src/Sink.d.ts +4 -4
- package/dist/declarations/src/Sink.d.ts.map +1 -1
- package/dist/declarations/src/Stream.d.ts +24 -24
- package/dist/declarations/src/Stream.d.ts.map +1 -1
- package/dist/declarations/src/Streamable.d.ts +27 -0
- package/dist/declarations/src/Streamable.d.ts.map +1 -0
- package/dist/declarations/src/String.d.ts +1 -1
- package/dist/declarations/src/SubscriptionRef.d.ts.map +1 -1
- package/dist/declarations/src/TPubSub.d.ts +146 -0
- package/dist/declarations/src/TPubSub.d.ts.map +1 -0
- package/dist/declarations/src/index.d.ts +15 -15
- package/dist/declarations/src/index.d.ts.map +1 -1
- package/dist/{defaultServices-5530ff0e.cjs.dev.js → defaultServices-755d5b46.cjs.dev.js} +6 -6
- package/dist/{defaultServices-086b8ac9.cjs.prod.js → defaultServices-9d7ce86f.cjs.prod.js} +6 -6
- package/dist/effect.cjs.dev.js +9 -9
- package/dist/effect.cjs.mjs +3 -3
- package/dist/effect.cjs.prod.js +9 -9
- package/dist/effect.esm.js +6 -6
- package/dist/{fiber-1bfb4c1d.cjs.dev.js → fiber-5156eff2.cjs.dev.js} +12 -12
- package/dist/{fiber-2eb0a4c1.cjs.prod.js → fiber-9519d109.cjs.prod.js} +12 -12
- package/dist/{fiberRefs-be6b6a70.cjs.prod.js → fiberRefs-558c17e6.cjs.prod.js} +1 -1
- package/dist/{fiberRefs-be4fae6a.cjs.dev.js → fiberRefs-98b71233.cjs.dev.js} +1 -1
- package/dist/{fiberRuntime-2d31e120.cjs.prod.js → fiberRuntime-31ae011f.cjs.prod.js} +99 -100
- package/dist/{fiberRuntime-c7280769.cjs.dev.js → fiberRuntime-d3872282.cjs.dev.js} +99 -100
- package/dist/{groupBy-0702739b.cjs.prod.js → groupBy-724f64ef.cjs.prod.js} +4 -4
- package/dist/{groupBy-7f852bf3.cjs.dev.js → groupBy-862cc2da.cjs.dev.js} +4 -4
- package/dist/{hook-e72b20fd.cjs.dev.js → hook-8cefc909.cjs.dev.js} +8 -4
- package/dist/{hook-470b717e.cjs.prod.js → hook-98ce30e4.cjs.prod.js} +8 -4
- package/dist/{key-f0a1408a.cjs.dev.js → key-198b6670.cjs.dev.js} +3 -3
- package/dist/{key-378a6a2c.cjs.prod.js → key-eb8a12b2.cjs.prod.js} +3 -3
- package/dist/{keyType-cf67c69c.cjs.prod.js → keyType-0c5e6178.cjs.prod.js} +9 -2
- package/dist/{keyType-55f27f07.cjs.dev.js → keyType-7c164b82.cjs.dev.js} +9 -2
- package/dist/{layer-b42e8022.cjs.dev.js → layer-29574350.cjs.dev.js} +33 -33
- package/dist/{layer-d103b49b.cjs.prod.js → layer-51ff4846.cjs.prod.js} +33 -33
- package/dist/{patch-a1b2802f.cjs.dev.js → patch-0220a642.cjs.dev.js} +1 -1
- package/dist/{patch-c4d6c61e.cjs.prod.js → patch-7c559bb2.cjs.prod.js} +1 -1
- package/dist/{pathPatch-15c8d723.cjs.prod.js → pathPatch-b56a4da2.cjs.prod.js} +1 -1
- package/dist/{pathPatch-d9d41297.cjs.dev.js → pathPatch-fab016f1.cjs.dev.js} +1 -1
- package/dist/{pool-ef44ba82.cjs.dev.js → pool-3211287f.cjs.dev.js} +31 -31
- package/dist/{pool-e414eb88.cjs.prod.js → pool-f77d7705.cjs.prod.js} +31 -31
- package/dist/{query-1d0157db.cjs.prod.js → query-a52b25f0.cjs.prod.js} +11 -11
- package/dist/{query-54337864.cjs.dev.js → query-c36decd5.cjs.dev.js} +11 -11
- package/dist/{queue-27ac9d98.cjs.prod.js → queue-315ea45d.cjs.prod.js} +22 -22
- package/dist/{queue-533d70d4.cjs.dev.js → queue-7a223c44.cjs.dev.js} +22 -22
- package/dist/{registry-1099de3f.cjs.dev.js → registry-62ff192e.cjs.dev.js} +4 -4
- package/dist/{registry-013ecdde.cjs.prod.js → registry-d5258dff.cjs.prod.js} +4 -4
- package/dist/{runtime-ea174155.cjs.prod.js → runtime-005f8a9b.cjs.prod.js} +7 -7
- package/dist/{runtime-afad6a9b.cjs.dev.js → runtime-57c8ddf8.cjs.dev.js} +7 -7
- package/dist/{schedule-1d92198c.cjs.prod.js → schedule-8cdf6bf1.cjs.prod.js} +40 -40
- package/dist/{schedule-e0f55cab.cjs.dev.js → schedule-e7a9f93f.cjs.dev.js} +40 -40
- package/dist/scopedRef-789d7fef.cjs.prod.js +55 -0
- package/dist/scopedRef-eb19c7a6.cjs.dev.js +55 -0
- package/dist/{singleProducerAsyncInput-4105a342.cjs.dev.js → singleProducerAsyncInput-9ff8389b.cjs.dev.js} +1 -1
- package/dist/{singleProducerAsyncInput-21463e16.cjs.prod.js → singleProducerAsyncInput-f9b258b1.cjs.prod.js} +1 -1
- package/dist/{sink-9129504b.cjs.prod.js → sink-572d8981.cjs.prod.js} +17 -17
- package/dist/{sink-ee393b63.cjs.dev.js → sink-8d3427e7.cjs.dev.js} +17 -17
- package/dist/{state-dd1bd066.cjs.prod.js → state-0bdf02b7.cjs.prod.js} +2 -6
- package/dist/{state-8fbec044.cjs.dev.js → state-931050c4.cjs.dev.js} +2 -6
- package/dist/{stm-537da66b.cjs.dev.js → stm-8aca0022.cjs.dev.js} +3 -3
- package/dist/{stm-5043c3cb.cjs.prod.js → stm-f250b596.cjs.prod.js} +3 -3
- package/dist/{stream-c7eda5bc.cjs.dev.js → stream-34d80d2c.cjs.dev.js} +31 -28
- package/dist/{stream-13637643.cjs.prod.js → stream-ea4f4d44.cjs.prod.js} +31 -28
- package/dist/{synchronizedRef-37e32854.cjs.dev.js → synchronizedRef-a12fd967.cjs.dev.js} +6 -6
- package/dist/{synchronizedRef-b4cde4de.cjs.prod.js → synchronizedRef-ed8aa6ac.cjs.prod.js} +6 -6
- package/dist/{tArray-df1bae1c.cjs.dev.js → tArray-17f078f2.cjs.dev.js} +3 -3
- package/dist/{tArray-d5476a2d.cjs.prod.js → tArray-d184e22f.cjs.prod.js} +3 -3
- package/dist/{tMap-a3e14c05.cjs.dev.js → tMap-1a5aa78b.cjs.dev.js} +4 -4
- package/dist/{tMap-20ef43ea.cjs.prod.js → tMap-e219f30e.cjs.prod.js} +4 -4
- package/dist/{tQueue-bd3cf539.cjs.dev.js → tQueue-0a4fc773.cjs.dev.js} +3 -3
- package/dist/{tQueue-c02c22bd.cjs.prod.js → tQueue-47129ad0.cjs.prod.js} +3 -3
- package/dist/{tRef-49e44dde.cjs.prod.js → tRef-ab4c5713.cjs.prod.js} +1 -1
- package/dist/{tRef-75dd04b3.cjs.dev.js → tRef-b860ef05.cjs.dev.js} +1 -1
- package/internal/Context.esm.js +4 -4
- package/internal/Data.esm.js +4 -1
- package/internal/Differ/ChunkPatch.esm.js +1 -1
- package/internal/Differ/ContextPatch.esm.js +1 -1
- package/internal/Differ/HashMapPatch.esm.js +1 -1
- package/internal/Differ/HashSetPatch.esm.js +1 -1
- package/internal/Differ/OrPatch.esm.js +1 -1
- package/internal/Effectable.esm.js +9 -9
- package/internal/Either.esm.js +3 -3
- package/internal/Option.esm.js +3 -3
- package/internal/cache.esm.js +1 -1
- package/internal/cause.esm.js +6 -21
- package/internal/channel.esm.js +5 -5
- package/internal/core-effect.esm.js +6 -4
- package/internal/fiberRuntime.esm.js +3 -3
- package/internal/layer.esm.js +1 -1
- package/internal/metric/hook.esm.js +7 -3
- package/internal/metric/key.esm.js +2 -2
- package/internal/metric/keyType.esm.js +9 -2
- package/internal/metric/registry.esm.js +2 -2
- package/internal/metric/state.esm.js +2 -6
- package/internal/metric.esm.js +3 -3
- package/internal/{hub.esm.js → pubsub.esm.js} +108 -108
- package/internal/request.esm.js +1 -1
- package/internal/sink.esm.js +8 -8
- package/internal/stm/{tHub.esm.js → tPubSub.esm.js} +30 -30
- package/internal/stream.esm.js +23 -20
- package/internal/subscriptionRef.esm.js +8 -8
- package/package.json +66 -211
- package/src/.index.ts +30 -0
- package/src/Bigint.ts +497 -0
- package/src/Boolean.ts +261 -0
- package/src/Brand.ts +336 -0
- package/src/Cache.ts +250 -0
- package/src/Cause.ts +813 -0
- package/src/Channel.ts +2244 -0
- package/src/ChannelChildExecutorDecision.ts +138 -0
- package/src/ChannelMergeDecision.ts +94 -0
- package/src/ChannelMergeState.ts +166 -0
- package/src/ChannelMergeStrategy.ts +107 -0
- package/src/ChannelSingleProducerAsyncInput.ts +68 -0
- package/src/ChannelUpstreamPullRequest.ts +110 -0
- package/src/ChannelUpstreamPullStrategy.ts +120 -0
- package/src/Chunk.ts +1314 -0
- package/src/Clock.ts +111 -0
- package/src/Config.ts +447 -0
- package/src/ConfigError.ts +267 -0
- package/src/ConfigProvider.ts +296 -0
- package/src/ConfigProviderPathPatch.ts +100 -0
- package/src/ConfigSecret.ts +76 -0
- package/src/Console.ts +222 -0
- package/src/Context.ts +365 -0
- package/src/Data.ts +367 -0
- package/src/DefaultServices.ts +34 -0
- package/src/Deferred.ts +283 -0
- package/src/Differ.ts +406 -0
- package/src/Duration.ts +558 -0
- package/src/Effect.ts +5177 -0
- package/src/Effectable.ts +107 -0
- package/src/Either.ts +593 -0
- package/src/Encoding.ts +130 -0
- package/src/Equal.ts +64 -0
- package/src/Equivalence.ts +235 -0
- package/src/ExecutionStrategy.ts +111 -0
- package/src/Exit.ts +464 -0
- package/src/Fiber.ts +650 -0
- package/src/FiberId.ts +187 -0
- package/src/FiberRef.ts +399 -0
- package/src/FiberRefs.ts +160 -0
- package/src/FiberRefsPatch.ts +105 -0
- package/src/FiberStatus.ts +108 -0
- package/src/Function.ts +834 -0
- package/src/GlobalValue.ts +20 -0
- package/src/GroupBy.ts +102 -0
- package/src/HKT.ts +44 -0
- package/src/Hash.ts +162 -0
- package/src/HashMap.ts +373 -0
- package/src/HashSet.ts +300 -0
- package/src/Inspectable.ts +45 -0
- package/src/KeyedPool.ts +160 -0
- package/src/Layer.ts +866 -0
- package/src/List.ts +942 -0
- package/src/LogLevel.ts +266 -0
- package/src/LogSpan.ts +25 -0
- package/src/Logger.ts +321 -0
- package/src/Metric.ts +657 -0
- package/src/MetricBoundaries.ts +70 -0
- package/src/MetricHook.ts +139 -0
- package/src/MetricKey.ts +227 -0
- package/src/MetricKeyType.ts +257 -0
- package/src/MetricLabel.ts +47 -0
- package/src/MetricPair.ts +70 -0
- package/src/MetricPolling.ts +136 -0
- package/src/MetricRegistry.ts +47 -0
- package/src/MetricState.ts +256 -0
- package/src/MutableHashMap.ts +187 -0
- package/src/MutableHashSet.ts +118 -0
- package/src/MutableList.ts +289 -0
- package/src/MutableQueue.ts +227 -0
- package/src/MutableRef.ts +204 -0
- package/src/NonEmptyIterable.ts +30 -0
- package/src/Number.ts +406 -0
- package/src/Option.ts +1307 -0
- package/src/Order.ts +328 -0
- package/src/Ordering.ts +112 -0
- package/src/Pipeable.ts +318 -0
- package/src/Pool.ts +148 -0
- package/src/Predicate.ts +704 -0
- package/src/PubSub.ts +175 -0
- package/src/Queue.ts +575 -0
- package/src/Random.ts +115 -0
- package/src/ReadonlyArray.ts +2017 -0
- package/src/ReadonlyRecord.ts +641 -0
- package/src/RedBlackTree.ts +415 -0
- package/src/Ref.ts +159 -0
- package/src/Reloadable.ts +136 -0
- package/src/Request.ts +285 -0
- package/src/RequestBlock.ts +157 -0
- package/src/RequestResolver.ts +305 -0
- package/src/Resource.ts +97 -0
- package/src/Runtime.ts +216 -0
- package/src/RuntimeFlags.ts +336 -0
- package/src/RuntimeFlagsPatch.ts +183 -0
- package/src/STM.ts +2076 -0
- package/src/Schedule.ts +1396 -0
- package/src/ScheduleDecision.ts +62 -0
- package/src/ScheduleInterval.ts +151 -0
- package/src/ScheduleIntervals.ts +122 -0
- package/src/Scheduler.ts +359 -0
- package/src/Scope.ts +171 -0
- package/src/ScopedCache.ts +148 -0
- package/src/ScopedRef.ts +95 -0
- package/src/Sink.ts +1431 -0
- package/src/SortedMap.ts +229 -0
- package/src/SortedSet.ts +385 -0
- package/src/Stream.ts +4540 -0
- package/src/StreamEmit.ts +83 -0
- package/src/StreamHaltStrategy.ts +111 -0
- package/src/Streamable.ts +42 -0
- package/src/String.ts +682 -0
- package/src/Struct.ts +151 -0
- package/src/SubscriptionRef.ts +273 -0
- package/src/Supervisor.ts +239 -0
- package/src/Symbol.ts +28 -0
- package/src/SynchronizedRef.ts +249 -0
- package/src/TArray.ts +494 -0
- package/src/TDeferred.ts +99 -0
- package/src/TMap.ts +510 -0
- package/src/TPriorityQueue.ts +223 -0
- package/src/TPubSub.ts +187 -0
- package/src/TQueue.ts +431 -0
- package/src/TRandom.ts +129 -0
- package/src/TReentrantLock.ts +224 -0
- package/src/TRef.ts +176 -0
- package/src/TSemaphore.ts +129 -0
- package/src/TSet.ts +349 -0
- package/src/Take.ts +257 -0
- package/src/TestAnnotation.ts +166 -0
- package/src/TestAnnotationMap.ts +124 -0
- package/src/TestAnnotations.ts +113 -0
- package/src/TestClock.ts +552 -0
- package/src/TestConfig.ts +49 -0
- package/src/TestContext.ts +35 -0
- package/src/TestLive.ts +55 -0
- package/src/TestServices.ts +392 -0
- package/src/TestSized.ts +55 -0
- package/src/Tracer.ts +119 -0
- package/src/Tuple.ts +204 -0
- package/src/Types.ts +123 -0
- package/src/Unify.ts +118 -0
- package/src/Utils.ts +699 -0
- package/src/index.ts +840 -0
- package/src/internal/Common.ts +56 -0
- package/src/internal/Context.ts +252 -0
- package/src/internal/Data.ts +55 -0
- package/src/internal/Differ/ChunkPatch.ts +209 -0
- package/src/internal/Differ/ContextPatch.ts +229 -0
- package/src/internal/Differ/HashMapPatch.ts +217 -0
- package/src/internal/Differ/HashSetPatch.ts +174 -0
- package/src/internal/Differ/OrPatch.ts +296 -0
- package/src/internal/Differ.ts +184 -0
- package/src/internal/Effectable.ts +92 -0
- package/src/internal/Either.ts +107 -0
- package/src/internal/Encoding/Base64.ts +282 -0
- package/src/internal/Encoding/Base64Url.ts +28 -0
- package/src/internal/Encoding/Common.ts +24 -0
- package/src/internal/Encoding/Hex.ts +315 -0
- package/src/internal/HashMap/array.ts +49 -0
- package/src/internal/HashMap/bitwise.ts +32 -0
- package/src/internal/HashMap/config.ts +14 -0
- package/src/internal/HashMap/keySet.ts +8 -0
- package/src/internal/HashMap/node.ts +390 -0
- package/src/internal/HashMap.ts +533 -0
- package/src/internal/HashSet.ts +319 -0
- package/src/internal/Iterable.ts +54 -0
- package/src/internal/Option.ts +79 -0
- package/src/internal/ReadonlyArray.ts +8 -0
- package/src/internal/RedBlackTree/iterator.ts +207 -0
- package/src/internal/RedBlackTree/node.ts +48 -0
- package/src/internal/RedBlackTree.ts +1195 -0
- package/src/internal/Stack.ts +4 -0
- package/src/internal/blockedRequests.ts +512 -0
- package/src/internal/cache.ts +714 -0
- package/src/internal/cause.ts +1205 -0
- package/src/internal/channel/channelExecutor.ts +1193 -0
- package/src/internal/channel/channelState.ts +132 -0
- package/src/internal/channel/childExecutorDecision.ts +95 -0
- package/src/internal/channel/continuation.ts +171 -0
- package/src/internal/channel/mergeDecision.ts +115 -0
- package/src/internal/channel/mergeState.ts +120 -0
- package/src/internal/channel/mergeStrategy.ts +72 -0
- package/src/internal/channel/singleProducerAsyncInput.ts +261 -0
- package/src/internal/channel/subexecutor.ts +229 -0
- package/src/internal/channel/upstreamPullRequest.ts +83 -0
- package/src/internal/channel/upstreamPullStrategy.ts +86 -0
- package/src/internal/channel.ts +2516 -0
- package/src/internal/clock.ts +97 -0
- package/src/internal/completedRequestMap.ts +9 -0
- package/src/internal/concurrency.ts +83 -0
- package/src/internal/config.ts +598 -0
- package/src/internal/configError.ts +291 -0
- package/src/internal/configProvider/pathPatch.ts +97 -0
- package/src/internal/configProvider.ts +692 -0
- package/src/internal/configSecret.ts +71 -0
- package/src/internal/console.ts +136 -0
- package/src/internal/core-effect.ts +2146 -0
- package/src/internal/core-stream.ts +999 -0
- package/src/internal/core.ts +2765 -0
- package/src/internal/dataSource.ts +258 -0
- package/src/internal/defaultServices/console.ts +97 -0
- package/src/internal/defaultServices.ts +140 -0
- package/src/internal/deferred.ts +44 -0
- package/src/internal/effect/circular.ts +664 -0
- package/src/internal/executionStrategy.ts +72 -0
- package/src/internal/fiber.ts +350 -0
- package/src/internal/fiberId.ts +270 -0
- package/src/internal/fiberMessage.ts +85 -0
- package/src/internal/fiberRefs/patch.ts +144 -0
- package/src/internal/fiberRefs.ts +239 -0
- package/src/internal/fiberRuntime.ts +3477 -0
- package/src/internal/fiberScope.ts +72 -0
- package/src/internal/fiberStatus.ts +118 -0
- package/src/internal/groupBy.ts +516 -0
- package/src/internal/keyedPool.ts +240 -0
- package/src/internal/layer/circular.ts +203 -0
- package/src/internal/layer.ts +1230 -0
- package/src/internal/logSpan.ts +15 -0
- package/src/internal/logger-circular.ts +24 -0
- package/src/internal/logger.ts +307 -0
- package/src/internal/metric/boundaries.ts +72 -0
- package/src/internal/metric/hook.ts +459 -0
- package/src/internal/metric/key.ts +173 -0
- package/src/internal/metric/keyType.ts +263 -0
- package/src/internal/metric/label.ts +44 -0
- package/src/internal/metric/pair.ts +48 -0
- package/src/internal/metric/polling.ts +143 -0
- package/src/internal/metric/registry.ts +188 -0
- package/src/internal/metric/state.ts +286 -0
- package/src/internal/metric.ts +522 -0
- package/src/internal/opCodes/cause.ts +35 -0
- package/src/internal/opCodes/channel.ts +83 -0
- package/src/internal/opCodes/channelChildExecutorDecision.ts +17 -0
- package/src/internal/opCodes/channelMergeDecision.ts +11 -0
- package/src/internal/opCodes/channelMergeState.ts +17 -0
- package/src/internal/opCodes/channelMergeStrategy.ts +11 -0
- package/src/internal/opCodes/channelState.ts +23 -0
- package/src/internal/opCodes/channelUpstreamPullRequest.ts +11 -0
- package/src/internal/opCodes/channelUpstreamPullStrategy.ts +11 -0
- package/src/internal/opCodes/config.ts +65 -0
- package/src/internal/opCodes/configError.ts +35 -0
- package/src/internal/opCodes/continuation.ts +11 -0
- package/src/internal/opCodes/deferred.ts +11 -0
- package/src/internal/opCodes/effect.ts +83 -0
- package/src/internal/opCodes/layer.ts +53 -0
- package/src/internal/opCodes/streamHaltStrategy.ts +23 -0
- package/src/internal/pool.ts +499 -0
- package/src/internal/pubsub.ts +1557 -0
- package/src/internal/query.ts +199 -0
- package/src/internal/queue.ts +729 -0
- package/src/internal/random.ts +88 -0
- package/src/internal/ref.ts +164 -0
- package/src/internal/reloadable.ts +164 -0
- package/src/internal/request.ts +137 -0
- package/src/internal/resource.ts +64 -0
- package/src/internal/ringBuffer.ts +68 -0
- package/src/internal/runtime.ts +348 -0
- package/src/internal/runtimeFlags.ts +176 -0
- package/src/internal/runtimeFlagsPatch.ts +103 -0
- package/src/internal/schedule/decision.ts +47 -0
- package/src/internal/schedule/interval.ts +101 -0
- package/src/internal/schedule/intervals.ts +179 -0
- package/src/internal/schedule.ts +2096 -0
- package/src/internal/scopedCache.ts +634 -0
- package/src/internal/scopedRef.ts +133 -0
- package/src/internal/singleShotGen.ts +35 -0
- package/src/internal/sink.ts +2118 -0
- package/src/internal/stm/core.ts +804 -0
- package/src/internal/stm/opCodes/stm.ts +71 -0
- package/src/internal/stm/opCodes/stmState.ts +17 -0
- package/src/internal/stm/opCodes/strategy.ts +17 -0
- package/src/internal/stm/opCodes/tExit.ts +29 -0
- package/src/internal/stm/opCodes/tryCommit.ts +11 -0
- package/src/internal/stm/stm/entry.ts +59 -0
- package/src/internal/stm/stm/journal.ts +123 -0
- package/src/internal/stm/stm/opCodes/stm.ts +71 -0
- package/src/internal/stm/stm/opCodes/stmState.ts +17 -0
- package/src/internal/stm/stm/opCodes/strategy.ts +17 -0
- package/src/internal/stm/stm/opCodes/tExit.ts +29 -0
- package/src/internal/stm/stm/opCodes/tryCommit.ts +11 -0
- package/src/internal/stm/stm/stmState.ts +130 -0
- package/src/internal/stm/stm/tExit.ts +180 -0
- package/src/internal/stm/stm/tryCommit.ts +34 -0
- package/src/internal/stm/stm/txnId.ts +14 -0
- package/src/internal/stm/stm/versioned.ts +4 -0
- package/src/internal/stm/stm.ts +1491 -0
- package/src/internal/stm/tArray.ts +550 -0
- package/src/internal/stm/tDeferred.ts +79 -0
- package/src/internal/stm/tMap.ts +824 -0
- package/src/internal/stm/tPriorityQueue.ts +259 -0
- package/src/internal/stm/tPubSub.ts +542 -0
- package/src/internal/stm/tQueue.ts +400 -0
- package/src/internal/stm/tRandom.ts +140 -0
- package/src/internal/stm/tReentrantLock.ts +352 -0
- package/src/internal/stm/tRef.ts +190 -0
- package/src/internal/stm/tSemaphore.ts +113 -0
- package/src/internal/stm/tSet.ts +237 -0
- package/src/internal/stream/debounceState.ts +57 -0
- package/src/internal/stream/emit.ts +46 -0
- package/src/internal/stream/haltStrategy.ts +85 -0
- package/src/internal/stream/handoff.ts +185 -0
- package/src/internal/stream/handoffSignal.ts +59 -0
- package/src/internal/stream/pull.ts +35 -0
- package/src/internal/stream/sinkEndReason.ts +30 -0
- package/src/internal/stream/zipAllState.ts +88 -0
- package/src/internal/stream/zipChunksState.ts +56 -0
- package/src/internal/stream.ts +8089 -0
- package/src/internal/string-utils.ts +107 -0
- package/src/internal/subscriptionRef.ts +133 -0
- package/src/internal/supervisor/patch.ts +190 -0
- package/src/internal/supervisor.ts +301 -0
- package/src/internal/synchronizedRef.ts +115 -0
- package/src/internal/take.ts +198 -0
- package/src/internal/testing/sleep.ts +27 -0
- package/src/internal/testing/suspendedWarningData.ts +85 -0
- package/src/internal/testing/warningData.ts +94 -0
- package/src/internal/timeout.ts +23 -0
- package/src/internal/tracer.ts +74 -0
- package/Error/dist/effect-Error.cjs.d.mts +0 -2
- package/Error/dist/effect-Error.cjs.d.mts.map +0 -1
- package/Error/dist/effect-Error.cjs.d.ts +0 -2
- package/Error/dist/effect-Error.cjs.d.ts.map +0 -1
- package/Error/dist/effect-Error.cjs.dev.js +0 -140
- package/Error/dist/effect-Error.cjs.js +0 -7
- package/Error/dist/effect-Error.cjs.mjs +0 -4
- package/Error/dist/effect-Error.cjs.prod.js +0 -140
- package/Error/dist/effect-Error.esm.js +0 -47
- package/Error/package.json +0 -4
- package/Hub/dist/effect-Hub.cjs.d.mts +0 -2
- package/Hub/dist/effect-Hub.cjs.d.mts.map +0 -1
- package/Hub/dist/effect-Hub.cjs.d.ts +0 -2
- package/Hub/dist/effect-Hub.cjs.d.ts.map +0 -1
- package/Hub/dist/effect-Hub.cjs.js +0 -7
- package/Hub/package.json +0 -4
- package/THub/dist/effect-THub.cjs.d.mts +0 -2
- package/THub/dist/effect-THub.cjs.d.mts.map +0 -1
- package/THub/dist/effect-THub.cjs.d.ts +0 -2
- package/THub/dist/effect-THub.cjs.d.ts.map +0 -1
- package/THub/dist/effect-THub.cjs.js +0 -7
- package/THub/dist/effect-THub.esm.js +0 -157
- package/THub/package.json +0 -4
- package/dist/declarations/src/Error.d.ts +0 -37
- package/dist/declarations/src/Error.d.ts.map +0 -1
- package/dist/declarations/src/Hub.d.ts.map +0 -1
- package/dist/declarations/src/THub.d.ts +0 -146
- package/dist/declarations/src/THub.d.ts.map +0 -1
- package/dist/scopedRef-1c2c9acf.cjs.prod.js +0 -55
- package/dist/scopedRef-ab4c58b0.cjs.dev.js +0 -55
- /package/dist/{FiberId-e594f6e8.cjs.prod.js → FiberId-1d7ac632.cjs.prod.js} +0 -0
- /package/dist/{FiberId-557db880.cjs.dev.js → FiberId-d88ddce6.cjs.dev.js} +0 -0
- /package/dist/{RuntimeFlagsPatch-ea268c50.cjs.dev.js → RuntimeFlagsPatch-69102b03.cjs.dev.js} +0 -0
- /package/dist/{RuntimeFlagsPatch-e2769b87.cjs.prod.js → RuntimeFlagsPatch-866fa259.cjs.prod.js} +0 -0
- /package/dist/{boundaries-20cfad9d.cjs.prod.js → boundaries-9af538e3.cjs.prod.js} +0 -0
- /package/dist/{boundaries-3810d885.cjs.dev.js → boundaries-f212e414.cjs.dev.js} +0 -0
- /package/dist/{configError-33e55472.cjs.prod.js → configError-b43723af.cjs.prod.js} +0 -0
- /package/dist/{configError-240e9b61.cjs.dev.js → configError-d5efe9c0.cjs.dev.js} +0 -0
- /package/dist/{configSecret-e34c1b14.cjs.dev.js → configSecret-3e8ae336.cjs.dev.js} +0 -0
- /package/dist/{configSecret-d1caca55.cjs.prod.js → configSecret-e2faa181.cjs.prod.js} +0 -0
- /package/dist/{take-2af6e92a.cjs.prod.js → take-85daaf79.cjs.prod.js} +0 -0
- /package/dist/{take-df9480a8.cjs.dev.js → take-f9ef9e2e.cjs.dev.js} +0 -0
|
@@ -0,0 +1,2017 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides utility functions for working with arrays in TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* @since 2.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Either } from "./Either"
|
|
8
|
+
import * as E from "./Either"
|
|
9
|
+
import * as Equal from "./Equal"
|
|
10
|
+
import * as Equivalence from "./Equivalence"
|
|
11
|
+
import { dual, identity } from "./Function"
|
|
12
|
+
import type { LazyArg } from "./Function"
|
|
13
|
+
import type { TypeLambda } from "./HKT"
|
|
14
|
+
import * as readonlyArray from "./internal/ReadonlyArray"
|
|
15
|
+
import type { Option } from "./Option"
|
|
16
|
+
import * as O from "./Option"
|
|
17
|
+
import * as Order from "./Order"
|
|
18
|
+
import type { Predicate, Refinement } from "./Predicate"
|
|
19
|
+
import * as RR from "./ReadonlyRecord"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @category type lambdas
|
|
23
|
+
* @since 2.0.0
|
|
24
|
+
*/
|
|
25
|
+
export interface ReadonlyArrayTypeLambda extends TypeLambda {
|
|
26
|
+
readonly type: ReadonlyArray<this["Target"]>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @category models
|
|
31
|
+
* @since 2.0.0
|
|
32
|
+
*/
|
|
33
|
+
export type NonEmptyReadonlyArray<A> = readonly [A, ...Array<A>]
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @category models
|
|
37
|
+
* @since 2.0.0
|
|
38
|
+
*/
|
|
39
|
+
export type NonEmptyArray<A> = [A, ...Array<A>]
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Builds a `NonEmptyArray` from an non-empty collection of elements.
|
|
43
|
+
*
|
|
44
|
+
* @category constructors
|
|
45
|
+
* @since 2.0.0
|
|
46
|
+
*/
|
|
47
|
+
export const make = <Elements extends NonEmptyArray<any>>(
|
|
48
|
+
...elements: Elements
|
|
49
|
+
): NonEmptyArray<Elements[number]> => elements
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Return a `NonEmptyArray` of length `n` with element `i` initialized with `f(i)`.
|
|
53
|
+
*
|
|
54
|
+
* **Note**. `n` is normalized to an integer >= 1.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* import { makeBy } from 'effect/ReadonlyArray'
|
|
58
|
+
*
|
|
59
|
+
* assert.deepStrictEqual(makeBy(5, n => n * 2), [0, 2, 4, 6, 8])
|
|
60
|
+
*
|
|
61
|
+
* @category constructors
|
|
62
|
+
* @since 2.0.0
|
|
63
|
+
*/
|
|
64
|
+
export const makeBy = <A>(n: number, f: (i: number) => A): NonEmptyArray<A> => {
|
|
65
|
+
const max = Math.max(1, Math.floor(n))
|
|
66
|
+
const out: NonEmptyArray<A> = [f(0)]
|
|
67
|
+
for (let i = 1; i < max; i++) {
|
|
68
|
+
out.push(f(i))
|
|
69
|
+
}
|
|
70
|
+
return out
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Return a `NonEmptyArray` containing a range of integers, including both endpoints.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* import { range } from 'effect/ReadonlyArray'
|
|
78
|
+
*
|
|
79
|
+
* assert.deepStrictEqual(range(1, 3), [1, 2, 3])
|
|
80
|
+
*
|
|
81
|
+
* @category constructors
|
|
82
|
+
* @since 2.0.0
|
|
83
|
+
*/
|
|
84
|
+
export const range = (start: number, end: number): NonEmptyArray<number> =>
|
|
85
|
+
start <= end ? makeBy(end - start + 1, (i) => start + i) : [start]
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Return a `NonEmptyArray` containing a value repeated the specified number of times.
|
|
89
|
+
*
|
|
90
|
+
* **Note**. `n` is normalized to an integer >= 1.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* import { replicate } from 'effect/ReadonlyArray'
|
|
94
|
+
*
|
|
95
|
+
* assert.deepStrictEqual(replicate("a", 3), ["a", "a", "a"])
|
|
96
|
+
*
|
|
97
|
+
* @category constructors
|
|
98
|
+
* @since 2.0.0
|
|
99
|
+
*/
|
|
100
|
+
export const replicate: {
|
|
101
|
+
(n: number): <A>(a: A) => NonEmptyArray<A>
|
|
102
|
+
<A>(a: A, n: number): NonEmptyArray<A>
|
|
103
|
+
} = dual(2, <A>(a: A, n: number): NonEmptyArray<A> => makeBy(n, () => a))
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @category conversions
|
|
107
|
+
* @since 2.0.0
|
|
108
|
+
*/
|
|
109
|
+
export const fromIterable = <A>(collection: Iterable<A>): Array<A> =>
|
|
110
|
+
Array.isArray(collection) ? collection : Array.from(collection)
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Takes a record and returns an array of tuples containing its keys and values.
|
|
114
|
+
*
|
|
115
|
+
* @param self - The record to transform.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* import { fromRecord } from "effect/ReadonlyArray"
|
|
119
|
+
*
|
|
120
|
+
* const x = { a: 1, b: 2, c: 3 }
|
|
121
|
+
* assert.deepStrictEqual(fromRecord(x), [["a", 1], ["b", 2], ["c", 3]])
|
|
122
|
+
*
|
|
123
|
+
* @category conversions
|
|
124
|
+
* @since 2.0.0
|
|
125
|
+
*/
|
|
126
|
+
export const fromRecord: <K extends string, A>(self: Readonly<Record<K, A>>) => Array<[K, A]> = RR.toEntries
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @category conversions
|
|
130
|
+
* @since 2.0.0
|
|
131
|
+
*/
|
|
132
|
+
export const fromOption: <A>(self: Option<A>) => Array<A> = O.toArray
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @category pattern matching
|
|
136
|
+
* @since 2.0.0
|
|
137
|
+
*/
|
|
138
|
+
export const match: {
|
|
139
|
+
<B, A, C = B>(
|
|
140
|
+
options: {
|
|
141
|
+
readonly onEmpty: LazyArg<B>
|
|
142
|
+
readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C
|
|
143
|
+
}
|
|
144
|
+
): (self: ReadonlyArray<A>) => B | C
|
|
145
|
+
<A, B, C = B>(
|
|
146
|
+
self: ReadonlyArray<A>,
|
|
147
|
+
options: {
|
|
148
|
+
readonly onEmpty: LazyArg<B>
|
|
149
|
+
readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C
|
|
150
|
+
}
|
|
151
|
+
): B | C
|
|
152
|
+
} = dual(2, <A, B, C = B>(
|
|
153
|
+
self: ReadonlyArray<A>,
|
|
154
|
+
{ onEmpty, onNonEmpty }: {
|
|
155
|
+
readonly onEmpty: LazyArg<B>
|
|
156
|
+
readonly onNonEmpty: (self: NonEmptyReadonlyArray<A>) => C
|
|
157
|
+
}
|
|
158
|
+
): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(self) : onEmpty())
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @category pattern matching
|
|
162
|
+
* @since 2.0.0
|
|
163
|
+
*/
|
|
164
|
+
export const matchLeft: {
|
|
165
|
+
<B, A, C = B>(
|
|
166
|
+
options: {
|
|
167
|
+
readonly onEmpty: LazyArg<B>
|
|
168
|
+
readonly onNonEmpty: (head: A, tail: Array<A>) => C
|
|
169
|
+
}
|
|
170
|
+
): (self: ReadonlyArray<A>) => B | C
|
|
171
|
+
<A, B, C = B>(
|
|
172
|
+
self: ReadonlyArray<A>,
|
|
173
|
+
options: {
|
|
174
|
+
readonly onEmpty: LazyArg<B>
|
|
175
|
+
readonly onNonEmpty: (head: A, tail: Array<A>) => C
|
|
176
|
+
}
|
|
177
|
+
): B | C
|
|
178
|
+
} = dual(2, <A, B, C = B>(
|
|
179
|
+
self: ReadonlyArray<A>,
|
|
180
|
+
{ onEmpty, onNonEmpty }: {
|
|
181
|
+
readonly onEmpty: LazyArg<B>
|
|
182
|
+
readonly onNonEmpty: (head: A, tail: Array<A>) => C
|
|
183
|
+
}
|
|
184
|
+
): B | C => isNonEmptyReadonlyArray(self) ? onNonEmpty(headNonEmpty(self), tailNonEmpty(self)) : onEmpty())
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @category pattern matching
|
|
188
|
+
* @since 2.0.0
|
|
189
|
+
*/
|
|
190
|
+
export const matchRight: {
|
|
191
|
+
<B, A, C = B>(
|
|
192
|
+
options: {
|
|
193
|
+
readonly onEmpty: LazyArg<B>
|
|
194
|
+
readonly onNonEmpty: (init: Array<A>, last: A) => C
|
|
195
|
+
}
|
|
196
|
+
): (self: ReadonlyArray<A>) => B | C
|
|
197
|
+
<A, B, C = B>(
|
|
198
|
+
self: ReadonlyArray<A>,
|
|
199
|
+
options: {
|
|
200
|
+
readonly onEmpty: LazyArg<B>
|
|
201
|
+
readonly onNonEmpty: (init: Array<A>, last: A) => C
|
|
202
|
+
}
|
|
203
|
+
): B | C
|
|
204
|
+
} = dual(2, <A, B, C = B>(
|
|
205
|
+
self: ReadonlyArray<A>,
|
|
206
|
+
{ onEmpty, onNonEmpty }: {
|
|
207
|
+
readonly onEmpty: LazyArg<B>
|
|
208
|
+
readonly onNonEmpty: (init: Array<A>, last: A) => C
|
|
209
|
+
}
|
|
210
|
+
): B | C =>
|
|
211
|
+
isNonEmptyReadonlyArray(self) ?
|
|
212
|
+
onNonEmpty(initNonEmpty(self), lastNonEmpty(self)) :
|
|
213
|
+
onEmpty())
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Prepend an element to the front of an `Iterable`, creating a new `NonEmptyArray`.
|
|
217
|
+
*
|
|
218
|
+
* @category concatenating
|
|
219
|
+
* @since 2.0.0
|
|
220
|
+
*/
|
|
221
|
+
export const prepend: {
|
|
222
|
+
<B>(head: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>
|
|
223
|
+
<A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B>
|
|
224
|
+
} = dual(2, <A, B>(self: Iterable<A>, head: B): NonEmptyArray<A | B> => [head, ...self])
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @category concatenating
|
|
228
|
+
* @since 2.0.0
|
|
229
|
+
*/
|
|
230
|
+
export const prependAll: {
|
|
231
|
+
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A | B>
|
|
232
|
+
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>
|
|
233
|
+
} = dual(
|
|
234
|
+
2,
|
|
235
|
+
<A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(that).concat(fromIterable(self))
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @category concatenating
|
|
240
|
+
* @since 2.0.0
|
|
241
|
+
*/
|
|
242
|
+
export const prependAllNonEmpty: {
|
|
243
|
+
<B>(that: NonEmptyReadonlyArray<B>): <A>(self: Iterable<A>) => NonEmptyArray<A | B>
|
|
244
|
+
<B>(that: Iterable<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
245
|
+
<A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>
|
|
246
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>
|
|
247
|
+
} = dual(
|
|
248
|
+
2,
|
|
249
|
+
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => prependAll(self, that)
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Append an element to the end of an `Iterable`, creating a new `NonEmptyArray`.
|
|
254
|
+
*
|
|
255
|
+
* @category concatenating
|
|
256
|
+
* @since 2.0.0
|
|
257
|
+
*/
|
|
258
|
+
export const append: {
|
|
259
|
+
<B>(last: B): <A>(self: Iterable<A>) => NonEmptyArray<A | B>
|
|
260
|
+
<A, B>(self: Iterable<A>, last: B): NonEmptyArray<A | B>
|
|
261
|
+
} = dual(2, <A, B>(self: Iterable<A>, last: B): Array<A | B> => [...self, last])
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @category concatenating
|
|
265
|
+
* @since 2.0.0
|
|
266
|
+
*/
|
|
267
|
+
export const appendAll: {
|
|
268
|
+
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A | B>
|
|
269
|
+
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>
|
|
270
|
+
} = dual(
|
|
271
|
+
2,
|
|
272
|
+
<A>(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).concat(fromIterable(that))
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @category concatenating
|
|
277
|
+
* @since 2.0.0
|
|
278
|
+
*/
|
|
279
|
+
export const appendAllNonEmpty: {
|
|
280
|
+
<B>(that: NonEmptyReadonlyArray<B>): <A>(self: Iterable<A>) => NonEmptyArray<A | B>
|
|
281
|
+
<B>(that: Iterable<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
282
|
+
<A, B>(self: Iterable<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<A | B>
|
|
283
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, that: Iterable<B>): NonEmptyArray<A | B>
|
|
284
|
+
} = dual(
|
|
285
|
+
2,
|
|
286
|
+
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B> => appendAll(self, that)
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Reduce an `Iterable` from the left, keeping all intermediate results instead of only the final result.
|
|
291
|
+
*
|
|
292
|
+
* @category folding
|
|
293
|
+
* @since 2.0.0
|
|
294
|
+
*/
|
|
295
|
+
export const scan: {
|
|
296
|
+
<B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>
|
|
297
|
+
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>
|
|
298
|
+
} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {
|
|
299
|
+
const out: NonEmptyArray<B> = [b]
|
|
300
|
+
let i = 0
|
|
301
|
+
for (const a of self) {
|
|
302
|
+
out[i + 1] = f(out[i], a)
|
|
303
|
+
i++
|
|
304
|
+
}
|
|
305
|
+
return out
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Reduce an `Iterable` from the right, keeping all intermediate results instead of only the final result.
|
|
310
|
+
*
|
|
311
|
+
* @category folding
|
|
312
|
+
* @since 2.0.0
|
|
313
|
+
*/
|
|
314
|
+
export const scanRight: {
|
|
315
|
+
<B, A>(b: B, f: (b: B, a: A) => B): (self: Iterable<A>) => NonEmptyArray<B>
|
|
316
|
+
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B>
|
|
317
|
+
} = dual(3, <A, B>(self: Iterable<A>, b: B, f: (b: B, a: A) => B): NonEmptyArray<B> => {
|
|
318
|
+
const input = fromIterable(self)
|
|
319
|
+
const out: NonEmptyArray<B> = new Array(input.length + 1) as any
|
|
320
|
+
out[input.length] = b
|
|
321
|
+
for (let i = input.length - 1; i >= 0; i--) {
|
|
322
|
+
out[i] = f(out[i + 1], input[i])
|
|
323
|
+
}
|
|
324
|
+
return out
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Determine if an `Array` is empty narrowing down the type to `[]`.
|
|
329
|
+
*
|
|
330
|
+
* @param self - The `Array` to check.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* import { isEmptyArray } from "effect/ReadonlyArray"
|
|
334
|
+
*
|
|
335
|
+
* assert.deepStrictEqual(isEmptyArray([]), true);
|
|
336
|
+
* assert.deepStrictEqual(isEmptyArray([1, 2, 3]), false);
|
|
337
|
+
*
|
|
338
|
+
* @category guards
|
|
339
|
+
* @since 2.0.0
|
|
340
|
+
*/
|
|
341
|
+
export const isEmptyArray = <A>(self: Array<A>): self is [] => self.length === 0
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Determine if a `ReadonlyArray` is empty narrowing down the type to `readonly []`.
|
|
345
|
+
*
|
|
346
|
+
* @param self - The `ReadonlyArray` to check.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* import { isEmptyReadonlyArray } from "effect/ReadonlyArray"
|
|
350
|
+
*
|
|
351
|
+
* assert.deepStrictEqual(isEmptyReadonlyArray([]), true);
|
|
352
|
+
* assert.deepStrictEqual(isEmptyReadonlyArray([1, 2, 3]), false);
|
|
353
|
+
*
|
|
354
|
+
* @category guards
|
|
355
|
+
* @since 2.0.0
|
|
356
|
+
*/
|
|
357
|
+
export const isEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is readonly [] = isEmptyArray as any
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Determine if an `Array` is non empty narrowing down the type to `NonEmptyArray`.
|
|
361
|
+
*
|
|
362
|
+
* An `Array` is considered to be a `NonEmptyArray` if it contains at least one element.
|
|
363
|
+
*
|
|
364
|
+
* @param self - The `Array` to check.
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* import { isNonEmptyArray } from "effect/ReadonlyArray"
|
|
368
|
+
*
|
|
369
|
+
* assert.deepStrictEqual(isNonEmptyArray([]), false);
|
|
370
|
+
* assert.deepStrictEqual(isNonEmptyArray([1, 2, 3]), true);
|
|
371
|
+
*
|
|
372
|
+
* @category guards
|
|
373
|
+
* @since 2.0.0
|
|
374
|
+
*/
|
|
375
|
+
export const isNonEmptyArray: <A>(self: Array<A>) => self is NonEmptyArray<A> = readonlyArray.isNonEmptyArray
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Determine if a `ReadonlyArray` is non empty narrowing down the type to `NonEmptyReadonlyArray`.
|
|
379
|
+
*
|
|
380
|
+
* A `ReadonlyArray` is considered to be a `NonEmptyReadonlyArray` if it contains at least one element.
|
|
381
|
+
*
|
|
382
|
+
* @param self - The `ReadonlyArray` to check.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* import { isNonEmptyReadonlyArray } from "effect/ReadonlyArray"
|
|
386
|
+
*
|
|
387
|
+
* assert.deepStrictEqual(isNonEmptyReadonlyArray([]), false);
|
|
388
|
+
* assert.deepStrictEqual(isNonEmptyReadonlyArray([1, 2, 3]), true);
|
|
389
|
+
*
|
|
390
|
+
* @category guards
|
|
391
|
+
* @since 2.0.0
|
|
392
|
+
*/
|
|
393
|
+
export const isNonEmptyReadonlyArray: <A>(self: ReadonlyArray<A>) => self is NonEmptyReadonlyArray<A> =
|
|
394
|
+
readonlyArray.isNonEmptyArray
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Return the number of elements in a `ReadonlyArray`.
|
|
398
|
+
*
|
|
399
|
+
* @category getters
|
|
400
|
+
* @since 2.0.0
|
|
401
|
+
*/
|
|
402
|
+
export const length = <A>(self: ReadonlyArray<A>): number => self.length
|
|
403
|
+
|
|
404
|
+
const isOutOfBound = <A>(i: number, as: ReadonlyArray<A>): boolean => i < 0 || i >= as.length
|
|
405
|
+
|
|
406
|
+
const clamp = <A>(i: number, as: ReadonlyArray<A>): number => Math.floor(Math.min(Math.max(0, i), as.length))
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* This function provides a safe way to read a value at a particular index from a `ReadonlyArray`.
|
|
410
|
+
*
|
|
411
|
+
* @category getters
|
|
412
|
+
* @since 2.0.0
|
|
413
|
+
*/
|
|
414
|
+
export const get: {
|
|
415
|
+
(index: number): <A>(self: ReadonlyArray<A>) => Option<A>
|
|
416
|
+
<A>(self: ReadonlyArray<A>, index: number): Option<A>
|
|
417
|
+
} = dual(2, <A>(self: ReadonlyArray<A>, index: number): Option<A> => {
|
|
418
|
+
const i = Math.floor(index)
|
|
419
|
+
return isOutOfBound(i, self) ? O.none() : O.some(self[i])
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Gets an element unsafely, will throw on out of bounds.
|
|
424
|
+
*
|
|
425
|
+
* @since 2.0.0
|
|
426
|
+
* @category unsafe
|
|
427
|
+
*/
|
|
428
|
+
export const unsafeGet: {
|
|
429
|
+
(index: number): <A>(self: ReadonlyArray<A>) => A
|
|
430
|
+
<A>(self: ReadonlyArray<A>, index: number): A
|
|
431
|
+
} = dual(2, <A>(self: ReadonlyArray<A>, index: number): A => {
|
|
432
|
+
const i = Math.floor(index)
|
|
433
|
+
if (isOutOfBound(i, self)) {
|
|
434
|
+
throw new Error(`Index ${i} out of bounds`)
|
|
435
|
+
}
|
|
436
|
+
return self[i]
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Return a tuple containing the first element, and a new `Array` of the remaining elements, if any.
|
|
441
|
+
*
|
|
442
|
+
* @category getters
|
|
443
|
+
* @since 2.0.0
|
|
444
|
+
*/
|
|
445
|
+
export const unprepend = <A>(
|
|
446
|
+
self: NonEmptyReadonlyArray<A>
|
|
447
|
+
): [A, Array<A>] => [headNonEmpty(self), tailNonEmpty(self)]
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Return a tuple containing a copy of the `NonEmptyReadonlyArray` without its last element, and that last element.
|
|
451
|
+
*
|
|
452
|
+
* @category getters
|
|
453
|
+
* @since 2.0.0
|
|
454
|
+
*/
|
|
455
|
+
export const unappend = <A>(
|
|
456
|
+
self: NonEmptyReadonlyArray<A>
|
|
457
|
+
): [Array<A>, A] => [initNonEmpty(self), lastNonEmpty(self)]
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Get the first element of a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.
|
|
461
|
+
*
|
|
462
|
+
* @category getters
|
|
463
|
+
* @since 2.0.0
|
|
464
|
+
*/
|
|
465
|
+
export const head: <A>(self: ReadonlyArray<A>) => Option<A> = get(0)
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* @category getters
|
|
469
|
+
* @since 2.0.0
|
|
470
|
+
*/
|
|
471
|
+
export const headNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => A = unsafeGet(0)
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Get the last element in a `ReadonlyArray`, or `None` if the `ReadonlyArray` is empty.
|
|
475
|
+
*
|
|
476
|
+
* @category getters
|
|
477
|
+
* @since 2.0.0
|
|
478
|
+
*/
|
|
479
|
+
export const last = <A>(self: ReadonlyArray<A>): Option<A> =>
|
|
480
|
+
isNonEmptyReadonlyArray(self) ? O.some(lastNonEmpty(self)) : O.none()
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* @category getters
|
|
484
|
+
* @since 2.0.0
|
|
485
|
+
*/
|
|
486
|
+
export const lastNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): A => self[self.length - 1]
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Get all but the first element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.
|
|
490
|
+
*
|
|
491
|
+
* @category getters
|
|
492
|
+
* @since 2.0.0
|
|
493
|
+
*/
|
|
494
|
+
export const tail = <A>(self: Iterable<A>): Option<Array<A>> => {
|
|
495
|
+
const input = fromIterable(self)
|
|
496
|
+
return isNonEmptyReadonlyArray(input) ? O.some(tailNonEmpty(input)) : O.none()
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* @category getters
|
|
501
|
+
* @since 2.0.0
|
|
502
|
+
*/
|
|
503
|
+
export const tailNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(1)
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Get all but the last element of an `Iterable`, creating a new `Array`, or `None` if the `Iterable` is empty.
|
|
507
|
+
*
|
|
508
|
+
* @category getters
|
|
509
|
+
* @since 2.0.0
|
|
510
|
+
*/
|
|
511
|
+
export const init = <A>(self: Iterable<A>): Option<Array<A>> => {
|
|
512
|
+
const input = fromIterable(self)
|
|
513
|
+
return isNonEmptyReadonlyArray(input) ? O.some(initNonEmpty(input)) : O.none()
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Get all but the last element of a non empty array, creating a new array.
|
|
518
|
+
*
|
|
519
|
+
* @category getters
|
|
520
|
+
* @since 2.0.0
|
|
521
|
+
*/
|
|
522
|
+
export const initNonEmpty = <A>(self: NonEmptyReadonlyArray<A>): Array<A> => self.slice(0, -1)
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Keep only a max number of elements from the start of an `Iterable`, creating a new `Array`.
|
|
526
|
+
*
|
|
527
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
528
|
+
*
|
|
529
|
+
* @category getters
|
|
530
|
+
* @since 2.0.0
|
|
531
|
+
*/
|
|
532
|
+
export const take: {
|
|
533
|
+
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
534
|
+
<A>(self: Iterable<A>, n: number): Array<A>
|
|
535
|
+
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
536
|
+
const input = fromIterable(self)
|
|
537
|
+
return input.slice(0, clamp(n, input))
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Keep only a max number of elements from the end of an `Iterable`, creating a new `Array`.
|
|
542
|
+
*
|
|
543
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
544
|
+
*
|
|
545
|
+
* @category getters
|
|
546
|
+
* @since 2.0.0
|
|
547
|
+
*/
|
|
548
|
+
export const takeRight: {
|
|
549
|
+
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
550
|
+
<A>(self: Iterable<A>, n: number): Array<A>
|
|
551
|
+
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
552
|
+
const input = fromIterable(self)
|
|
553
|
+
const i = clamp(n, input)
|
|
554
|
+
return i === 0 ? [] : input.slice(-i)
|
|
555
|
+
})
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Calculate the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
559
|
+
*
|
|
560
|
+
* @category getters
|
|
561
|
+
* @since 2.0.0
|
|
562
|
+
*/
|
|
563
|
+
export const takeWhile: {
|
|
564
|
+
<A, B extends A>(refinement: Refinement<A, B>): (self: Iterable<A>) => Array<B>
|
|
565
|
+
<A>(predicate: Predicate<A>): <B extends A>(self: Iterable<B>) => Array<B>
|
|
566
|
+
<A, B extends A>(self: Iterable<A>, refinement: Refinement<A, B>): Array<B>
|
|
567
|
+
<B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): Array<B>
|
|
568
|
+
} = dual(2, <B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): Array<B> => {
|
|
569
|
+
const out: Array<B> = []
|
|
570
|
+
for (const a of self) {
|
|
571
|
+
if (!predicate(a)) {
|
|
572
|
+
break
|
|
573
|
+
}
|
|
574
|
+
out.push(a)
|
|
575
|
+
}
|
|
576
|
+
return out
|
|
577
|
+
})
|
|
578
|
+
|
|
579
|
+
const spanIndex = <A>(self: Iterable<A>, predicate: Predicate<A>): number => {
|
|
580
|
+
let i = 0
|
|
581
|
+
for (const a of self) {
|
|
582
|
+
if (!predicate(a)) {
|
|
583
|
+
break
|
|
584
|
+
}
|
|
585
|
+
i++
|
|
586
|
+
}
|
|
587
|
+
return i
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Split an `Iterable` into two parts:
|
|
592
|
+
*
|
|
593
|
+
* 1. the longest initial subarray for which all elements satisfy the specified predicate
|
|
594
|
+
* 2. the remaining elements
|
|
595
|
+
*
|
|
596
|
+
* @category filtering
|
|
597
|
+
* @since 2.0.0
|
|
598
|
+
*/
|
|
599
|
+
export const span: {
|
|
600
|
+
<A, B extends A>(
|
|
601
|
+
refinement: Refinement<A, B>
|
|
602
|
+
): (self: Iterable<A>) => [init: Array<B>, rest: Array<A>]
|
|
603
|
+
<A>(predicate: Predicate<A>): <B extends A>(self: Iterable<B>) => [init: Array<B>, rest: Array<B>]
|
|
604
|
+
<A, B extends A>(
|
|
605
|
+
self: Iterable<A>,
|
|
606
|
+
refinement: Refinement<A, B>
|
|
607
|
+
): [init: Array<B>, rest: Array<A>]
|
|
608
|
+
<B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): [init: Array<B>, rest: Array<B>]
|
|
609
|
+
} = dual(
|
|
610
|
+
2,
|
|
611
|
+
<B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): [init: Array<B>, rest: Array<B>] =>
|
|
612
|
+
splitAt(self, spanIndex(self, predicate))
|
|
613
|
+
)
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Drop a max number of elements from the start of an `Iterable`, creating a new `Array`.
|
|
617
|
+
*
|
|
618
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
619
|
+
*
|
|
620
|
+
* @category getters
|
|
621
|
+
* @since 2.0.0
|
|
622
|
+
*/
|
|
623
|
+
export const drop: {
|
|
624
|
+
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
625
|
+
<A>(self: Iterable<A>, n: number): Array<A>
|
|
626
|
+
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
627
|
+
const input = fromIterable(self)
|
|
628
|
+
return input.slice(clamp(n, input), input.length)
|
|
629
|
+
})
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Drop a max number of elements from the end of an `Iterable`, creating a new `Array`.
|
|
633
|
+
*
|
|
634
|
+
* **Note**. `n` is normalized to a non negative integer.
|
|
635
|
+
*
|
|
636
|
+
* @category getters
|
|
637
|
+
* @since 2.0.0
|
|
638
|
+
*/
|
|
639
|
+
export const dropRight: {
|
|
640
|
+
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
641
|
+
<A>(self: Iterable<A>, n: number): Array<A>
|
|
642
|
+
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
643
|
+
const input = fromIterable(self)
|
|
644
|
+
return input.slice(0, input.length - clamp(n, input))
|
|
645
|
+
})
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Remove the longest initial subarray for which all element satisfy the specified predicate, creating a new `Array`.
|
|
649
|
+
*
|
|
650
|
+
* @category getters
|
|
651
|
+
* @since 2.0.0
|
|
652
|
+
*/
|
|
653
|
+
export const dropWhile: {
|
|
654
|
+
<A, B extends A>(refinement: Refinement<A, B>): (self: Iterable<A>) => Array<B>
|
|
655
|
+
<A>(predicate: Predicate<A>): <B extends A>(self: Iterable<B>) => Array<B>
|
|
656
|
+
<A, B extends A>(self: Iterable<A>, refinement: Refinement<A, B>): Array<B>
|
|
657
|
+
<B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): Array<B>
|
|
658
|
+
} = dual(
|
|
659
|
+
2,
|
|
660
|
+
<B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): Array<B> =>
|
|
661
|
+
fromIterable(self).slice(spanIndex(self, predicate))
|
|
662
|
+
)
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Return the first index for which a predicate holds.
|
|
666
|
+
*
|
|
667
|
+
* @category elements
|
|
668
|
+
* @since 2.0.0
|
|
669
|
+
*/
|
|
670
|
+
export const findFirstIndex: {
|
|
671
|
+
<A>(predicate: Predicate<A>): (self: Iterable<A>) => Option<number>
|
|
672
|
+
<A>(self: Iterable<A>, predicate: Predicate<A>): Option<number>
|
|
673
|
+
} = dual(2, <A>(self: Iterable<A>, predicate: Predicate<A>): Option<number> => {
|
|
674
|
+
let i = 0
|
|
675
|
+
for (const a of self) {
|
|
676
|
+
if (predicate(a)) {
|
|
677
|
+
return O.some(i)
|
|
678
|
+
}
|
|
679
|
+
i++
|
|
680
|
+
}
|
|
681
|
+
return O.none()
|
|
682
|
+
})
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Return the last index for which a predicate holds.
|
|
686
|
+
*
|
|
687
|
+
* @category elements
|
|
688
|
+
* @since 2.0.0
|
|
689
|
+
*/
|
|
690
|
+
export const findLastIndex: {
|
|
691
|
+
<A>(predicate: Predicate<A>): (self: Iterable<A>) => Option<number>
|
|
692
|
+
<A>(self: Iterable<A>, predicate: Predicate<A>): Option<number>
|
|
693
|
+
} = dual(2, <A>(self: Iterable<A>, predicate: Predicate<A>): Option<number> => {
|
|
694
|
+
const input = fromIterable(self)
|
|
695
|
+
for (let i = input.length - 1; i >= 0; i--) {
|
|
696
|
+
if (predicate(input[i])) {
|
|
697
|
+
return O.some(i)
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return O.none()
|
|
701
|
+
})
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Returns the first element that satisfies the specified
|
|
705
|
+
* predicate, or `None` if no such element exists.
|
|
706
|
+
*
|
|
707
|
+
* @category elements
|
|
708
|
+
* @since 2.0.0
|
|
709
|
+
*/
|
|
710
|
+
export const findFirst: {
|
|
711
|
+
<A, B extends A>(refinement: Refinement<A, B>): (self: Iterable<A>) => Option<B>
|
|
712
|
+
<A>(predicate: Predicate<A>): <B extends A>(self: Iterable<B>) => Option<B>
|
|
713
|
+
<A, B extends A>(self: Iterable<A>, refinement: Refinement<A, B>): Option<B>
|
|
714
|
+
<B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): Option<B>
|
|
715
|
+
} = dual(2, <B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): Option<B> => {
|
|
716
|
+
const input = fromIterable(self)
|
|
717
|
+
for (let i = 0; i < input.length; i++) {
|
|
718
|
+
if (predicate(input[i])) {
|
|
719
|
+
return O.some(input[i])
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return O.none()
|
|
723
|
+
})
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Find the last element for which a predicate holds.
|
|
727
|
+
*
|
|
728
|
+
* @category elements
|
|
729
|
+
* @since 2.0.0
|
|
730
|
+
*/
|
|
731
|
+
export const findLast: {
|
|
732
|
+
<A, B extends A>(refinement: Refinement<A, B>): (self: Iterable<A>) => Option<B>
|
|
733
|
+
<A>(predicate: Predicate<A>): <B extends A>(self: Iterable<B>) => Option<B>
|
|
734
|
+
<A, B extends A>(self: Iterable<A>, refinement: Refinement<A, B>): Option<B>
|
|
735
|
+
<B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): Option<B>
|
|
736
|
+
} = dual(2, <B extends A, A>(self: Iterable<B>, predicate: Predicate<A>): Option<B> => {
|
|
737
|
+
const input = fromIterable(self)
|
|
738
|
+
for (let i = input.length - 1; i >= 0; i--) {
|
|
739
|
+
if (predicate(input[i])) {
|
|
740
|
+
return O.some(input[i])
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return O.none()
|
|
744
|
+
})
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Insert an element at the specified index, creating a new `NonEmptyArray`,
|
|
748
|
+
* or return `None` if the index is out of bounds.
|
|
749
|
+
*
|
|
750
|
+
* @since 2.0.0
|
|
751
|
+
*/
|
|
752
|
+
export const insertAt: {
|
|
753
|
+
<B>(i: number, b: B): <A>(self: Iterable<A>) => Option<NonEmptyArray<A | B>>
|
|
754
|
+
<A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>>
|
|
755
|
+
} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Option<NonEmptyArray<A | B>> => {
|
|
756
|
+
const out: Array<A | B> = Array.from(self)
|
|
757
|
+
// v--- `= self.length` is ok, it means inserting in last position
|
|
758
|
+
if (i < 0 || i > out.length) {
|
|
759
|
+
return O.none()
|
|
760
|
+
}
|
|
761
|
+
out.splice(i, 0, b)
|
|
762
|
+
return O.some(out) as any
|
|
763
|
+
})
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Change the element at the specified index, creating a new `Array`,
|
|
767
|
+
* or return a copy of the input if the index is out of bounds.
|
|
768
|
+
*
|
|
769
|
+
* @since 2.0.0
|
|
770
|
+
*/
|
|
771
|
+
export const replace: {
|
|
772
|
+
<B>(i: number, b: B): <A>(self: Iterable<A>) => Array<A | B>
|
|
773
|
+
<A, B>(self: Iterable<A>, i: number, b: B): Array<A | B>
|
|
774
|
+
} = dual(3, <A, B>(self: Iterable<A>, i: number, b: B): Array<A | B> => modify(self, i, () => b))
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* @since 2.0.0
|
|
778
|
+
*/
|
|
779
|
+
export const replaceOption: {
|
|
780
|
+
<B>(i: number, b: B): <A>(self: Iterable<A>) => Option<Array<A | B>>
|
|
781
|
+
<A, B>(self: Iterable<A>, i: number, b: B): Option<Array<A | B>>
|
|
782
|
+
} = dual(
|
|
783
|
+
3,
|
|
784
|
+
<A, B>(self: Iterable<A>, i: number, b: B): Option<Array<A | B>> => modifyOption(self, i, () => b)
|
|
785
|
+
)
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
789
|
+
* or return a copy of the input if the index is out of bounds.
|
|
790
|
+
*
|
|
791
|
+
* @since 2.0.0
|
|
792
|
+
*/
|
|
793
|
+
export const modify: {
|
|
794
|
+
<A, B>(i: number, f: (a: A) => B): (self: Iterable<A>) => Array<A | B>
|
|
795
|
+
<A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Array<A | B>
|
|
796
|
+
} = dual(
|
|
797
|
+
3,
|
|
798
|
+
<A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Array<A | B> =>
|
|
799
|
+
O.getOrElse(modifyOption(self, i, f), () => Array.from(self))
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Apply a function to the element at the specified index, creating a new `Array`,
|
|
804
|
+
* or return `None` if the index is out of bounds.
|
|
805
|
+
*
|
|
806
|
+
* @since 2.0.0
|
|
807
|
+
*/
|
|
808
|
+
export const modifyOption: {
|
|
809
|
+
<A, B>(i: number, f: (a: A) => B): (self: Iterable<A>) => Option<Array<A | B>>
|
|
810
|
+
<A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option<Array<A | B>>
|
|
811
|
+
} = dual(3, <A, B>(self: Iterable<A>, i: number, f: (a: A) => B): Option<Array<A | B>> => {
|
|
812
|
+
const out = Array.from(self)
|
|
813
|
+
if (isOutOfBound(i, out)) {
|
|
814
|
+
return O.none()
|
|
815
|
+
}
|
|
816
|
+
const next = f(out[i])
|
|
817
|
+
// @ts-expect-error
|
|
818
|
+
out[i] = next
|
|
819
|
+
return O.some(out)
|
|
820
|
+
})
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Delete the element at the specified index, creating a new `Array`,
|
|
824
|
+
* or return a copy of the input if the index is out of bounds.
|
|
825
|
+
*
|
|
826
|
+
* @since 2.0.0
|
|
827
|
+
*/
|
|
828
|
+
export const remove: {
|
|
829
|
+
(i: number): <A>(self: Iterable<A>) => Array<A>
|
|
830
|
+
<A>(self: Iterable<A>, i: number): Array<A>
|
|
831
|
+
} = dual(2, <A>(self: Iterable<A>, i: number): Array<A> => {
|
|
832
|
+
const out = Array.from(self)
|
|
833
|
+
if (isOutOfBound(i, out)) {
|
|
834
|
+
return out
|
|
835
|
+
}
|
|
836
|
+
out.splice(i, 1)
|
|
837
|
+
return out
|
|
838
|
+
})
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Reverse an `Iterable`, creating a new `Array`.
|
|
842
|
+
*
|
|
843
|
+
* @category elements
|
|
844
|
+
* @since 2.0.0
|
|
845
|
+
*/
|
|
846
|
+
export const reverse = <A>(self: Iterable<A>): Array<A> => Array.from(self).reverse()
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* @category elements
|
|
850
|
+
* @since 2.0.0
|
|
851
|
+
*/
|
|
852
|
+
export const reverseNonEmpty = <A>(
|
|
853
|
+
self: NonEmptyReadonlyArray<A>
|
|
854
|
+
): NonEmptyArray<A> => [lastNonEmpty(self), ...self.slice(0, -1).reverse()]
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Sort the elements of an `Iterable` in increasing order, creating a new `Array`.
|
|
858
|
+
*
|
|
859
|
+
* @category sorting
|
|
860
|
+
* @since 2.0.0
|
|
861
|
+
*/
|
|
862
|
+
export const sort: {
|
|
863
|
+
<B>(O: Order.Order<B>): <A extends B>(self: Iterable<A>) => Array<A>
|
|
864
|
+
<A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A>
|
|
865
|
+
} = dual(2, <A extends B, B>(self: Iterable<A>, O: Order.Order<B>): Array<A> => {
|
|
866
|
+
const out = Array.from(self)
|
|
867
|
+
out.sort(O)
|
|
868
|
+
return out
|
|
869
|
+
})
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* @since 2.0.0
|
|
873
|
+
* @category elements
|
|
874
|
+
*/
|
|
875
|
+
export const sortWith: {
|
|
876
|
+
<A, B>(f: (a: A) => B, order: Order.Order<B>): (self: ReadonlyArray<A>) => Array<A>
|
|
877
|
+
<A, B>(self: ReadonlyArray<A>, f: (a: A) => B, order: Order.Order<B>): Array<A>
|
|
878
|
+
} = dual(
|
|
879
|
+
3,
|
|
880
|
+
<A, B>(self: ReadonlyArray<A>, f: (a: A) => B, order: Order.Order<B>): Array<A> =>
|
|
881
|
+
sort(self, Order.mapInput(order, f))
|
|
882
|
+
)
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Sort the elements of a `NonEmptyReadonlyArray` in increasing order, creating a new `NonEmptyArray`.
|
|
886
|
+
*
|
|
887
|
+
* @category sorting
|
|
888
|
+
* @since 2.0.0
|
|
889
|
+
*/
|
|
890
|
+
export const sortNonEmpty: {
|
|
891
|
+
<B>(O: Order.Order<B>): <A extends B>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A>
|
|
892
|
+
<A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A>
|
|
893
|
+
} = dual(
|
|
894
|
+
2,
|
|
895
|
+
<A extends B, B>(self: NonEmptyReadonlyArray<A>, O: Order.Order<B>): NonEmptyArray<A> => sort(O)(self) as any
|
|
896
|
+
)
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Sort the elements of an `Iterable` in increasing order, where elements are compared
|
|
900
|
+
* using first `orders[0]`, then `orders[1]`, etc...
|
|
901
|
+
*
|
|
902
|
+
* @category sorting
|
|
903
|
+
* @since 2.0.0
|
|
904
|
+
*/
|
|
905
|
+
export const sortBy = <B>(...orders: ReadonlyArray<Order.Order<B>>) => <A extends B>(self: Iterable<A>): Array<A> => {
|
|
906
|
+
const input = fromIterable(self)
|
|
907
|
+
return (isNonEmptyReadonlyArray(input) ? sortByNonEmpty(...orders)(input) : [])
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* @category sorting
|
|
912
|
+
* @since 2.0.0
|
|
913
|
+
*/
|
|
914
|
+
export const sortByNonEmpty = <B>(
|
|
915
|
+
...orders: ReadonlyArray<Order.Order<B>>
|
|
916
|
+
): <A extends B>(as: NonEmptyReadonlyArray<A>) => NonEmptyArray<A> => sortNonEmpty(Order.combineAll(orders))
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* Takes two `Iterable`s and returns an `Array` of corresponding pairs.
|
|
920
|
+
* If one input `Iterable` is short, excess elements of the
|
|
921
|
+
* longer `Iterable` are discarded.
|
|
922
|
+
*
|
|
923
|
+
* @since 2.0.0
|
|
924
|
+
*/
|
|
925
|
+
export const zip: {
|
|
926
|
+
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<[A, B]>
|
|
927
|
+
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]>
|
|
928
|
+
} = dual(
|
|
929
|
+
2,
|
|
930
|
+
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<[A, B]> => zipWith(self, that, (a, b) => [a, b])
|
|
931
|
+
)
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Apply a function to pairs of elements at the same index in two `Iterable`s, collecting the results in a new `Array`. If one
|
|
935
|
+
* input `Iterable` is short, excess elements of the longer `Iterable` are discarded.
|
|
936
|
+
*
|
|
937
|
+
* @since 2.0.0
|
|
938
|
+
*/
|
|
939
|
+
export const zipWith: {
|
|
940
|
+
<B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Array<C>
|
|
941
|
+
<B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C>
|
|
942
|
+
} = dual(3, <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Array<C> => {
|
|
943
|
+
const as = fromIterable(self)
|
|
944
|
+
const bs = fromIterable(that)
|
|
945
|
+
return isNonEmptyReadonlyArray(as) && isNonEmptyReadonlyArray(bs) ? zipNonEmptyWith(bs, f)(as) : []
|
|
946
|
+
})
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* @since 2.0.0
|
|
950
|
+
*/
|
|
951
|
+
export const zipNonEmpty: {
|
|
952
|
+
<B>(that: NonEmptyReadonlyArray<B>): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<[A, B]>
|
|
953
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]>
|
|
954
|
+
} = dual(
|
|
955
|
+
2,
|
|
956
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, that: NonEmptyReadonlyArray<B>): NonEmptyArray<[A, B]> =>
|
|
957
|
+
zipNonEmptyWith(self, that, (a, b) => [a, b])
|
|
958
|
+
)
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* @since 2.0.0
|
|
962
|
+
*/
|
|
963
|
+
export const zipNonEmptyWith: {
|
|
964
|
+
<B, A, C>(
|
|
965
|
+
that: NonEmptyReadonlyArray<B>,
|
|
966
|
+
f: (a: A, b: B) => C
|
|
967
|
+
): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<C>
|
|
968
|
+
<A, B, C>(
|
|
969
|
+
self: NonEmptyReadonlyArray<A>,
|
|
970
|
+
that: NonEmptyReadonlyArray<B>,
|
|
971
|
+
f: (a: A, b: B) => C
|
|
972
|
+
): NonEmptyArray<C>
|
|
973
|
+
} = dual(3, <A, B, C>(
|
|
974
|
+
self: NonEmptyReadonlyArray<A>,
|
|
975
|
+
that: NonEmptyReadonlyArray<B>,
|
|
976
|
+
f: (a: A, b: B) => C
|
|
977
|
+
): NonEmptyArray<C> => {
|
|
978
|
+
const cs: NonEmptyArray<C> = [f(headNonEmpty(self), headNonEmpty(that))]
|
|
979
|
+
const len = Math.min(self.length, that.length)
|
|
980
|
+
for (let i = 1; i < len; i++) {
|
|
981
|
+
cs[i] = f(self[i], that[i])
|
|
982
|
+
}
|
|
983
|
+
return cs
|
|
984
|
+
})
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* This function is the inverse of `zip`. Takes an `Iterable` of pairs and return two corresponding `Array`s.
|
|
988
|
+
*
|
|
989
|
+
* @since 2.0.0
|
|
990
|
+
*/
|
|
991
|
+
export const unzip = <A, B>(self: Iterable<readonly [A, B]>): [Array<A>, Array<B>] => {
|
|
992
|
+
const input = fromIterable(self)
|
|
993
|
+
return isNonEmptyReadonlyArray(input) ? unzipNonEmpty(input) : [[], []]
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* @since 2.0.0
|
|
998
|
+
*/
|
|
999
|
+
export const unzipNonEmpty = <A, B>(
|
|
1000
|
+
self: NonEmptyReadonlyArray<readonly [A, B]>
|
|
1001
|
+
): [NonEmptyArray<A>, NonEmptyArray<B>] => {
|
|
1002
|
+
const fa: NonEmptyArray<A> = [self[0][0]]
|
|
1003
|
+
const fb: NonEmptyArray<B> = [self[0][1]]
|
|
1004
|
+
for (let i = 1; i < self.length; i++) {
|
|
1005
|
+
fa[i] = self[i][0]
|
|
1006
|
+
fb[i] = self[i][1]
|
|
1007
|
+
}
|
|
1008
|
+
return [fa, fb]
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* Places an element in between members of an `Iterable`
|
|
1013
|
+
*
|
|
1014
|
+
* @since 2.0.0
|
|
1015
|
+
*/
|
|
1016
|
+
export const intersperse: {
|
|
1017
|
+
<B>(middle: B): <A>(self: Iterable<A>) => Array<A | B>
|
|
1018
|
+
<A, B>(self: Iterable<A>, middle: B): Array<A | B>
|
|
1019
|
+
} = dual(2, <A, B>(self: Iterable<A>, middle: B): Array<A | B> => {
|
|
1020
|
+
const input = fromIterable(self)
|
|
1021
|
+
return (isNonEmptyReadonlyArray(input) ? intersperseNonEmpty(input, middle) : [])
|
|
1022
|
+
})
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Places an element in between members of a `NonEmptyReadonlyArray`
|
|
1026
|
+
*
|
|
1027
|
+
* @since 2.0.0
|
|
1028
|
+
*/
|
|
1029
|
+
export const intersperseNonEmpty: {
|
|
1030
|
+
<B>(middle: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
1031
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B>
|
|
1032
|
+
} = dual(2, <A, B>(self: NonEmptyReadonlyArray<A>, middle: B): NonEmptyArray<A | B> => {
|
|
1033
|
+
const out: NonEmptyArray<A | B> = [headNonEmpty(self)]
|
|
1034
|
+
const tail = tailNonEmpty(self)
|
|
1035
|
+
for (let i = 0; i < tail.length; i++) {
|
|
1036
|
+
if (i < tail.length) {
|
|
1037
|
+
out.push(middle)
|
|
1038
|
+
}
|
|
1039
|
+
out.push(tail[i])
|
|
1040
|
+
}
|
|
1041
|
+
return out
|
|
1042
|
+
})
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Apply a function to the head, creating a new `NonEmptyReadonlyArray`.
|
|
1046
|
+
*
|
|
1047
|
+
* @since 2.0.0
|
|
1048
|
+
*/
|
|
1049
|
+
export const modifyNonEmptyHead: {
|
|
1050
|
+
<A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
1051
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>
|
|
1052
|
+
} = dual(
|
|
1053
|
+
2,
|
|
1054
|
+
<A, B>(
|
|
1055
|
+
self: NonEmptyReadonlyArray<A>,
|
|
1056
|
+
f: (a: A) => B
|
|
1057
|
+
): NonEmptyArray<A | B> => [f(headNonEmpty(self)), ...tailNonEmpty(self)]
|
|
1058
|
+
)
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* Change the head, creating a new `NonEmptyReadonlyArray`.
|
|
1062
|
+
*
|
|
1063
|
+
* @since 2.0.0
|
|
1064
|
+
*/
|
|
1065
|
+
export const setNonEmptyHead: {
|
|
1066
|
+
<B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
1067
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>
|
|
1068
|
+
} = dual(
|
|
1069
|
+
2,
|
|
1070
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyHead(self, () => b)
|
|
1071
|
+
)
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* Apply a function to the last element, creating a new `NonEmptyReadonlyArray`.
|
|
1075
|
+
*
|
|
1076
|
+
* @since 2.0.0
|
|
1077
|
+
*/
|
|
1078
|
+
export const modifyNonEmptyLast: {
|
|
1079
|
+
<A, B>(f: (a: A) => B): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
1080
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B>
|
|
1081
|
+
} = dual(
|
|
1082
|
+
2,
|
|
1083
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A) => B): NonEmptyArray<A | B> =>
|
|
1084
|
+
append(initNonEmpty(self), f(lastNonEmpty(self)))
|
|
1085
|
+
)
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Change the last element, creating a new `NonEmptyReadonlyArray`.
|
|
1089
|
+
*
|
|
1090
|
+
* @since 2.0.0
|
|
1091
|
+
*/
|
|
1092
|
+
export const setNonEmptyLast: {
|
|
1093
|
+
<B>(b: B): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A | B>
|
|
1094
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B>
|
|
1095
|
+
} = dual(
|
|
1096
|
+
2,
|
|
1097
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, b: B): NonEmptyArray<A | B> => modifyNonEmptyLast(self, () => b)
|
|
1098
|
+
)
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* Rotate an `Iterable` by `n` steps.
|
|
1102
|
+
*
|
|
1103
|
+
* @since 2.0.0
|
|
1104
|
+
*/
|
|
1105
|
+
export const rotate: {
|
|
1106
|
+
(n: number): <A>(self: Iterable<A>) => Array<A>
|
|
1107
|
+
<A>(self: Iterable<A>, n: number): Array<A>
|
|
1108
|
+
} = dual(2, <A>(self: Iterable<A>, n: number): Array<A> => {
|
|
1109
|
+
const input = fromIterable(self)
|
|
1110
|
+
return isNonEmptyReadonlyArray(input) ? rotateNonEmpty(input, n) : []
|
|
1111
|
+
})
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
1114
|
+
* Rotate a `NonEmptyReadonlyArray` by `n` steps.
|
|
1115
|
+
*
|
|
1116
|
+
* @since 2.0.0
|
|
1117
|
+
*/
|
|
1118
|
+
export const rotateNonEmpty: {
|
|
1119
|
+
(n: number): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A>
|
|
1120
|
+
<A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A>
|
|
1121
|
+
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<A> => {
|
|
1122
|
+
const len = self.length
|
|
1123
|
+
const m = Math.round(n) % len
|
|
1124
|
+
if (isOutOfBound(Math.abs(m), self) || m === 0) {
|
|
1125
|
+
return copy(self)
|
|
1126
|
+
}
|
|
1127
|
+
if (m < 0) {
|
|
1128
|
+
const [f, s] = splitNonEmptyAt(self, -m)
|
|
1129
|
+
return appendAllNonEmpty(s, f)
|
|
1130
|
+
} else {
|
|
1131
|
+
return rotateNonEmpty(self, m - len)
|
|
1132
|
+
}
|
|
1133
|
+
})
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Returns a function that checks if a `ReadonlyArray` contains a given value using a provided `isEquivalent` function.
|
|
1137
|
+
*
|
|
1138
|
+
* @category elements
|
|
1139
|
+
* @since 2.0.0
|
|
1140
|
+
*/
|
|
1141
|
+
export const containsWith = <A>(isEquivalent: (self: A, that: A) => boolean): {
|
|
1142
|
+
(a: A): (self: Iterable<A>) => boolean
|
|
1143
|
+
(self: Iterable<A>, a: A): boolean
|
|
1144
|
+
} =>
|
|
1145
|
+
dual(2, (self: Iterable<A>, a: A): boolean => {
|
|
1146
|
+
for (const i of self) {
|
|
1147
|
+
if (isEquivalent(a, i)) {
|
|
1148
|
+
return true
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return false
|
|
1152
|
+
})
|
|
1153
|
+
|
|
1154
|
+
const _equivalence = Equal.equivalence()
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* Returns a function that checks if a `ReadonlyArray` contains a given value using the default `Equivalence`.
|
|
1158
|
+
*
|
|
1159
|
+
* @category elements
|
|
1160
|
+
* @since 2.0.0
|
|
1161
|
+
*/
|
|
1162
|
+
export const contains: {
|
|
1163
|
+
<A>(a: A): (self: Iterable<A>) => boolean
|
|
1164
|
+
<A>(self: Iterable<A>, a: A): boolean
|
|
1165
|
+
} = containsWith(_equivalence)
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* Remove duplicates from a `NonEmptyReadonlyArray`, keeping the first occurrence of an element using the provided `isEquivalent` function.
|
|
1169
|
+
*
|
|
1170
|
+
* @since 2.0.0
|
|
1171
|
+
*/
|
|
1172
|
+
export const dedupeNonEmptyWith: {
|
|
1173
|
+
<A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A>
|
|
1174
|
+
<A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<A>
|
|
1175
|
+
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<A> => {
|
|
1176
|
+
const out: NonEmptyArray<A> = [headNonEmpty(self)]
|
|
1177
|
+
const rest = tailNonEmpty(self)
|
|
1178
|
+
for (const a of rest) {
|
|
1179
|
+
if (out.every((o) => !isEquivalent(a, o))) {
|
|
1180
|
+
out.push(a)
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return out
|
|
1184
|
+
})
|
|
1185
|
+
|
|
1186
|
+
/**
|
|
1187
|
+
* Remove duplicates from a `NonEmptyReadonlyArray`, keeping the first occurrence of an element.
|
|
1188
|
+
*
|
|
1189
|
+
* @since 2.0.0
|
|
1190
|
+
*/
|
|
1191
|
+
export const dedupeNonEmpty: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A> = dedupeNonEmptyWith(
|
|
1192
|
+
Equal.equivalence()
|
|
1193
|
+
)
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* A useful recursion pattern for processing an `Iterable` to produce a new `Array`, often used for "chopping" up the input
|
|
1197
|
+
* `Iterable`. Typically chop is called with some function that will consume an initial prefix of the `Iterable` and produce a
|
|
1198
|
+
* value and the rest of the `Array`.
|
|
1199
|
+
*
|
|
1200
|
+
* @since 2.0.0
|
|
1201
|
+
*/
|
|
1202
|
+
export const chop: {
|
|
1203
|
+
<A, B>(
|
|
1204
|
+
f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]
|
|
1205
|
+
): (self: Iterable<A>) => Array<B>
|
|
1206
|
+
<A, B>(
|
|
1207
|
+
self: Iterable<A>,
|
|
1208
|
+
f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]
|
|
1209
|
+
): Array<B>
|
|
1210
|
+
} = dual(2, <A, B>(
|
|
1211
|
+
self: Iterable<A>,
|
|
1212
|
+
f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]
|
|
1213
|
+
): Array<B> => {
|
|
1214
|
+
const input = fromIterable(self)
|
|
1215
|
+
return isNonEmptyReadonlyArray(input) ? chopNonEmpty(input, f) : []
|
|
1216
|
+
})
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* A useful recursion pattern for processing a `NonEmptyReadonlyArray` to produce a new `NonEmptyReadonlyArray`, often used for "chopping" up the input
|
|
1220
|
+
* `NonEmptyReadonlyArray`. Typically `chop` is called with some function that will consume an initial prefix of the `NonEmptyReadonlyArray` and produce a
|
|
1221
|
+
* value and the tail of the `NonEmptyReadonlyArray`.
|
|
1222
|
+
*
|
|
1223
|
+
* @since 2.0.0
|
|
1224
|
+
*/
|
|
1225
|
+
export const chopNonEmpty: {
|
|
1226
|
+
<A, B>(
|
|
1227
|
+
f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]
|
|
1228
|
+
): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<B>
|
|
1229
|
+
<A, B>(
|
|
1230
|
+
self: NonEmptyReadonlyArray<A>,
|
|
1231
|
+
f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]
|
|
1232
|
+
): NonEmptyArray<B>
|
|
1233
|
+
} = dual(2, <A, B>(
|
|
1234
|
+
self: NonEmptyReadonlyArray<A>,
|
|
1235
|
+
f: (as: NonEmptyReadonlyArray<A>) => readonly [B, ReadonlyArray<A>]
|
|
1236
|
+
): NonEmptyArray<B> => {
|
|
1237
|
+
const [b, rest] = f(self)
|
|
1238
|
+
const out: NonEmptyArray<B> = [b]
|
|
1239
|
+
let next: ReadonlyArray<A> = rest
|
|
1240
|
+
while (readonlyArray.isNonEmptyArray(next)) {
|
|
1241
|
+
const [b, rest] = f(next)
|
|
1242
|
+
out.push(b)
|
|
1243
|
+
next = rest
|
|
1244
|
+
}
|
|
1245
|
+
return out
|
|
1246
|
+
})
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* Splits an `Iterable` into two pieces, the first piece has max `n` elements.
|
|
1250
|
+
*
|
|
1251
|
+
* @category getters
|
|
1252
|
+
* @since 2.0.0
|
|
1253
|
+
*/
|
|
1254
|
+
export const splitAt: {
|
|
1255
|
+
(n: number): <A>(self: Iterable<A>) => [Array<A>, Array<A>]
|
|
1256
|
+
<A>(self: Iterable<A>, n: number): [Array<A>, Array<A>]
|
|
1257
|
+
} = dual(2, <A>(self: Iterable<A>, n: number): [Array<A>, Array<A>] => {
|
|
1258
|
+
const input = Array.from(self)
|
|
1259
|
+
return n >= 1 && isNonEmptyReadonlyArray(input) ?
|
|
1260
|
+
splitNonEmptyAt(input, n) :
|
|
1261
|
+
isEmptyReadonlyArray(input) ?
|
|
1262
|
+
[input, []] :
|
|
1263
|
+
[[], input]
|
|
1264
|
+
})
|
|
1265
|
+
|
|
1266
|
+
/**
|
|
1267
|
+
* @since 2.0.0
|
|
1268
|
+
*/
|
|
1269
|
+
export const copy: {
|
|
1270
|
+
<A>(self: NonEmptyReadonlyArray<A>): NonEmptyArray<A>
|
|
1271
|
+
<A>(self: ReadonlyArray<A>): Array<A>
|
|
1272
|
+
} = (<A>(self: ReadonlyArray<A>): Array<A> => self.slice()) as any
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* Splits a `NonEmptyReadonlyArray` into two pieces, the first piece has max `n` elements.
|
|
1276
|
+
*
|
|
1277
|
+
* @category getters
|
|
1278
|
+
* @since 2.0.0
|
|
1279
|
+
*/
|
|
1280
|
+
export const splitNonEmptyAt: {
|
|
1281
|
+
(n: number): <A>(self: NonEmptyReadonlyArray<A>) => [NonEmptyArray<A>, Array<A>]
|
|
1282
|
+
<A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>]
|
|
1283
|
+
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, n: number): [NonEmptyArray<A>, Array<A>] => {
|
|
1284
|
+
const m = Math.max(1, n)
|
|
1285
|
+
return m >= self.length ?
|
|
1286
|
+
[copy(self), []] :
|
|
1287
|
+
[prepend(self.slice(1, m), headNonEmpty(self)), self.slice(m)]
|
|
1288
|
+
})
|
|
1289
|
+
|
|
1290
|
+
/**
|
|
1291
|
+
* Splits an `Iterable` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
1292
|
+
* the `Iterable`. Note that `chunksOf(n)([])` is `[]`, not `[[]]`. This is intentional, and is consistent with a recursive
|
|
1293
|
+
* definition of `chunksOf`; it satisfies the property that
|
|
1294
|
+
*
|
|
1295
|
+
* ```ts
|
|
1296
|
+
* chunksOf(n)(xs).concat(chunksOf(n)(ys)) == chunksOf(n)(xs.concat(ys)))
|
|
1297
|
+
* ```
|
|
1298
|
+
*
|
|
1299
|
+
* whenever `n` evenly divides the length of `self`.
|
|
1300
|
+
*
|
|
1301
|
+
* @category getters
|
|
1302
|
+
* @since 2.0.0
|
|
1303
|
+
*/
|
|
1304
|
+
export const chunksOf: {
|
|
1305
|
+
(n: number): <A>(self: Iterable<A>) => Array<NonEmptyArray<A>>
|
|
1306
|
+
<A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>>
|
|
1307
|
+
} = dual(2, <A>(self: Iterable<A>, n: number): Array<NonEmptyArray<A>> => {
|
|
1308
|
+
const input = fromIterable(self)
|
|
1309
|
+
return isNonEmptyReadonlyArray(input) ? chunksOfNonEmpty(input, n) : []
|
|
1310
|
+
})
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* Splits a `NonEmptyReadonlyArray` into length-`n` pieces. The last piece will be shorter if `n` does not evenly divide the length of
|
|
1314
|
+
* the `NonEmptyReadonlyArray`.
|
|
1315
|
+
*
|
|
1316
|
+
* @category getters
|
|
1317
|
+
* @since 2.0.0
|
|
1318
|
+
*/
|
|
1319
|
+
export const chunksOfNonEmpty: {
|
|
1320
|
+
(n: number): <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>
|
|
1321
|
+
<A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>>
|
|
1322
|
+
} = dual(
|
|
1323
|
+
2,
|
|
1324
|
+
<A>(self: NonEmptyReadonlyArray<A>, n: number): NonEmptyArray<NonEmptyArray<A>> =>
|
|
1325
|
+
chopNonEmpty(self, splitNonEmptyAt(n))
|
|
1326
|
+
)
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s using the provided `isEquivalent` function.
|
|
1330
|
+
*
|
|
1331
|
+
* @category grouping
|
|
1332
|
+
* @since 2.0.0
|
|
1333
|
+
*/
|
|
1334
|
+
export const groupWith: {
|
|
1335
|
+
<A>(isEquivalent: (self: A, that: A) => boolean): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>>
|
|
1336
|
+
<A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>>
|
|
1337
|
+
} = dual(
|
|
1338
|
+
2,
|
|
1339
|
+
<A>(self: NonEmptyReadonlyArray<A>, isEquivalent: (self: A, that: A) => boolean): NonEmptyArray<NonEmptyArray<A>> =>
|
|
1340
|
+
chopNonEmpty(self, (as) => {
|
|
1341
|
+
const h = headNonEmpty(as)
|
|
1342
|
+
const out: NonEmptyArray<A> = [h]
|
|
1343
|
+
let i = 1
|
|
1344
|
+
for (; i < as.length; i++) {
|
|
1345
|
+
const a = as[i]
|
|
1346
|
+
if (isEquivalent(a, h)) {
|
|
1347
|
+
out.push(a)
|
|
1348
|
+
} else {
|
|
1349
|
+
break
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return [out, as.slice(i)]
|
|
1353
|
+
})
|
|
1354
|
+
)
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* Group equal, consecutive elements of a `NonEmptyReadonlyArray` into `NonEmptyArray`s.
|
|
1358
|
+
*
|
|
1359
|
+
* @category grouping
|
|
1360
|
+
* @since 2.0.0
|
|
1361
|
+
*/
|
|
1362
|
+
export const group: <A>(self: NonEmptyReadonlyArray<A>) => NonEmptyArray<NonEmptyArray<A>> = groupWith(
|
|
1363
|
+
Equal.equivalence()
|
|
1364
|
+
)
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Splits an `Iterable` into sub-non-empty-arrays stored in an object, based on the result of calling a `string`-returning
|
|
1368
|
+
* function on each element, and grouping the results according to values returned
|
|
1369
|
+
*
|
|
1370
|
+
* @category grouping
|
|
1371
|
+
* @since 2.0.0
|
|
1372
|
+
*/
|
|
1373
|
+
export const groupBy: {
|
|
1374
|
+
<A>(f: (a: A) => string): (self: Iterable<A>) => Record<string, NonEmptyArray<A>>
|
|
1375
|
+
<A>(self: Iterable<A>, f: (a: A) => string): Record<string, NonEmptyArray<A>>
|
|
1376
|
+
} = dual(2, <A>(self: Iterable<A>, f: (a: A) => string): Record<string, NonEmptyArray<A>> => {
|
|
1377
|
+
const out: Record<string, NonEmptyArray<A>> = {}
|
|
1378
|
+
for (const a of self) {
|
|
1379
|
+
const k = f(a)
|
|
1380
|
+
if (Object.prototype.hasOwnProperty.call(out, k)) {
|
|
1381
|
+
out[k].push(a)
|
|
1382
|
+
} else {
|
|
1383
|
+
out[k] = [a]
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
return out
|
|
1387
|
+
})
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* @since 2.0.0
|
|
1391
|
+
*/
|
|
1392
|
+
export const unionWith = <A>(isEquivalent: (self: A, that: A) => boolean): {
|
|
1393
|
+
(that: Iterable<A>): (self: Iterable<A>) => Array<A>
|
|
1394
|
+
(self: Iterable<A>, that: Iterable<A>): Array<A>
|
|
1395
|
+
} =>
|
|
1396
|
+
dual(2, (self: Iterable<A>, that: Iterable<A>): Array<A> => {
|
|
1397
|
+
const a = fromIterable(self)
|
|
1398
|
+
const b = fromIterable(that)
|
|
1399
|
+
return isNonEmptyReadonlyArray(a) && isNonEmptyReadonlyArray(b) ?
|
|
1400
|
+
unionNonEmptyWith(isEquivalent)(a, b) :
|
|
1401
|
+
isNonEmptyReadonlyArray(a) ?
|
|
1402
|
+
a :
|
|
1403
|
+
b
|
|
1404
|
+
})
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* @since 2.0.0
|
|
1408
|
+
*/
|
|
1409
|
+
export const union: {
|
|
1410
|
+
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A | B>
|
|
1411
|
+
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A | B>
|
|
1412
|
+
} = unionWith(_equivalence)
|
|
1413
|
+
|
|
1414
|
+
/**
|
|
1415
|
+
* @since 2.0.0
|
|
1416
|
+
*/
|
|
1417
|
+
export const unionNonEmptyWith = <A>(isEquivalent: (self: A, that: A) => boolean): {
|
|
1418
|
+
(that: NonEmptyReadonlyArray<A>): (self: ReadonlyArray<A>) => NonEmptyArray<A>
|
|
1419
|
+
(that: ReadonlyArray<A>): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A>
|
|
1420
|
+
(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<A>): NonEmptyArray<A>
|
|
1421
|
+
(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<A>): NonEmptyArray<A>
|
|
1422
|
+
} => {
|
|
1423
|
+
const dedupe = dedupeNonEmptyWith(isEquivalent)
|
|
1424
|
+
return dual(
|
|
1425
|
+
2,
|
|
1426
|
+
(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<A>): NonEmptyArray<A> => dedupe(appendAllNonEmpty(self, that))
|
|
1427
|
+
)
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
/**
|
|
1431
|
+
* @since 2.0.0
|
|
1432
|
+
*/
|
|
1433
|
+
export const unionNonEmpty: {
|
|
1434
|
+
<A>(that: NonEmptyReadonlyArray<A>): (self: ReadonlyArray<A>) => NonEmptyArray<A>
|
|
1435
|
+
<A>(that: ReadonlyArray<A>): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<A>
|
|
1436
|
+
<A>(self: ReadonlyArray<A>, that: NonEmptyReadonlyArray<A>): NonEmptyArray<A>
|
|
1437
|
+
<A>(self: NonEmptyReadonlyArray<A>, that: ReadonlyArray<A>): NonEmptyArray<A>
|
|
1438
|
+
} = unionNonEmptyWith(_equivalence)
|
|
1439
|
+
|
|
1440
|
+
/**
|
|
1441
|
+
* Creates an `Array` of unique values that are included in all given `Iterable`s using the provided `isEquivalent` function.
|
|
1442
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
1443
|
+
*
|
|
1444
|
+
* @since 2.0.0
|
|
1445
|
+
*/
|
|
1446
|
+
export const intersectionWith = <A>(isEquivalent: (self: A, that: A) => boolean): {
|
|
1447
|
+
(that: Iterable<A>): (self: Iterable<A>) => Array<A>
|
|
1448
|
+
(self: Iterable<A>, that: Iterable<A>): Array<A>
|
|
1449
|
+
} => {
|
|
1450
|
+
const has = containsWith(isEquivalent)
|
|
1451
|
+
return dual(
|
|
1452
|
+
2,
|
|
1453
|
+
(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => has(that, a))
|
|
1454
|
+
)
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
/**
|
|
1458
|
+
* Creates an `Array` of unique values that are included in all given `Iterable`s.
|
|
1459
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
1460
|
+
*
|
|
1461
|
+
* @since 2.0.0
|
|
1462
|
+
*/
|
|
1463
|
+
export const intersection: {
|
|
1464
|
+
<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>
|
|
1465
|
+
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>
|
|
1466
|
+
} = intersectionWith(_equivalence)
|
|
1467
|
+
|
|
1468
|
+
/**
|
|
1469
|
+
* Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.
|
|
1470
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
1471
|
+
*
|
|
1472
|
+
* @since 2.0.0
|
|
1473
|
+
*/
|
|
1474
|
+
export const differenceWith = <A>(isEquivalent: (self: A, that: A) => boolean): {
|
|
1475
|
+
(that: Iterable<A>): (self: Iterable<A>) => Array<A>
|
|
1476
|
+
(self: Iterable<A>, that: Iterable<A>): Array<A>
|
|
1477
|
+
} => {
|
|
1478
|
+
const has = containsWith(isEquivalent)
|
|
1479
|
+
return dual(
|
|
1480
|
+
2,
|
|
1481
|
+
(self: Iterable<A>, that: Iterable<A>): Array<A> => fromIterable(self).filter((a) => !has(that, a))
|
|
1482
|
+
)
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
/**
|
|
1486
|
+
* Creates a `Array` of values not included in the other given `Iterable` using the provided `isEquivalent` function.
|
|
1487
|
+
* The order and references of result values are determined by the first `Iterable`.
|
|
1488
|
+
*
|
|
1489
|
+
* @since 2.0.0
|
|
1490
|
+
*/
|
|
1491
|
+
export const difference: {
|
|
1492
|
+
<A>(that: Iterable<A>): (self: Iterable<A>) => Array<A>
|
|
1493
|
+
<A>(self: Iterable<A>, that: Iterable<A>): Array<A>
|
|
1494
|
+
} = differenceWith(_equivalence)
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* @category constructors
|
|
1498
|
+
* @since 2.0.0
|
|
1499
|
+
*/
|
|
1500
|
+
export const empty: <A = never>() => Array<A> = () => []
|
|
1501
|
+
|
|
1502
|
+
/**
|
|
1503
|
+
* Constructs a new `NonEmptyArray<A>` from the specified value.
|
|
1504
|
+
*
|
|
1505
|
+
* @category constructors
|
|
1506
|
+
* @since 2.0.0
|
|
1507
|
+
*/
|
|
1508
|
+
export const of = <A>(a: A): NonEmptyArray<A> => [a]
|
|
1509
|
+
|
|
1510
|
+
/**
|
|
1511
|
+
* @category mapping
|
|
1512
|
+
* @since 2.0.0
|
|
1513
|
+
*/
|
|
1514
|
+
export const map: {
|
|
1515
|
+
<A, B>(f: (a: A, i: number) => B): (self: ReadonlyArray<A>) => Array<B>
|
|
1516
|
+
<A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B>
|
|
1517
|
+
} = dual(2, <A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => B): Array<B> => self.map(f))
|
|
1518
|
+
|
|
1519
|
+
/**
|
|
1520
|
+
* @category mapping
|
|
1521
|
+
* @since 2.0.0
|
|
1522
|
+
*/
|
|
1523
|
+
export const mapNonEmpty: {
|
|
1524
|
+
<A, B>(f: (a: A, i: number) => B): (self: readonly [A, ...Array<A>]) => [B, ...Array<B>]
|
|
1525
|
+
<A, B>(self: readonly [A, ...Array<A>], f: (a: A, i: number) => B): [B, ...Array<B>]
|
|
1526
|
+
} = map as any
|
|
1527
|
+
|
|
1528
|
+
/**
|
|
1529
|
+
* @category sequencing
|
|
1530
|
+
* @since 2.0.0
|
|
1531
|
+
*/
|
|
1532
|
+
export const flatMap: {
|
|
1533
|
+
<A, B>(f: (a: A, i: number) => ReadonlyArray<B>): (self: ReadonlyArray<A>) => Array<B>
|
|
1534
|
+
<A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B>
|
|
1535
|
+
} = dual(
|
|
1536
|
+
2,
|
|
1537
|
+
<A, B>(self: ReadonlyArray<A>, f: (a: A, i: number) => ReadonlyArray<B>): Array<B> => {
|
|
1538
|
+
if (isEmptyReadonlyArray(self)) {
|
|
1539
|
+
return []
|
|
1540
|
+
}
|
|
1541
|
+
const out: Array<B> = []
|
|
1542
|
+
for (let i = 0; i < self.length; i++) {
|
|
1543
|
+
out.push(...f(self[i], i))
|
|
1544
|
+
}
|
|
1545
|
+
return out
|
|
1546
|
+
}
|
|
1547
|
+
)
|
|
1548
|
+
|
|
1549
|
+
/**
|
|
1550
|
+
* @category sequencing
|
|
1551
|
+
* @since 2.0.0
|
|
1552
|
+
*/
|
|
1553
|
+
export const flatMapNonEmpty: {
|
|
1554
|
+
<A, B>(f: (a: A, i: number) => NonEmptyReadonlyArray<B>): (self: NonEmptyReadonlyArray<A>) => NonEmptyArray<B>
|
|
1555
|
+
<A, B>(self: NonEmptyReadonlyArray<A>, f: (a: A, i: number) => NonEmptyReadonlyArray<B>): NonEmptyArray<B>
|
|
1556
|
+
} = flatMap as any
|
|
1557
|
+
|
|
1558
|
+
/**
|
|
1559
|
+
* @category sequencing
|
|
1560
|
+
* @since 2.0.0
|
|
1561
|
+
*/
|
|
1562
|
+
export const flatten: <A>(self: ReadonlyArray<ReadonlyArray<A>>) => Array<A> = flatMap(identity)
|
|
1563
|
+
|
|
1564
|
+
/**
|
|
1565
|
+
* @category sequencing
|
|
1566
|
+
* @since 2.0.0
|
|
1567
|
+
*/
|
|
1568
|
+
export const flattenNonEmpty: <A>(
|
|
1569
|
+
self: NonEmptyReadonlyArray<NonEmptyReadonlyArray<A>>
|
|
1570
|
+
) => NonEmptyArray<A> = flatMapNonEmpty(identity)
|
|
1571
|
+
|
|
1572
|
+
/**
|
|
1573
|
+
* @category filtering
|
|
1574
|
+
* @since 2.0.0
|
|
1575
|
+
*/
|
|
1576
|
+
export const filterMap: {
|
|
1577
|
+
<A, B>(f: (a: A, i: number) => Option<B>): (self: Iterable<A>) => Array<B>
|
|
1578
|
+
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B>
|
|
1579
|
+
} = dual(
|
|
1580
|
+
2,
|
|
1581
|
+
<A, B>(self: Iterable<A>, f: (a: A, i: number) => Option<B>): Array<B> => {
|
|
1582
|
+
const as = fromIterable(self)
|
|
1583
|
+
const out: Array<B> = []
|
|
1584
|
+
for (let i = 0; i < as.length; i++) {
|
|
1585
|
+
const o = f(as[i], i)
|
|
1586
|
+
if (O.isSome(o)) {
|
|
1587
|
+
out.push(o.value)
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return out
|
|
1591
|
+
}
|
|
1592
|
+
)
|
|
1593
|
+
|
|
1594
|
+
/**
|
|
1595
|
+
* Transforms all elements of the `readonlyArray` for as long as the specified function returns some value
|
|
1596
|
+
*
|
|
1597
|
+
* @category filtering
|
|
1598
|
+
* @since 2.0.0
|
|
1599
|
+
*/
|
|
1600
|
+
export const filterMapWhile: {
|
|
1601
|
+
<A, B>(f: (a: A) => Option<B>): (self: Iterable<A>) => Array<B>
|
|
1602
|
+
<A, B>(self: Iterable<A>, f: (a: A) => Option<B>): Array<B>
|
|
1603
|
+
} = dual(2, <A, B>(self: Iterable<A>, f: (a: A) => Option<B>) => {
|
|
1604
|
+
const out: Array<B> = []
|
|
1605
|
+
for (const a of self) {
|
|
1606
|
+
const b = f(a)
|
|
1607
|
+
if (O.isSome(b)) {
|
|
1608
|
+
out.push(b.value)
|
|
1609
|
+
} else {
|
|
1610
|
+
break
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
return out
|
|
1614
|
+
})
|
|
1615
|
+
|
|
1616
|
+
/**
|
|
1617
|
+
* @category filtering
|
|
1618
|
+
* @since 2.0.0
|
|
1619
|
+
*/
|
|
1620
|
+
export const partitionMap: {
|
|
1621
|
+
<A, B, C>(f: (a: A, i: number) => Either<B, C>): (self: Iterable<A>) => [Array<B>, Array<C>]
|
|
1622
|
+
<A, B, C>(self: Iterable<A>, f: (a: A, i: number) => Either<B, C>): [Array<B>, Array<C>]
|
|
1623
|
+
} = dual(
|
|
1624
|
+
2,
|
|
1625
|
+
<A, B, C>(self: Iterable<A>, f: (a: A, i: number) => Either<B, C>): [Array<B>, Array<C>] => {
|
|
1626
|
+
const left: Array<B> = []
|
|
1627
|
+
const right: Array<C> = []
|
|
1628
|
+
const as = fromIterable(self)
|
|
1629
|
+
for (let i = 0; i < as.length; i++) {
|
|
1630
|
+
const e = f(as[i], i)
|
|
1631
|
+
if (E.isLeft(e)) {
|
|
1632
|
+
left.push(e.left)
|
|
1633
|
+
} else {
|
|
1634
|
+
right.push(e.right)
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
return [left, right]
|
|
1638
|
+
}
|
|
1639
|
+
)
|
|
1640
|
+
|
|
1641
|
+
/**
|
|
1642
|
+
* @category filtering
|
|
1643
|
+
* @since 2.0.0
|
|
1644
|
+
*/
|
|
1645
|
+
export const compact: <A>(self: Iterable<Option<A>>) => Array<A> = filterMap(identity)
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* @category filtering
|
|
1649
|
+
* @since 2.0.0
|
|
1650
|
+
*/
|
|
1651
|
+
export const filter: {
|
|
1652
|
+
<C extends A, B extends A, A = C>(
|
|
1653
|
+
refinement: (a: A, i: number) => a is B
|
|
1654
|
+
): (self: Iterable<C>) => Array<B>
|
|
1655
|
+
<B extends A, A = B>(predicate: (a: A, i: number) => boolean): (self: Iterable<B>) => Array<B>
|
|
1656
|
+
<C extends A, B extends A, A = C>(
|
|
1657
|
+
self: Iterable<C>,
|
|
1658
|
+
refinement: (a: A, i: number) => a is B
|
|
1659
|
+
): Array<B>
|
|
1660
|
+
<B extends A, A = B>(self: Iterable<B>, predicate: (a: A, i: number) => boolean): Array<B>
|
|
1661
|
+
} = dual(
|
|
1662
|
+
2,
|
|
1663
|
+
<B extends A, A = B>(self: Iterable<B>, predicate: (a: A, i: number) => boolean): Array<B> => {
|
|
1664
|
+
const as = fromIterable(self)
|
|
1665
|
+
const out: Array<B> = []
|
|
1666
|
+
for (let i = 0; i < as.length; i++) {
|
|
1667
|
+
if (predicate(as[i], i)) {
|
|
1668
|
+
out.push(as[i])
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
return out
|
|
1672
|
+
}
|
|
1673
|
+
)
|
|
1674
|
+
|
|
1675
|
+
/**
|
|
1676
|
+
* @category filtering
|
|
1677
|
+
* @since 2.0.0
|
|
1678
|
+
*/
|
|
1679
|
+
export const partition: {
|
|
1680
|
+
<C extends A, B extends A, A = C>(refinement: (a: A, i: number) => a is B): (
|
|
1681
|
+
self: Iterable<C>
|
|
1682
|
+
) => [Array<C>, Array<B>]
|
|
1683
|
+
<B extends A, A = B>(
|
|
1684
|
+
predicate: (a: A, i: number) => boolean
|
|
1685
|
+
): (self: Iterable<B>) => [Array<B>, Array<B>]
|
|
1686
|
+
<C extends A, B extends A, A = C>(
|
|
1687
|
+
self: Iterable<C>,
|
|
1688
|
+
refinement: (a: A, i: number) => a is B
|
|
1689
|
+
): [Array<C>, Array<B>]
|
|
1690
|
+
<B extends A, A = B>(
|
|
1691
|
+
self: Iterable<B>,
|
|
1692
|
+
predicate: (a: A, i: number) => boolean
|
|
1693
|
+
): [Array<B>, Array<B>]
|
|
1694
|
+
} = dual(
|
|
1695
|
+
2,
|
|
1696
|
+
<B extends A, A = B>(
|
|
1697
|
+
self: Iterable<B>,
|
|
1698
|
+
predicate: (a: A, i: number) => boolean
|
|
1699
|
+
): [Array<B>, Array<B>] => {
|
|
1700
|
+
const left: Array<B> = []
|
|
1701
|
+
const right: Array<B> = []
|
|
1702
|
+
const as = fromIterable(self)
|
|
1703
|
+
for (let i = 0; i < as.length; i++) {
|
|
1704
|
+
if (predicate(as[i], i)) {
|
|
1705
|
+
right.push(as[i])
|
|
1706
|
+
} else {
|
|
1707
|
+
left.push(as[i])
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
return [left, right]
|
|
1711
|
+
}
|
|
1712
|
+
)
|
|
1713
|
+
|
|
1714
|
+
/**
|
|
1715
|
+
* @category filtering
|
|
1716
|
+
* @since 2.0.0
|
|
1717
|
+
*/
|
|
1718
|
+
export const separate: <E, A>(self: Iterable<Either<E, A>>) => [Array<E>, Array<A>] = partitionMap(
|
|
1719
|
+
identity
|
|
1720
|
+
)
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* @category folding
|
|
1724
|
+
* @since 2.0.0
|
|
1725
|
+
*/
|
|
1726
|
+
export const reduce: {
|
|
1727
|
+
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B
|
|
1728
|
+
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
1729
|
+
} = dual(
|
|
1730
|
+
3,
|
|
1731
|
+
<B, A>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>
|
|
1732
|
+
fromIterable(self).reduce((b, a, i) => f(b, a, i), b)
|
|
1733
|
+
)
|
|
1734
|
+
|
|
1735
|
+
/**
|
|
1736
|
+
* @category folding
|
|
1737
|
+
* @since 2.0.0
|
|
1738
|
+
*/
|
|
1739
|
+
export const reduceRight: {
|
|
1740
|
+
<B, A>(b: B, f: (b: B, a: A, i: number) => B): (self: Iterable<A>) => B
|
|
1741
|
+
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B
|
|
1742
|
+
} = dual(
|
|
1743
|
+
3,
|
|
1744
|
+
<A, B>(self: Iterable<A>, b: B, f: (b: B, a: A, i: number) => B): B =>
|
|
1745
|
+
fromIterable(self).reduceRight((b, a, i) => f(b, a, i), b)
|
|
1746
|
+
)
|
|
1747
|
+
|
|
1748
|
+
/**
|
|
1749
|
+
* @category lifting
|
|
1750
|
+
* @since 2.0.0
|
|
1751
|
+
*/
|
|
1752
|
+
export const liftPredicate: {
|
|
1753
|
+
<C extends A, B extends A, A = C>(refinement: Refinement<A, B>): (c: C) => Array<B>
|
|
1754
|
+
<B extends A, A = B>(predicate: Predicate<A>): (b: B) => Array<B>
|
|
1755
|
+
} = <B extends A, A = B>(predicate: Predicate<A>) => (b: B) => predicate(b) ? [b] : []
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* @category lifting
|
|
1759
|
+
* @since 2.0.0
|
|
1760
|
+
*/
|
|
1761
|
+
export const liftOption = <A extends Array<unknown>, B>(
|
|
1762
|
+
f: (...a: A) => Option<B>
|
|
1763
|
+
) =>
|
|
1764
|
+
(...a: A): Array<B> => fromOption(f(...a))
|
|
1765
|
+
|
|
1766
|
+
/**
|
|
1767
|
+
* @category conversions
|
|
1768
|
+
* @since 2.0.0
|
|
1769
|
+
*/
|
|
1770
|
+
export const fromNullable = <A>(a: A): Array<NonNullable<A>> => a == null ? empty() : [a as NonNullable<A>]
|
|
1771
|
+
|
|
1772
|
+
/**
|
|
1773
|
+
* @category lifting
|
|
1774
|
+
* @since 2.0.0
|
|
1775
|
+
*/
|
|
1776
|
+
export const liftNullable = <A extends Array<unknown>, B>(
|
|
1777
|
+
f: (...a: A) => B | null | undefined
|
|
1778
|
+
): (...a: A) => Array<NonNullable<B>> =>
|
|
1779
|
+
(...a) => fromNullable(f(...a))
|
|
1780
|
+
|
|
1781
|
+
/**
|
|
1782
|
+
* @category combining
|
|
1783
|
+
* @since 2.0.0
|
|
1784
|
+
*/
|
|
1785
|
+
export const flatMapNullable: {
|
|
1786
|
+
<A, B>(f: (a: A) => B | null | undefined): (self: ReadonlyArray<A>) => Array<NonNullable<B>>
|
|
1787
|
+
<A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>>
|
|
1788
|
+
} = dual(
|
|
1789
|
+
2,
|
|
1790
|
+
<A, B>(self: ReadonlyArray<A>, f: (a: A) => B | null | undefined): Array<NonNullable<B>> =>
|
|
1791
|
+
isNonEmptyReadonlyArray(self) ? fromNullable(f(headNonEmpty(self))) : empty()
|
|
1792
|
+
)
|
|
1793
|
+
|
|
1794
|
+
/**
|
|
1795
|
+
* @category lifting
|
|
1796
|
+
* @since 2.0.0
|
|
1797
|
+
*/
|
|
1798
|
+
export const liftEither = <A extends Array<unknown>, E, B>(
|
|
1799
|
+
f: (...a: A) => Either<E, B>
|
|
1800
|
+
) =>
|
|
1801
|
+
(...a: A): Array<B> => {
|
|
1802
|
+
const e = f(...a)
|
|
1803
|
+
return E.isLeft(e) ? [] : [e.right]
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
/**
|
|
1807
|
+
* Check if a predicate holds true for every `ReadonlyArray` element.
|
|
1808
|
+
*
|
|
1809
|
+
* @category elements
|
|
1810
|
+
* @since 2.0.0
|
|
1811
|
+
*/
|
|
1812
|
+
export const every: {
|
|
1813
|
+
<A, B extends A>(refinement: Refinement<A, B>): (self: ReadonlyArray<A>) => self is ReadonlyArray<B>
|
|
1814
|
+
<A>(predicate: Predicate<A>): (self: ReadonlyArray<A>) => boolean
|
|
1815
|
+
<A, B extends A>(self: ReadonlyArray<A>, refinement: Refinement<A, B>): self is ReadonlyArray<B>
|
|
1816
|
+
<A>(self: ReadonlyArray<A>, predicate: Predicate<A>): boolean
|
|
1817
|
+
} = dual(
|
|
1818
|
+
2,
|
|
1819
|
+
<A, B extends A>(self: ReadonlyArray<A>, refinement: Refinement<A, B>): self is ReadonlyArray<B> =>
|
|
1820
|
+
self.every(refinement)
|
|
1821
|
+
)
|
|
1822
|
+
|
|
1823
|
+
/**
|
|
1824
|
+
* Check if a predicate holds true for some `ReadonlyArray` element.
|
|
1825
|
+
*
|
|
1826
|
+
* @category elements
|
|
1827
|
+
* @since 2.0.0
|
|
1828
|
+
*/
|
|
1829
|
+
export const some: {
|
|
1830
|
+
<A>(predicate: Predicate<A>): <B extends A>(self: ReadonlyArray<B>) => self is NonEmptyReadonlyArray<B>
|
|
1831
|
+
<B extends A, A = B>(self: ReadonlyArray<B>, predicate: Predicate<A>): self is NonEmptyReadonlyArray<B>
|
|
1832
|
+
} = dual(
|
|
1833
|
+
2,
|
|
1834
|
+
<A>(self: ReadonlyArray<A>, predicate: Predicate<A>): self is NonEmptyReadonlyArray<A> => self.some(predicate)
|
|
1835
|
+
)
|
|
1836
|
+
|
|
1837
|
+
/**
|
|
1838
|
+
* @since 2.0.0
|
|
1839
|
+
*/
|
|
1840
|
+
export const extend: {
|
|
1841
|
+
<A, B>(f: (as: ReadonlyArray<A>) => B): (self: ReadonlyArray<A>) => Array<B>
|
|
1842
|
+
<A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B>
|
|
1843
|
+
} = dual(
|
|
1844
|
+
2,
|
|
1845
|
+
<A, B>(self: ReadonlyArray<A>, f: (as: ReadonlyArray<A>) => B): Array<B> => self.map((_, i, as) => f(as.slice(i)))
|
|
1846
|
+
)
|
|
1847
|
+
|
|
1848
|
+
/**
|
|
1849
|
+
* @since 2.0.0
|
|
1850
|
+
*/
|
|
1851
|
+
export const min: {
|
|
1852
|
+
<A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A
|
|
1853
|
+
<A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A
|
|
1854
|
+
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.min(O)))
|
|
1855
|
+
|
|
1856
|
+
/**
|
|
1857
|
+
* @since 2.0.0
|
|
1858
|
+
*/
|
|
1859
|
+
export const max: {
|
|
1860
|
+
<A>(O: Order.Order<A>): (self: NonEmptyReadonlyArray<A>) => A
|
|
1861
|
+
<A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A
|
|
1862
|
+
} = dual(2, <A>(self: NonEmptyReadonlyArray<A>, O: Order.Order<A>): A => self.reduce(Order.max(O)))
|
|
1863
|
+
|
|
1864
|
+
/**
|
|
1865
|
+
* @category constructors
|
|
1866
|
+
* @since 2.0.0
|
|
1867
|
+
*/
|
|
1868
|
+
export const unfold = <B, A>(b: B, f: (b: B) => Option<readonly [A, B]>): Array<A> => {
|
|
1869
|
+
const out: Array<A> = []
|
|
1870
|
+
let next: B = b
|
|
1871
|
+
let o: Option<readonly [A, B]>
|
|
1872
|
+
while (O.isSome(o = f(next))) {
|
|
1873
|
+
const [a, b] = o.value
|
|
1874
|
+
out.push(a)
|
|
1875
|
+
next = b
|
|
1876
|
+
}
|
|
1877
|
+
return out
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
/**
|
|
1881
|
+
* This function creates and returns a new `Order` for an array of values based on a given `Order` for the elements of the array.
|
|
1882
|
+
* The returned `Order` compares two arrays by applying the given `Order` to each element in the arrays.
|
|
1883
|
+
* If all elements are equal, the arrays are then compared based on their length.
|
|
1884
|
+
* It is useful when you need to compare two arrays of the same type and you have a specific way of comparing each element of the array.
|
|
1885
|
+
*
|
|
1886
|
+
* @category instances
|
|
1887
|
+
* @since 2.0.0
|
|
1888
|
+
*/
|
|
1889
|
+
export const getOrder: <A>(O: Order.Order<A>) => Order.Order<ReadonlyArray<A>> = Order.array
|
|
1890
|
+
|
|
1891
|
+
/**
|
|
1892
|
+
* @category instances
|
|
1893
|
+
* @since 2.0.0
|
|
1894
|
+
*/
|
|
1895
|
+
export const getEquivalence: <A>(
|
|
1896
|
+
isEquivalent: Equivalence.Equivalence<A>
|
|
1897
|
+
) => Equivalence.Equivalence<ReadonlyArray<A>> = Equivalence.array
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* Iterate over the `Iterable` applying `f`.
|
|
1901
|
+
*
|
|
1902
|
+
* @since 2.0.0
|
|
1903
|
+
*/
|
|
1904
|
+
export const forEach: {
|
|
1905
|
+
<A>(f: (a: A, i: number) => void): (self: Iterable<A>) => void
|
|
1906
|
+
<A>(self: Iterable<A>, f: (a: A, i: number) => void): void
|
|
1907
|
+
} = dual(2, <A>(self: Iterable<A>, f: (a: A, i: number) => void): void => fromIterable(self).forEach((a, i) => f(a, i)))
|
|
1908
|
+
|
|
1909
|
+
/**
|
|
1910
|
+
* Remove duplicates from am `Iterable` using the provided `isEquivalent` function, keeping the first occurrence of an element.
|
|
1911
|
+
*
|
|
1912
|
+
* @since 2.0.0
|
|
1913
|
+
*/
|
|
1914
|
+
export const dedupeWith: {
|
|
1915
|
+
<A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>
|
|
1916
|
+
<A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>
|
|
1917
|
+
} = dual(
|
|
1918
|
+
2,
|
|
1919
|
+
<A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {
|
|
1920
|
+
const input = fromIterable(self)
|
|
1921
|
+
return isNonEmptyReadonlyArray(input) ? dedupeNonEmptyWith(isEquivalent)(input) : []
|
|
1922
|
+
}
|
|
1923
|
+
)
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* Remove duplicates from am `Iterable`, keeping the first occurrence of an element.
|
|
1927
|
+
*
|
|
1928
|
+
* @since 2.0.0
|
|
1929
|
+
*/
|
|
1930
|
+
export const dedupe: <A>(self: Iterable<A>) => Array<A> = dedupeWith(Equal.equivalence())
|
|
1931
|
+
|
|
1932
|
+
/**
|
|
1933
|
+
* Deduplicates adjacent elements that are identical using the provided `isEquivalent` function.
|
|
1934
|
+
*
|
|
1935
|
+
* @since 2.0.0
|
|
1936
|
+
*/
|
|
1937
|
+
export const dedupeAdjacentWith: {
|
|
1938
|
+
<A>(isEquivalent: (self: A, that: A) => boolean): (self: Iterable<A>) => Array<A>
|
|
1939
|
+
<A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A>
|
|
1940
|
+
} = dual(2, <A>(self: Iterable<A>, isEquivalent: (self: A, that: A) => boolean): Array<A> => {
|
|
1941
|
+
const out: Array<A> = []
|
|
1942
|
+
let lastA: O.Option<A> = O.none()
|
|
1943
|
+
for (const a of self) {
|
|
1944
|
+
if (O.isNone(lastA) || !isEquivalent(a, lastA.value)) {
|
|
1945
|
+
out.push(a)
|
|
1946
|
+
lastA = O.some(a)
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
return out
|
|
1950
|
+
})
|
|
1951
|
+
|
|
1952
|
+
/**
|
|
1953
|
+
* Deduplicates adjacent elements that are identical.
|
|
1954
|
+
*
|
|
1955
|
+
* @since 2.0.0
|
|
1956
|
+
*/
|
|
1957
|
+
export const dedupeAdjacent: <A>(self: Iterable<A>) => Array<A> = dedupeAdjacentWith(Equal.equivalence())
|
|
1958
|
+
|
|
1959
|
+
/**
|
|
1960
|
+
* Joins the elements together with "sep" in the middle.
|
|
1961
|
+
*
|
|
1962
|
+
* @since 2.0.0
|
|
1963
|
+
* @category folding
|
|
1964
|
+
*/
|
|
1965
|
+
export const join: {
|
|
1966
|
+
(sep: string): (self: Iterable<string>) => string
|
|
1967
|
+
(self: Iterable<string>, sep: string): string
|
|
1968
|
+
} = dual(2, (self: Iterable<string>, sep: string): string => fromIterable(self).join(sep))
|
|
1969
|
+
|
|
1970
|
+
/**
|
|
1971
|
+
* Statefully maps over the chunk, producing new elements of type `B`.
|
|
1972
|
+
*
|
|
1973
|
+
* @since 2.0.0
|
|
1974
|
+
* @category folding
|
|
1975
|
+
*/
|
|
1976
|
+
export const mapAccum: {
|
|
1977
|
+
<S, A, B>(s: S, f: (s: S, a: A) => readonly [S, B]): (self: Iterable<A>) => [S, Array<B>]
|
|
1978
|
+
<S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A) => readonly [S, B]): [S, Array<B>]
|
|
1979
|
+
} = dual(3, <S, A, B>(self: Iterable<A>, s: S, f: (s: S, a: A) => [S, B]) => {
|
|
1980
|
+
let s1 = s
|
|
1981
|
+
const out: Array<B> = []
|
|
1982
|
+
for (const a of self) {
|
|
1983
|
+
const r = f(s1, a)
|
|
1984
|
+
s1 = r[0]
|
|
1985
|
+
out.push(r[1])
|
|
1986
|
+
}
|
|
1987
|
+
return [s1, out]
|
|
1988
|
+
})
|
|
1989
|
+
|
|
1990
|
+
/**
|
|
1991
|
+
* Zips this chunk crosswise with the specified chunk using the specified combiner.
|
|
1992
|
+
*
|
|
1993
|
+
* @since 2.0.0
|
|
1994
|
+
* @category elements
|
|
1995
|
+
*/
|
|
1996
|
+
export const cartesianWith: {
|
|
1997
|
+
<A, B, C>(that: ReadonlyArray<B>, f: (a: A, b: B) => C): (self: ReadonlyArray<A>) => Array<C>
|
|
1998
|
+
<A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C>
|
|
1999
|
+
} = dual(
|
|
2000
|
+
3,
|
|
2001
|
+
<A, B, C>(self: ReadonlyArray<A>, that: ReadonlyArray<B>, f: (a: A, b: B) => C): Array<C> =>
|
|
2002
|
+
flatMap(self, (a) => map(that, (b) => f(a, b)))
|
|
2003
|
+
)
|
|
2004
|
+
|
|
2005
|
+
/**
|
|
2006
|
+
* Zips this chunk crosswise with the specified chunk.
|
|
2007
|
+
*
|
|
2008
|
+
* @since 2.0.0
|
|
2009
|
+
* @category elements
|
|
2010
|
+
*/
|
|
2011
|
+
export const cartesian: {
|
|
2012
|
+
<B>(that: ReadonlyArray<B>): <A>(self: ReadonlyArray<A>) => Array<[A, B]>
|
|
2013
|
+
<A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]>
|
|
2014
|
+
} = dual(
|
|
2015
|
+
2,
|
|
2016
|
+
<A, B>(self: ReadonlyArray<A>, that: ReadonlyArray<B>): Array<[A, B]> => cartesianWith(self, that, (a, b) => [a, b])
|
|
2017
|
+
)
|