@clayroach/effect 3.19.14-source-capture.8 → 3.19.14-source-trace.2

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