effect 2.0.0-next.50 → 2.0.0-next.51

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 (318) hide show
  1. package/BigDecimal/dist/effect-BigDecimal.cjs.d.mts +2 -0
  2. package/BigDecimal/dist/effect-BigDecimal.cjs.d.mts.map +1 -0
  3. package/BigDecimal/dist/effect-BigDecimal.cjs.d.ts +2 -0
  4. package/BigDecimal/dist/effect-BigDecimal.cjs.d.ts.map +1 -0
  5. package/BigDecimal/dist/effect-BigDecimal.cjs.dev.js +914 -0
  6. package/BigDecimal/dist/effect-BigDecimal.cjs.js +7 -0
  7. package/BigDecimal/dist/effect-BigDecimal.cjs.mjs +38 -0
  8. package/BigDecimal/dist/effect-BigDecimal.cjs.prod.js +914 -0
  9. package/BigDecimal/dist/effect-BigDecimal.esm.js +869 -0
  10. package/BigDecimal/package.json +4 -0
  11. package/Cache/dist/effect-Cache.cjs.dev.js +21 -21
  12. package/Cache/dist/effect-Cache.cjs.prod.js +21 -21
  13. package/Cause/dist/effect-Cause.cjs.dev.js +4 -4
  14. package/Cause/dist/effect-Cause.cjs.prod.js +4 -4
  15. package/Channel/dist/effect-Channel.cjs.dev.js +33 -33
  16. package/Channel/dist/effect-Channel.cjs.prod.js +33 -33
  17. package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.dev.js +28 -28
  18. package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.prod.js +28 -28
  19. package/Chunk/dist/effect-Chunk.cjs.dev.js +2 -7
  20. package/Chunk/dist/effect-Chunk.cjs.mjs +0 -1
  21. package/Chunk/dist/effect-Chunk.cjs.prod.js +2 -7
  22. package/Chunk/dist/effect-Chunk.esm.js +3 -7
  23. package/Clock/dist/effect-Clock.cjs.dev.js +10 -10
  24. package/Clock/dist/effect-Clock.cjs.prod.js +10 -10
  25. package/Config/dist/effect-Config.cjs.dev.js +7 -7
  26. package/Config/dist/effect-Config.cjs.prod.js +7 -7
  27. package/ConfigError/dist/effect-ConfigError.cjs.dev.js +1 -1
  28. package/ConfigError/dist/effect-ConfigError.cjs.prod.js +1 -1
  29. package/ConfigProvider/dist/effect-ConfigProvider.cjs.dev.js +9 -9
  30. package/ConfigProvider/dist/effect-ConfigProvider.cjs.prod.js +9 -9
  31. package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.dev.js +2 -2
  32. package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.prod.js +2 -2
  33. package/ConfigSecret/dist/effect-ConfigSecret.cjs.dev.js +1 -1
  34. package/ConfigSecret/dist/effect-ConfigSecret.cjs.prod.js +1 -1
  35. package/Console/dist/effect-Console.cjs.dev.js +25 -25
  36. package/Console/dist/effect-Console.cjs.prod.js +25 -25
  37. package/Data/dist/effect-Data.cjs.dev.js +148 -58
  38. package/Data/dist/effect-Data.cjs.prod.js +148 -58
  39. package/Data/dist/effect-Data.esm.js +121 -31
  40. package/DefaultServices/dist/effect-DefaultServices.cjs.dev.js +10 -10
  41. package/DefaultServices/dist/effect-DefaultServices.cjs.prod.js +10 -10
  42. package/Deferred/dist/effect-Deferred.cjs.dev.js +4 -4
  43. package/Deferred/dist/effect-Deferred.cjs.prod.js +4 -4
  44. package/Differ/dist/effect-Differ.cjs.dev.js +1 -1
  45. package/Differ/dist/effect-Differ.cjs.prod.js +1 -1
  46. package/Effect/dist/effect-Effect.cjs.dev.js +27 -27
  47. package/Effect/dist/effect-Effect.cjs.prod.js +27 -27
  48. package/Exit/dist/effect-Exit.cjs.dev.js +4 -4
  49. package/Exit/dist/effect-Exit.cjs.prod.js +4 -4
  50. package/Fiber/dist/effect-Fiber.cjs.dev.js +22 -22
  51. package/Fiber/dist/effect-Fiber.cjs.prod.js +22 -22
  52. package/FiberId/dist/effect-FiberId.cjs.dev.js +2 -2
  53. package/FiberId/dist/effect-FiberId.cjs.prod.js +2 -2
  54. package/FiberRef/dist/effect-FiberRef.cjs.dev.js +22 -22
  55. package/FiberRef/dist/effect-FiberRef.cjs.prod.js +22 -22
  56. package/FiberRefs/dist/effect-FiberRefs.cjs.dev.js +5 -5
  57. package/FiberRefs/dist/effect-FiberRefs.cjs.prod.js +5 -5
  58. package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.dev.js +6 -6
  59. package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.prod.js +6 -6
  60. package/GroupBy/dist/effect-GroupBy.cjs.dev.js +34 -34
  61. package/GroupBy/dist/effect-GroupBy.cjs.prod.js +34 -34
  62. package/HashMap/dist/effect-HashMap.cjs.dev.js +1 -1
  63. package/HashMap/dist/effect-HashMap.cjs.prod.js +1 -1
  64. package/HashSet/dist/effect-HashSet.cjs.dev.js +1 -1
  65. package/HashSet/dist/effect-HashSet.cjs.prod.js +1 -1
  66. package/KeyedPool/dist/effect-KeyedPool.cjs.dev.js +22 -22
  67. package/KeyedPool/dist/effect-KeyedPool.cjs.prod.js +22 -22
  68. package/Layer/dist/effect-Layer.cjs.dev.js +28 -28
  69. package/Layer/dist/effect-Layer.cjs.prod.js +28 -28
  70. package/List/dist/effect-List.cjs.dev.js +4 -7
  71. package/List/dist/effect-List.cjs.mjs +0 -1
  72. package/List/dist/effect-List.cjs.prod.js +4 -7
  73. package/List/dist/effect-List.esm.js +5 -7
  74. package/LogLevel/dist/effect-LogLevel.cjs.dev.js +4 -4
  75. package/LogLevel/dist/effect-LogLevel.cjs.prod.js +4 -4
  76. package/Logger/dist/effect-Logger.cjs.dev.js +26 -26
  77. package/Logger/dist/effect-Logger.cjs.prod.js +26 -26
  78. package/Match/dist/effect-Match.cjs.dev.js +1 -1
  79. package/Match/dist/effect-Match.cjs.prod.js +1 -1
  80. package/Match/dist/effect-Match.esm.js +1 -1
  81. package/Metric/dist/effect-Metric.cjs.dev.js +20 -20
  82. package/Metric/dist/effect-Metric.cjs.prod.js +20 -20
  83. package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.dev.js +1 -1
  84. package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.prod.js +1 -1
  85. package/MetricHook/dist/effect-MetricHook.cjs.dev.js +2 -2
  86. package/MetricHook/dist/effect-MetricHook.cjs.prod.js +2 -2
  87. package/MetricKey/dist/effect-MetricKey.cjs.dev.js +2 -2
  88. package/MetricKey/dist/effect-MetricKey.cjs.prod.js +2 -2
  89. package/MetricPolling/dist/effect-MetricPolling.cjs.dev.js +22 -22
  90. package/MetricPolling/dist/effect-MetricPolling.cjs.prod.js +22 -22
  91. package/MetricRegistry/dist/effect-MetricRegistry.cjs.dev.js +3 -3
  92. package/MetricRegistry/dist/effect-MetricRegistry.cjs.prod.js +3 -3
  93. package/MutableHashMap/dist/effect-MutableHashMap.cjs.dev.js +1 -1
  94. package/MutableHashMap/dist/effect-MutableHashMap.cjs.prod.js +1 -1
  95. package/MutableHashSet/dist/effect-MutableHashSet.cjs.dev.js +1 -1
  96. package/MutableHashSet/dist/effect-MutableHashSet.cjs.prod.js +1 -1
  97. package/Pool/dist/effect-Pool.cjs.dev.js +22 -22
  98. package/Pool/dist/effect-Pool.cjs.prod.js +22 -22
  99. package/PubSub/dist/effect-PubSub.cjs.dev.js +21 -21
  100. package/PubSub/dist/effect-PubSub.cjs.prod.js +21 -21
  101. package/Queue/dist/effect-Queue.cjs.dev.js +21 -21
  102. package/Queue/dist/effect-Queue.cjs.prod.js +21 -21
  103. package/Random/dist/effect-Random.cjs.dev.js +10 -10
  104. package/Random/dist/effect-Random.cjs.prod.js +10 -10
  105. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.dev.js +1 -4
  106. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.mjs +0 -1
  107. package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.prod.js +1 -4
  108. package/ReadonlyArray/dist/effect-ReadonlyArray.esm.js +2 -4
  109. package/Ref/dist/effect-Ref.cjs.dev.js +5 -5
  110. package/Ref/dist/effect-Ref.cjs.prod.js +5 -5
  111. package/Reloadable/dist/effect-Reloadable.cjs.dev.js +26 -26
  112. package/Reloadable/dist/effect-Reloadable.cjs.prod.js +26 -26
  113. package/Request/dist/effect-Request.cjs.dev.js +21 -21
  114. package/Request/dist/effect-Request.cjs.prod.js +21 -21
  115. package/RequestBlock/dist/effect-RequestBlock.cjs.dev.js +28 -28
  116. package/RequestBlock/dist/effect-RequestBlock.cjs.prod.js +28 -28
  117. package/RequestResolver/dist/effect-RequestResolver.cjs.dev.js +28 -28
  118. package/RequestResolver/dist/effect-RequestResolver.cjs.prod.js +28 -28
  119. package/Resource/dist/effect-Resource.cjs.dev.js +24 -24
  120. package/Resource/dist/effect-Resource.cjs.prod.js +24 -24
  121. package/Runtime/dist/effect-Runtime.cjs.dev.js +23 -23
  122. package/Runtime/dist/effect-Runtime.cjs.prod.js +23 -23
  123. package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.dev.js +26 -26
  124. package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.prod.js +26 -26
  125. package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.dev.js +2 -2
  126. package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.prod.js +2 -2
  127. package/STM/dist/effect-STM.cjs.dev.js +36 -36
  128. package/STM/dist/effect-STM.cjs.prod.js +36 -36
  129. package/Schedule/dist/effect-Schedule.cjs.dev.js +15 -15
  130. package/Schedule/dist/effect-Schedule.cjs.prod.js +15 -15
  131. package/Scheduler/dist/effect-Scheduler.cjs.dev.js +4 -4
  132. package/Scheduler/dist/effect-Scheduler.cjs.prod.js +4 -4
  133. package/Scope/dist/effect-Scope.cjs.dev.js +20 -20
  134. package/Scope/dist/effect-Scope.cjs.prod.js +20 -20
  135. package/ScopedCache/dist/effect-ScopedCache.cjs.dev.js +27 -27
  136. package/ScopedCache/dist/effect-ScopedCache.cjs.prod.js +27 -27
  137. package/ScopedRef/dist/effect-ScopedRef.cjs.dev.js +24 -24
  138. package/ScopedRef/dist/effect-ScopedRef.cjs.prod.js +24 -24
  139. package/Sink/dist/effect-Sink.cjs.dev.js +31 -31
  140. package/Sink/dist/effect-Sink.cjs.prod.js +31 -31
  141. package/Stream/dist/effect-Stream.cjs.dev.js +34 -34
  142. package/Stream/dist/effect-Stream.cjs.prod.js +34 -34
  143. package/Streamable/dist/effect-Streamable.cjs.dev.js +34 -34
  144. package/Streamable/dist/effect-Streamable.cjs.prod.js +34 -34
  145. package/Struct/dist/effect-Struct.cjs.dev.js +0 -1
  146. package/Struct/dist/effect-Struct.cjs.prod.js +0 -1
  147. package/Struct/dist/effect-Struct.esm.js +0 -1
  148. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.dev.js +33 -33
  149. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.prod.js +33 -33
  150. package/Supervisor/dist/effect-Supervisor.cjs.dev.js +26 -26
  151. package/Supervisor/dist/effect-Supervisor.cjs.prod.js +26 -26
  152. package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.dev.js +23 -23
  153. package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.prod.js +23 -23
  154. package/TArray/dist/effect-TArray.cjs.dev.js +38 -38
  155. package/TArray/dist/effect-TArray.cjs.prod.js +38 -38
  156. package/TDeferred/dist/effect-TDeferred.cjs.dev.js +37 -37
  157. package/TDeferred/dist/effect-TDeferred.cjs.prod.js +37 -37
  158. package/TMap/dist/effect-TMap.cjs.dev.js +39 -39
  159. package/TMap/dist/effect-TMap.cjs.prod.js +39 -39
  160. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.dev.js +36 -36
  161. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.prod.js +36 -36
  162. package/TPubSub/dist/effect-TPubSub.cjs.dev.js +38 -38
  163. package/TPubSub/dist/effect-TPubSub.cjs.prod.js +38 -38
  164. package/TQueue/dist/effect-TQueue.cjs.dev.js +38 -38
  165. package/TQueue/dist/effect-TQueue.cjs.prod.js +38 -38
  166. package/TRandom/dist/effect-TRandom.cjs.dev.js +38 -38
  167. package/TRandom/dist/effect-TRandom.cjs.prod.js +38 -38
  168. package/TReentrantLock/dist/effect-TReentrantLock.cjs.dev.js +36 -36
  169. package/TReentrantLock/dist/effect-TReentrantLock.cjs.prod.js +36 -36
  170. package/TRef/dist/effect-TRef.cjs.dev.js +36 -36
  171. package/TRef/dist/effect-TRef.cjs.prod.js +36 -36
  172. package/TSemaphore/dist/effect-TSemaphore.cjs.dev.js +37 -37
  173. package/TSemaphore/dist/effect-TSemaphore.cjs.prod.js +37 -37
  174. package/TSet/dist/effect-TSet.cjs.dev.js +39 -39
  175. package/TSet/dist/effect-TSet.cjs.prod.js +39 -39
  176. package/Take/dist/effect-Take.cjs.dev.js +28 -28
  177. package/Take/dist/effect-Take.cjs.prod.js +28 -28
  178. package/TestAnnotation/dist/effect-TestAnnotation.cjs.dev.js +1 -1
  179. package/TestAnnotation/dist/effect-TestAnnotation.cjs.prod.js +1 -1
  180. package/TestAnnotations/dist/effect-TestAnnotations.cjs.dev.js +15 -15
  181. package/TestAnnotations/dist/effect-TestAnnotations.cjs.prod.js +15 -15
  182. package/TestClock/dist/effect-TestClock.cjs.dev.js +25 -25
  183. package/TestClock/dist/effect-TestClock.cjs.prod.js +25 -25
  184. package/TestContext/dist/effect-TestContext.cjs.dev.js +27 -27
  185. package/TestContext/dist/effect-TestContext.cjs.prod.js +27 -27
  186. package/TestLive/dist/effect-TestLive.cjs.dev.js +10 -10
  187. package/TestLive/dist/effect-TestLive.cjs.prod.js +10 -10
  188. package/TestServices/dist/effect-TestServices.cjs.dev.js +27 -27
  189. package/TestServices/dist/effect-TestServices.cjs.prod.js +27 -27
  190. package/TestSized/dist/effect-TestSized.cjs.dev.js +4 -4
  191. package/TestSized/dist/effect-TestSized.cjs.prod.js +4 -4
  192. package/Tracer/dist/effect-Tracer.cjs.dev.js +10 -10
  193. package/Tracer/dist/effect-Tracer.cjs.prod.js +10 -10
  194. package/dist/{HashSet-251c8294.cjs.prod.js → HashSet-09ade044.cjs.prod.js} +1 -1
  195. package/dist/{HashSet-c12c037b.cjs.dev.js → HashSet-e9659fd4.cjs.dev.js} +1 -1
  196. package/dist/{Ref-00103de4.cjs.prod.js → Ref-50f14c13.cjs.prod.js} +1 -1
  197. package/dist/{Ref-f990026b.cjs.dev.js → Ref-d3a3826b.cjs.dev.js} +1 -1
  198. package/dist/{cache-d709d5cb.cjs.dev.js → cache-2a5d8381.cjs.dev.js} +4 -4
  199. package/dist/{cache-0b148e42.cjs.prod.js → cache-8f0c08cb.cjs.prod.js} +4 -4
  200. package/dist/{circular-6d2bb353.cjs.dev.js → circular-2effda94.cjs.dev.js} +4 -4
  201. package/dist/{circular-aa705e70.cjs.dev.js → circular-39e86dc8.cjs.dev.js} +7 -7
  202. package/dist/{circular-5b6f6504.cjs.prod.js → circular-4f03acf3.cjs.prod.js} +4 -4
  203. package/dist/{circular-952618e5.cjs.prod.js → circular-acb40239.cjs.prod.js} +7 -7
  204. package/dist/{config-f0bd27af.cjs.prod.js → config-00e6170c.cjs.prod.js} +3 -3
  205. package/dist/{config-8a7bf1ae.cjs.dev.js → config-beaa306c.cjs.dev.js} +3 -3
  206. package/dist/{configProvider-ae007b10.cjs.prod.js → configProvider-290d13e7.cjs.prod.js} +4 -4
  207. package/dist/{configProvider-3d85d4ef.cjs.dev.js → configProvider-aef50f41.cjs.dev.js} +4 -4
  208. package/dist/{core-d3f4e713.cjs.prod.js → core-279496f0.cjs.prod.js} +2 -2
  209. package/dist/{core-473934ce.cjs.prod.js → core-35439f06.cjs.prod.js} +2 -2
  210. package/dist/{core-dd1edd7a.cjs.dev.js → core-7445bfd4.cjs.dev.js} +2 -2
  211. package/dist/{core-b4bf44d3.cjs.dev.js → core-a0828fef.cjs.dev.js} +2 -2
  212. package/dist/{core-effect-f4b1aad8.cjs.dev.js → core-effect-02a7f1d7.cjs.dev.js} +6 -6
  213. package/dist/{core-effect-6666f2dc.cjs.prod.js → core-effect-460f968a.cjs.prod.js} +6 -6
  214. package/dist/{dataSource-d5d7f338.cjs.prod.js → dataSource-94fb44f9.cjs.prod.js} +2 -2
  215. package/dist/{dataSource-9f78e828.cjs.dev.js → dataSource-da4a602c.cjs.dev.js} +2 -2
  216. package/dist/declarations/src/BigDecimal.d.ts +622 -0
  217. package/dist/declarations/src/BigDecimal.d.ts.map +1 -0
  218. package/dist/declarations/src/Chunk.d.ts +14 -11
  219. package/dist/declarations/src/Chunk.d.ts.map +1 -1
  220. package/dist/declarations/src/Data.d.ts +192 -45
  221. package/dist/declarations/src/Data.d.ts.map +1 -1
  222. package/dist/declarations/src/List.d.ts +15 -10
  223. package/dist/declarations/src/List.d.ts.map +1 -1
  224. package/dist/declarations/src/Match.d.ts.map +1 -1
  225. package/dist/declarations/src/ReadonlyArray.d.ts +13 -8
  226. package/dist/declarations/src/ReadonlyArray.d.ts.map +1 -1
  227. package/dist/declarations/src/Struct.d.ts +3 -2
  228. package/dist/declarations/src/Struct.d.ts.map +1 -1
  229. package/dist/declarations/src/index.d.ts +16 -0
  230. package/dist/declarations/src/index.d.ts.map +1 -1
  231. package/dist/{defaultServices-8ea5e664.cjs.prod.js → defaultServices-61911fd4.cjs.prod.js} +2 -2
  232. package/dist/{defaultServices-6a9a2d2b.cjs.dev.js → defaultServices-f3f93337.cjs.dev.js} +2 -2
  233. package/dist/effect.cjs.dev.js +3 -0
  234. package/dist/effect.cjs.mjs +1 -0
  235. package/dist/effect.cjs.prod.js +3 -0
  236. package/dist/effect.esm.js +2 -0
  237. package/dist/{fiber-3d944398.cjs.dev.js → fiber-cac583ce.cjs.dev.js} +3 -3
  238. package/dist/{fiber-cbd0613f.cjs.prod.js → fiber-f67dca7d.cjs.prod.js} +3 -3
  239. package/dist/{fiberRefs-99808a27.cjs.prod.js → fiberRefs-59b59378.cjs.prod.js} +1 -1
  240. package/dist/{fiberRefs-ccc37f30.cjs.dev.js → fiberRefs-6bd9745e.cjs.dev.js} +1 -1
  241. package/dist/{fiberRuntime-f1e80ca7.cjs.prod.js → fiberRuntime-26f406c3.cjs.prod.js} +27 -23
  242. package/dist/{fiberRuntime-0c1e7478.cjs.dev.js → fiberRuntime-976a3e6f.cjs.dev.js} +27 -23
  243. package/dist/{groupBy-8ae74e3b.cjs.dev.js → groupBy-7fc93bc9.cjs.dev.js} +4 -4
  244. package/dist/{groupBy-30f6e9ba.cjs.prod.js → groupBy-8977b420.cjs.prod.js} +4 -4
  245. package/dist/{layer-bfb9802a.cjs.prod.js → layer-abbc91aa.cjs.prod.js} +8 -8
  246. package/dist/{layer-c284cf0d.cjs.dev.js → layer-c197624f.cjs.dev.js} +8 -8
  247. package/dist/{patch-cda9b6c8.cjs.dev.js → patch-2d425849.cjs.dev.js} +1 -1
  248. package/dist/{patch-256bc574.cjs.prod.js → patch-b7689042.cjs.prod.js} +1 -1
  249. package/dist/{pathPatch-31ce8101.cjs.dev.js → pathPatch-18fa425e.cjs.dev.js} +1 -1
  250. package/dist/{pathPatch-40b92af6.cjs.prod.js → pathPatch-b6020485.cjs.prod.js} +1 -1
  251. package/dist/{pool-f6ca2038.cjs.dev.js → pool-810c2214.cjs.dev.js} +5 -5
  252. package/dist/{pool-122f0fad.cjs.prod.js → pool-868dfa39.cjs.prod.js} +5 -5
  253. package/dist/{query-5cc0ddf8.cjs.prod.js → query-927b504e.cjs.prod.js} +5 -5
  254. package/dist/{query-7bffa3c3.cjs.dev.js → query-c6684e39.cjs.dev.js} +5 -5
  255. package/dist/{queue-e326fd89.cjs.prod.js → queue-062806c7.cjs.prod.js} +2 -2
  256. package/dist/{queue-4166cfdb.cjs.dev.js → queue-a0fc274d.cjs.dev.js} +2 -2
  257. package/dist/{registry-081e18a3.cjs.prod.js → registry-9268ec7c.cjs.prod.js} +1 -1
  258. package/dist/{registry-377855a9.cjs.dev.js → registry-e5ad2d74.cjs.dev.js} +1 -1
  259. package/dist/{runtime-d4514ab5.cjs.dev.js → runtime-340bd70b.cjs.dev.js} +5 -5
  260. package/dist/{runtime-4078f059.cjs.prod.js → runtime-ce0ad0ed.cjs.prod.js} +5 -5
  261. package/dist/{schedule-f036b254.cjs.prod.js → schedule-04b40c50.cjs.prod.js} +3 -3
  262. package/dist/{schedule-31e38871.cjs.dev.js → schedule-74c6207a.cjs.dev.js} +3 -3
  263. package/dist/{scopedRef-5ecf6468.cjs.dev.js → scopedRef-4f0dd122.cjs.dev.js} +6 -6
  264. package/dist/{scopedRef-8ce21228.cjs.prod.js → scopedRef-d429ec83.cjs.prod.js} +6 -6
  265. package/dist/{singleProducerAsyncInput-8879d87c.cjs.prod.js → singleProducerAsyncInput-06a9076a.cjs.prod.js} +1 -1
  266. package/dist/{singleProducerAsyncInput-ece7387b.cjs.dev.js → singleProducerAsyncInput-72c05452.cjs.dev.js} +1 -1
  267. package/dist/{sink-1794329b.cjs.dev.js → sink-301d2bb4.cjs.dev.js} +3 -3
  268. package/dist/{sink-9208df8d.cjs.prod.js → sink-46df55d3.cjs.prod.js} +3 -3
  269. package/dist/{stm-b080be31.cjs.dev.js → stm-0b50e3c1.cjs.dev.js} +3 -3
  270. package/dist/{stm-6ad7b384.cjs.prod.js → stm-c0489b43.cjs.prod.js} +3 -3
  271. package/dist/{stream-e19805ca.cjs.prod.js → stream-0c3160ef.cjs.prod.js} +4 -4
  272. package/dist/{stream-09aeeac3.cjs.dev.js → stream-44cdd7cb.cjs.dev.js} +4 -4
  273. package/dist/{synchronizedRef-cc04ecbd.cjs.prod.js → synchronizedRef-2f71b820.cjs.prod.js} +1 -1
  274. package/dist/{synchronizedRef-8fa16866.cjs.dev.js → synchronizedRef-78797507.cjs.dev.js} +1 -1
  275. package/dist/{tArray-5e42c290.cjs.prod.js → tArray-006f45b0.cjs.prod.js} +3 -3
  276. package/dist/{tArray-7d470ed7.cjs.dev.js → tArray-556355cd.cjs.dev.js} +3 -3
  277. package/dist/{tMap-f0df0ea0.cjs.dev.js → tMap-52d00ffb.cjs.dev.js} +4 -4
  278. package/dist/{tMap-a2cfde88.cjs.prod.js → tMap-9680b82b.cjs.prod.js} +4 -4
  279. package/dist/{tQueue-b80e940e.cjs.prod.js → tQueue-51cf109e.cjs.prod.js} +3 -3
  280. package/dist/{tQueue-085f70b5.cjs.dev.js → tQueue-ca56a2a8.cjs.dev.js} +3 -3
  281. package/dist/{tRef-42a212cb.cjs.prod.js → tRef-4a2a9689.cjs.prod.js} +1 -1
  282. package/dist/{tRef-2e495254.cjs.dev.js → tRef-b98e2e2a.cjs.dev.js} +1 -1
  283. package/internal/HashMap/node.esm.js +1 -1
  284. package/internal/fiberRuntime.esm.js +9 -8
  285. package/internal/query.esm.js +2 -2
  286. package/internal/supervisor/patch.esm.js +3 -3
  287. package/internal/supervisor.esm.js +5 -1
  288. package/package.json +10 -5
  289. package/src/BigDecimal.ts +977 -0
  290. package/src/Chunk.ts +17 -13
  291. package/src/Data.ts +219 -92
  292. package/src/List.ts +17 -11
  293. package/src/Match.ts +2 -2
  294. package/src/ReadonlyArray.ts +18 -9
  295. package/src/Struct.ts +3 -2
  296. package/src/index.ts +17 -0
  297. package/src/internal/HashMap/node.ts +1 -1
  298. package/src/internal/fiberRuntime.ts +56 -45
  299. package/src/internal/query.ts +12 -8
  300. package/src/internal/supervisor/patch.ts +2 -2
  301. package/src/internal/supervisor.ts +5 -0
  302. package/src/tsconfig.json +0 -1
  303. /package/dist/{FiberId-0f0b7779.cjs.prod.js → FiberId-88cc0067.cjs.prod.js} +0 -0
  304. /package/dist/{FiberId-6595cf4c.cjs.dev.js → FiberId-f329d0e3.cjs.dev.js} +0 -0
  305. /package/dist/{RuntimeFlagsPatch-7d62915d.cjs.dev.js → RuntimeFlagsPatch-063c5864.cjs.dev.js} +0 -0
  306. /package/dist/{RuntimeFlagsPatch-3890e860.cjs.prod.js → RuntimeFlagsPatch-233ac7d7.cjs.prod.js} +0 -0
  307. /package/dist/{boundaries-ebe66d32.cjs.prod.js → boundaries-0e5ddf7b.cjs.prod.js} +0 -0
  308. /package/dist/{boundaries-8dfe50cb.cjs.dev.js → boundaries-ce70e4e4.cjs.dev.js} +0 -0
  309. /package/dist/{configError-9021016b.cjs.prod.js → configError-72f57cd6.cjs.prod.js} +0 -0
  310. /package/dist/{configError-0c09b93c.cjs.dev.js → configError-834bedc1.cjs.dev.js} +0 -0
  311. /package/dist/{configSecret-0bdfadd8.cjs.prod.js → configSecret-80d3e36b.cjs.prod.js} +0 -0
  312. /package/dist/{configSecret-938818ad.cjs.dev.js → configSecret-abf643d8.cjs.dev.js} +0 -0
  313. /package/dist/{hook-ad5af092.cjs.dev.js → hook-13f4db1e.cjs.dev.js} +0 -0
  314. /package/dist/{hook-cab99f9e.cjs.prod.js → hook-8a020c3f.cjs.prod.js} +0 -0
  315. /package/dist/{key-9c7368c8.cjs.prod.js → key-2cf383a2.cjs.prod.js} +0 -0
  316. /package/dist/{key-e3189bbd.cjs.dev.js → key-4b5f6a7d.cjs.dev.js} +0 -0
  317. /package/dist/{take-114476e5.cjs.prod.js → take-07165139.cjs.prod.js} +0 -0
  318. /package/dist/{take-d4fa1beb.cjs.dev.js → take-689a29d5.cjs.dev.js} +0 -0
@@ -0,0 +1,977 @@
1
+ /**
2
+ * This module provides utility functions and type class instances for working with the `BigDecimal` type in TypeScript.
3
+ * It includes functions for basic arithmetic operations, as well as type class instances for `Equivalence` and `Order`.
4
+ *
5
+ * A `BigDecimal` allows storing any real number to arbitrary precision; which avoids common floating point errors
6
+ * (such as 0.1 + 0.2 ≠ 0.3) at the cost of complexity.
7
+ *
8
+ * Internally, `BigDecimal` uses a `BigInt` object, paired with a 64-bit integer which determines the position of the
9
+ * decimal point. Therefore, the precision *is not* actually arbitrary, but limited to 2<sup>63</sup> decimal places.
10
+ *
11
+ * It is not recommended to convert a floating point number to a decimal directly, as the floating point representation
12
+ * may be unexpected.
13
+ *
14
+ * @since 2.0.0
15
+ */
16
+
17
+ import * as Equal from "./Equal"
18
+ import * as equivalence from "./Equivalence"
19
+ import { dual, pipe } from "./Function"
20
+ import * as Hash from "./Hash"
21
+ import { type Inspectable, NodeInspectSymbol } from "./Inspectable"
22
+ import * as Option from "./Option"
23
+ import * as order from "./Order"
24
+ import type { Ordering } from "./Ordering"
25
+ import { type Pipeable, pipeArguments } from "./Pipeable"
26
+
27
+ const DEFAULT_PRECISION = 100
28
+
29
+ /**
30
+ * @since 2.0.0
31
+ * @category symbols
32
+ */
33
+ export const TypeId: unique symbol = Symbol.for("effect/BigDecimal")
34
+
35
+ /**
36
+ * @since 2.0.0
37
+ * @category symbol
38
+ */
39
+ export type TypeId = typeof TypeId
40
+
41
+ /**
42
+ * @since 2.0.0
43
+ * @category models
44
+ */
45
+ export interface BigDecimal extends Equal.Equal, Pipeable, Inspectable {
46
+ readonly [TypeId]: TypeId
47
+ readonly value: bigint
48
+ readonly scale: number
49
+ /** @internal */
50
+ normalized?: BigDecimal
51
+ }
52
+
53
+ const BigDecimalProto: Omit<BigDecimal, "value" | "scale" | "normalized"> = {
54
+ [TypeId]: TypeId,
55
+ [Hash.symbol](this: BigDecimal): number {
56
+ const normalized = normalize(this)
57
+ return pipe(
58
+ Hash.hash(normalized.value),
59
+ Hash.combine(Hash.number(normalized.scale))
60
+ )
61
+ },
62
+ [Equal.symbol](this: BigDecimal, that: unknown): boolean {
63
+ return isBigDecimal(that) && equals(this, that)
64
+ },
65
+ toString(this: BigDecimal) {
66
+ return toString(this)
67
+ },
68
+ toJSON(this: BigDecimal) {
69
+ return toString(this)
70
+ },
71
+ [NodeInspectSymbol](this: BigDecimal) {
72
+ return toString(this)
73
+ },
74
+ pipe() {
75
+ return pipeArguments(this, arguments)
76
+ }
77
+ } as const
78
+
79
+ /**
80
+ * Checks if a given value is a `BigDecimal`.
81
+ *
82
+ * @param u - The value to check.
83
+ *
84
+ * @since 2.0.0
85
+ * @category guards
86
+ */
87
+ export const isBigDecimal = (u: unknown): u is BigDecimal => typeof u === "object" && u !== null && TypeId in u
88
+
89
+ /**
90
+ * Creates a `BigDecimal` from a `bigint` value and a scale.
91
+ *
92
+ * @param value - The `bigint` value to create a `BigDecimal` from.
93
+ * @param scale - The scale of the `BigDecimal`.
94
+ *
95
+ * @since 2.0.0
96
+ * @category constructors
97
+ */
98
+ export const make = (value: bigint, scale: number): BigDecimal => {
99
+ const o = Object.create(BigDecimalProto)
100
+ o.value = value
101
+ o.scale = scale
102
+ return o
103
+ }
104
+
105
+ const bigint0 = BigInt(0)
106
+ const bigint1 = BigInt(1)
107
+ const bigint10 = BigInt(10)
108
+ const zero = make(bigint0, 0)
109
+
110
+ /**
111
+ * Normalizes a given `BigDecimal` by removing trailing zeros.
112
+ *
113
+ * @param self - The `BigDecimal` to normalize.
114
+ *
115
+ * @example
116
+ * import { normalize, make, unsafeFromString } from "effect/BigDecimal"
117
+ *
118
+ * assert.deepStrictEqual(normalize(unsafeFromString("123.00000")), make(123n, 0))
119
+ * assert.deepStrictEqual(normalize(unsafeFromString("12300000")), make(123n, -5))
120
+ *
121
+ * @since 2.0.0
122
+ * @category scaling
123
+ */
124
+ export const normalize = (self: BigDecimal): BigDecimal => {
125
+ if (self.normalized === undefined) {
126
+ if (self.value === bigint0) {
127
+ self.normalized = zero
128
+ } else {
129
+ const digits = `${self.value}`
130
+
131
+ let trail = 0
132
+ for (let i = digits.length - 1; i >= 0; i--) {
133
+ if (digits[i] === "0") {
134
+ trail++
135
+ } else {
136
+ break
137
+ }
138
+ }
139
+
140
+ if (trail === 0) {
141
+ self.normalized = self
142
+ }
143
+
144
+ const value = BigInt(digits.substring(0, digits.length - trail))
145
+ const scale = self.scale - trail
146
+ self.normalized = make(value, scale)
147
+ }
148
+ }
149
+
150
+ return self.normalized
151
+ }
152
+
153
+ /**
154
+ * Scales a given `BigDecimal` to the specified scale.
155
+ *
156
+ * If the given scale is smaller than the current scale, the value will be rounded down to
157
+ * the nearest integer.
158
+ *
159
+ * @param self - The `BigDecimal` to scale.
160
+ * @param scale - The scale to scale to.
161
+ *
162
+ * @since 2.0.0
163
+ * @category scaling
164
+ */
165
+ export const scale = (self: BigDecimal, scale: number): BigDecimal => {
166
+ if (scale > self.scale) {
167
+ return make(self.value * bigint10 ** BigInt(scale - self.scale), scale)
168
+ }
169
+
170
+ if (scale < self.scale) {
171
+ return make(self.value / bigint10 ** BigInt(self.scale - scale), scale)
172
+ }
173
+
174
+ return self
175
+ }
176
+
177
+ /**
178
+ * Provides an addition operation on `BigDecimal`s.
179
+ *
180
+ * @param self - The first operand.
181
+ * @param that - The second operand.
182
+ *
183
+ * @example
184
+ * import { sum, unsafeFromString } from "effect/BigDecimal"
185
+ *
186
+ * assert.deepStrictEqual(sum(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("5"))
187
+ *
188
+ * @since 2.0.0
189
+ * @category math
190
+ */
191
+ export const sum: {
192
+ (that: BigDecimal): (self: BigDecimal) => BigDecimal
193
+ (self: BigDecimal, that: BigDecimal): BigDecimal
194
+ } = dual(2, (self: BigDecimal, that: BigDecimal): BigDecimal => {
195
+ if (that.value === bigint0) {
196
+ return self
197
+ }
198
+
199
+ if (self.value === bigint0) {
200
+ return that
201
+ }
202
+
203
+ if (self.scale > that.scale) {
204
+ return make(scale(that, self.scale).value + self.value, self.scale)
205
+ }
206
+
207
+ if (self.scale < that.scale) {
208
+ return make(scale(self, that.scale).value + that.value, that.scale)
209
+ }
210
+
211
+ return make(self.value + that.value, self.scale)
212
+ })
213
+
214
+ /**
215
+ * Provides a multiplication operation on `BigDecimal`s.
216
+ *
217
+ * @param self - The first operand.
218
+ * @param that - The second operand.
219
+ *
220
+ * @example
221
+ * import { multiply, unsafeFromString } from "effect/BigDecimal"
222
+ *
223
+ * assert.deepStrictEqual(multiply(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("6"))
224
+ *
225
+ * @since 2.0.0
226
+ * @category math
227
+ */
228
+ export const multiply: {
229
+ (that: BigDecimal): (self: BigDecimal) => BigDecimal
230
+ (self: BigDecimal, that: BigDecimal): BigDecimal
231
+ } = dual(2, (self: BigDecimal, that: BigDecimal): BigDecimal => {
232
+ if (that.value === bigint0 || self.value === bigint0) {
233
+ return zero
234
+ }
235
+
236
+ return make(self.value * that.value, self.scale + that.scale)
237
+ })
238
+
239
+ /**
240
+ * Provides a subtraction operation on `BigDecimal`s.
241
+ *
242
+ * @param self - The first operand.
243
+ * @param that - The second operand.
244
+ *
245
+ * @example
246
+ * import { subtract, unsafeFromString } from "effect/BigDecimal"
247
+ *
248
+ * assert.deepStrictEqual(subtract(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("-1"))
249
+ *
250
+ * @since 2.0.0
251
+ * @category math
252
+ */
253
+ export const subtract: {
254
+ (that: BigDecimal): (self: BigDecimal) => BigDecimal
255
+ (self: BigDecimal, that: BigDecimal): BigDecimal
256
+ } = dual(2, (self: BigDecimal, that: BigDecimal): BigDecimal => {
257
+ if (that.value === bigint0) {
258
+ return self
259
+ }
260
+
261
+ if (self.value === bigint0) {
262
+ return make(-that.value, that.scale)
263
+ }
264
+
265
+ if (self.scale > that.scale) {
266
+ return make(self.value - scale(that, self.scale).value, self.scale)
267
+ }
268
+
269
+ if (self.scale < that.scale) {
270
+ return make(scale(self, that.scale).value - that.value, that.scale)
271
+ }
272
+
273
+ return make(self.value - that.value, self.scale)
274
+ })
275
+
276
+ /**
277
+ * Internal function used for arbitrary precision division.
278
+ */
279
+ const divideWithPrecision = (
280
+ num: bigint,
281
+ den: bigint,
282
+ scale: number,
283
+ precision: number
284
+ ): BigDecimal => {
285
+ if (num === bigint0) {
286
+ return zero
287
+ }
288
+
289
+ const numNegative = num < bigint0
290
+ const denNegative = den < bigint0
291
+ const negateResult = numNegative !== denNegative
292
+
293
+ num = numNegative ? -num : num
294
+ den = denNegative ? -den : den
295
+
296
+ // Shift digits until numerator is larger than denominator (set scale appropriately).
297
+ while (num < den) {
298
+ num *= bigint10
299
+ scale++
300
+ }
301
+
302
+ // First division.
303
+ let quotient = num / den
304
+ let remainder = num % den
305
+
306
+ if (remainder === bigint0) {
307
+ // No remainder, return immediately.
308
+ return make(negateResult ? -quotient : quotient, scale)
309
+ }
310
+
311
+ // The quotient is guaranteed to be non-negative at this point. No need to consider sign.
312
+ let count = `${quotient}`.length
313
+
314
+ // Shift the remainder by 1 decimal; The quotient will be 1 digit upon next division.
315
+ remainder *= bigint10
316
+ while (remainder !== bigint0 && count < precision) {
317
+ const q = remainder / den
318
+ const r = remainder % den
319
+ quotient = quotient * bigint10 + q
320
+ remainder = r * bigint10
321
+
322
+ count++
323
+ scale++
324
+ }
325
+
326
+ if (remainder !== bigint0) {
327
+ // Round final number with remainder.
328
+ quotient += roundTerminal(remainder / den)
329
+ }
330
+
331
+ return make(negateResult ? -quotient : quotient, scale)
332
+ }
333
+
334
+ /**
335
+ * Internal function used for rounding.
336
+ *
337
+ * Returns 1 if the most significant digit is >= 5, otherwise 0.
338
+ *
339
+ * This is used after dividing a number by a power of ten and rounding the last digit.
340
+ */
341
+ const roundTerminal = (n: bigint): bigint => {
342
+ if (n === bigint0) {
343
+ return bigint0
344
+ }
345
+
346
+ const pos = n > bigint0 ? 0 : 1
347
+ return Number(`${n}`[pos]) < 5 ? bigint0 : bigint1
348
+ }
349
+
350
+ /**
351
+ * Provides a division operation on `BigDecimal`s.
352
+ *
353
+ * If the dividend is not a multiple of the divisor the result will be a `BigDecimal` value
354
+ * which represents the integer division rounded down to the nearest integer.
355
+ *
356
+ * If the divisor is `0`, the result will be `None`.
357
+ *
358
+ * @param self - The dividend operand.
359
+ * @param that - The divisor operand.
360
+ *
361
+ * @example
362
+ * import { divide, unsafeFromString } from "effect/BigDecimal"
363
+ * import { some, none } from "effect/Option"
364
+ *
365
+ * assert.deepStrictEqual(divide(unsafeFromString("6"), unsafeFromString("3")), some(unsafeFromString("2")))
366
+ * assert.deepStrictEqual(divide(unsafeFromString("6"), unsafeFromString("4")), some(unsafeFromString("1.5")))
367
+ * assert.deepStrictEqual(divide(unsafeFromString("6"), unsafeFromString("0")), none())
368
+ *
369
+ * @since 2.0.0
370
+ * @category math
371
+ */
372
+ export const divide: {
373
+ (that: BigDecimal): (self: BigDecimal) => Option.Option<BigDecimal>
374
+ (self: BigDecimal, that: BigDecimal): Option.Option<BigDecimal>
375
+ } = dual(2, (self: BigDecimal, that: BigDecimal): Option.Option<BigDecimal> => {
376
+ if (that.value === bigint0) {
377
+ return Option.none()
378
+ }
379
+
380
+ if (self.value === bigint0) {
381
+ return Option.some(zero)
382
+ }
383
+
384
+ const scale = self.scale - that.scale
385
+ if (self.value === that.value) {
386
+ return Option.some(make(bigint1, scale))
387
+ }
388
+
389
+ return Option.some(divideWithPrecision(self.value, that.value, scale, DEFAULT_PRECISION))
390
+ })
391
+
392
+ /**
393
+ * Provides an unsafe division operation on `BigDecimal`s.
394
+ *
395
+ * If the dividend is not a multiple of the divisor the result will be a `BigDecimal` value
396
+ * which represents the integer division rounded down to the nearest integer.
397
+ *
398
+ * Throws a `RangeError` if the divisor is `0`.
399
+ *
400
+ * @param self - The dividend operand.
401
+ * @param that - The divisor operand.as
402
+ *
403
+ * @example
404
+ * import { unsafeDivide, unsafeFromString } from "effect/BigDecimal"
405
+ *
406
+ * assert.deepStrictEqual(unsafeDivide(unsafeFromString("6"), unsafeFromString("3")), unsafeFromString("2"))
407
+ * assert.deepStrictEqual(unsafeDivide(unsafeFromString("6"), unsafeFromString("4")), unsafeFromString("1.5"))
408
+ *
409
+ * @since 2.0.0
410
+ * @category math
411
+ */
412
+ export const unsafeDivide: {
413
+ (that: BigDecimal): (self: BigDecimal) => BigDecimal
414
+ (self: BigDecimal, that: BigDecimal): BigDecimal
415
+ } = dual(2, (self: BigDecimal, that: BigDecimal): BigDecimal => {
416
+ if (that.value === bigint0) {
417
+ throw new RangeError("Division by zero")
418
+ }
419
+
420
+ if (self.value === bigint0) {
421
+ return zero
422
+ }
423
+
424
+ const scale = self.scale - that.scale
425
+ if (self.value === that.value) {
426
+ return make(bigint1, scale)
427
+ }
428
+
429
+ return divideWithPrecision(self.value, that.value, scale, DEFAULT_PRECISION)
430
+ })
431
+
432
+ /**
433
+ * @since 2.0.0
434
+ * @category instances
435
+ */
436
+ export const Order: order.Order<BigDecimal> = order.make((self, that) => {
437
+ const scmp = order.number(sign(self), sign(that))
438
+ if (scmp !== 0) {
439
+ return scmp
440
+ }
441
+
442
+ if (self.scale > that.scale) {
443
+ return order.bigint(self.value, scale(that, self.scale).value)
444
+ }
445
+
446
+ if (self.scale < that.scale) {
447
+ return order.bigint(scale(self, that.scale).value, that.value)
448
+ }
449
+
450
+ return order.bigint(self.value, that.value)
451
+ })
452
+
453
+ /**
454
+ * Returns `true` if the first argument is less than the second, otherwise `false`.
455
+ *
456
+ * @param self - The first argument.
457
+ * @param that - The second argument.
458
+ *
459
+ * @example
460
+ * import { lessThan, unsafeFromString } from "effect/BigDecimal"
461
+ *
462
+ * assert.deepStrictEqual(lessThan(unsafeFromString("2"), unsafeFromString("3")), true)
463
+ * assert.deepStrictEqual(lessThan(unsafeFromString("3"), unsafeFromString("3")), false)
464
+ * assert.deepStrictEqual(lessThan(unsafeFromString("4"), unsafeFromString("3")), false)
465
+ *
466
+ * @since 2.0.0
467
+ * @category predicates
468
+ */
469
+ export const lessThan: {
470
+ (that: BigDecimal): (self: BigDecimal) => boolean
471
+ (self: BigDecimal, that: BigDecimal): boolean
472
+ } = order.lessThan(Order)
473
+
474
+ /**
475
+ * Checks if a given `BigDecimal` is less than or equal to the provided one.
476
+ *
477
+ * @param self - The first `BigDecimal` to compare with.
478
+ * @param that - The second `BigDecimal` to compare with.
479
+ *
480
+ * @example
481
+ * import { lessThanOrEqualTo, unsafeFromString } from "effect/BigDecimal"
482
+ *
483
+ * assert.deepStrictEqual(lessThanOrEqualTo(unsafeFromString("2"), unsafeFromString("3")), true)
484
+ * assert.deepStrictEqual(lessThanOrEqualTo(unsafeFromString("3"), unsafeFromString("3")), true)
485
+ * assert.deepStrictEqual(lessThanOrEqualTo(unsafeFromString("4"), unsafeFromString("3")), false)
486
+ *
487
+ * @since 2.0.0
488
+ * @category predicates
489
+ */
490
+ export const lessThanOrEqualTo: {
491
+ (that: BigDecimal): (self: BigDecimal) => boolean
492
+ (self: BigDecimal, that: BigDecimal): boolean
493
+ } = order.lessThanOrEqualTo(Order)
494
+
495
+ /**
496
+ * Returns `true` if the first argument is greater than the second, otherwise `false`.
497
+ *
498
+ * @param self - The first argument.
499
+ * @param that - The second argument.
500
+ *
501
+ * @example
502
+ * import { greaterThan, unsafeFromString } from "effect/BigDecimal"
503
+ *
504
+ * assert.deepStrictEqual(greaterThan(unsafeFromString("2"), unsafeFromString("3")), false)
505
+ * assert.deepStrictEqual(greaterThan(unsafeFromString("3"), unsafeFromString("3")), false)
506
+ * assert.deepStrictEqual(greaterThan(unsafeFromString("4"), unsafeFromString("3")), true)
507
+ *
508
+ * @since 2.0.0
509
+ * @category predicates
510
+ */
511
+ export const greaterThan: {
512
+ (that: BigDecimal): (self: BigDecimal) => boolean
513
+ (self: BigDecimal, that: BigDecimal): boolean
514
+ } = order.greaterThan(Order)
515
+
516
+ /**
517
+ * Checks if a given `BigDecimal` is greater than or equal to the provided one.
518
+ *
519
+ * @param self - The first `BigDecimal` to compare with.
520
+ * @param that - The second `BigDecimal` to compare with.
521
+ *
522
+ * @example
523
+ * import { greaterThanOrEqualTo, unsafeFromString } from "effect/BigDecimal"
524
+ *
525
+ * assert.deepStrictEqual(greaterThanOrEqualTo(unsafeFromString("2"), unsafeFromString("3")), false)
526
+ * assert.deepStrictEqual(greaterThanOrEqualTo(unsafeFromString("3"), unsafeFromString("3")), true)
527
+ * assert.deepStrictEqual(greaterThanOrEqualTo(unsafeFromString("4"), unsafeFromString("3")), true)
528
+ *
529
+ * @since 2.0.0
530
+ * @category predicates
531
+ */
532
+ export const greaterThanOrEqualTo: {
533
+ (that: BigDecimal): (self: BigDecimal) => boolean
534
+ (self: BigDecimal, that: BigDecimal): boolean
535
+ } = order.greaterThanOrEqualTo(Order)
536
+
537
+ /**
538
+ * Checks if a `BigDecimal` is between a `minimum` and `maximum` value (inclusive).
539
+ *
540
+ * @param self - The `number` to check.
541
+ * @param minimum - The `minimum` value to check.
542
+ * @param maximum - The `maximum` value to check.
543
+ *
544
+ * @example
545
+ * import { between, unsafeFromString } from "effect/BigDecimal"
546
+ *
547
+ * assert.deepStrictEqual(between(unsafeFromString("0"), unsafeFromString("5"))(unsafeFromString("3")), true)
548
+ * assert.deepStrictEqual(between(unsafeFromString("0"), unsafeFromString("5"))(unsafeFromString("-1")), false)
549
+ * assert.deepStrictEqual(between(unsafeFromString("0"), unsafeFromString("5"))(unsafeFromString("6")), false)
550
+ *
551
+ * @since 2.0.0
552
+ * @category predicates
553
+ */
554
+ export const between: {
555
+ (minimum: BigDecimal, maximum: BigDecimal): (self: BigDecimal) => boolean
556
+ (self: BigDecimal, minimum: BigDecimal, maximum: BigDecimal): boolean
557
+ } = order.between(Order)
558
+
559
+ /**
560
+ * Restricts the given `BigDecimal` to be within the range specified by the `minimum` and `maximum` values.
561
+ *
562
+ * - If the `BigDecimal` is less than the `minimum` value, the function returns the `minimum` value.
563
+ * - If the `BigDecimal` is greater than the `maximum` value, the function returns the `maximum` value.
564
+ * - Otherwise, it returns the original `BigDecimal`.
565
+ *
566
+ * @param self - The `BigDecimal` to be clamped.
567
+ * @param minimum - The lower end of the range.
568
+ * @param maximum - The upper end of the range.
569
+ *
570
+ * @example
571
+ * import { clamp, unsafeFromString } from "effect/BigDecimal"
572
+ *
573
+ * assert.deepStrictEqual(clamp(unsafeFromString("0"), unsafeFromString("5"))(unsafeFromString("3")), unsafeFromString("3"))
574
+ * assert.deepStrictEqual(clamp(unsafeFromString("0"), unsafeFromString("5"))(unsafeFromString("-1")), unsafeFromString("0"))
575
+ * assert.deepStrictEqual(clamp(unsafeFromString("0"), unsafeFromString("5"))(unsafeFromString("6")), unsafeFromString("5"))
576
+ *
577
+ * @since 2.0.0
578
+ * @category math
579
+ */
580
+ export const clamp: {
581
+ (minimum: BigDecimal, maximum: BigDecimal): (self: BigDecimal) => BigDecimal
582
+ (self: BigDecimal, minimum: BigDecimal, maximum: BigDecimal): BigDecimal
583
+ } = order.clamp(Order)
584
+
585
+ /**
586
+ * Returns the minimum between two `BigDecimal`s.
587
+ *
588
+ * @param self - The first `BigDecimal`.
589
+ * @param that - The second `BigDecimal`.
590
+ *
591
+ * @example
592
+ * import { min, unsafeFromString } from "effect/BigDecimal"
593
+ *
594
+ * assert.deepStrictEqual(min(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("2"))
595
+ *
596
+ * @since 2.0.0
597
+ * @category math
598
+ */
599
+ export const min: {
600
+ (that: BigDecimal): (self: BigDecimal) => BigDecimal
601
+ (self: BigDecimal, that: BigDecimal): BigDecimal
602
+ } = order.min(Order)
603
+
604
+ /**
605
+ * Returns the maximum between two `BigDecimal`s.
606
+ *
607
+ * @param self - The first `BigDecimal`.
608
+ * @param that - The second `BigDecimal`.
609
+ *
610
+ * @example
611
+ * import { max, unsafeFromString } from "effect/BigDecimal"
612
+ *
613
+ * assert.deepStrictEqual(max(unsafeFromString("2"), unsafeFromString("3")), unsafeFromString("3"))
614
+ *
615
+ * @since 2.0.0
616
+ * @category math
617
+ */
618
+ export const max: {
619
+ (that: BigDecimal): (self: BigDecimal) => BigDecimal
620
+ (self: BigDecimal, that: BigDecimal): BigDecimal
621
+ } = order.max(Order)
622
+
623
+ /**
624
+ * Determines the sign of a given `BigDecimal`.
625
+ *
626
+ * @param n - The `BigDecimal` to determine the sign of.
627
+ *
628
+ * @example
629
+ * import { sign, unsafeFromString } from "effect/BigDecimal"
630
+ *
631
+ * assert.deepStrictEqual(sign(unsafeFromString("-5")), -1)
632
+ * assert.deepStrictEqual(sign(unsafeFromString("0")), 0)
633
+ * assert.deepStrictEqual(sign(unsafeFromString("5")), 1)
634
+ *
635
+ * @since 2.0.0
636
+ * @category math
637
+ */
638
+ export const sign = (n: BigDecimal): Ordering => n.value === bigint0 ? 0 : n.value < bigint0 ? -1 : 1
639
+
640
+ /**
641
+ * Determines the absolute value of a given `BigDecimal`.
642
+ *
643
+ * @param n - The `BigDecimal` to determine the absolute value of.
644
+ *
645
+ * @example
646
+ * import { abs, unsafeFromString } from "effect/BigDecimal"
647
+ *
648
+ * assert.deepStrictEqual(abs(unsafeFromString("-5")), unsafeFromString("5"))
649
+ * assert.deepStrictEqual(abs(unsafeFromString("0")), unsafeFromString("0"))
650
+ * assert.deepStrictEqual(abs(unsafeFromString("5")), unsafeFromString("5"))
651
+ *
652
+ * @since 2.0.0
653
+ * @category math
654
+ */
655
+ export const abs = (n: BigDecimal): BigDecimal => n.value < bigint0 ? make(-n.value, n.scale) : n
656
+
657
+ /**
658
+ * Provides a negate operation on `BigDecimal`s.
659
+ *
660
+ * @param n - The `BigDecimal` to negate.
661
+ *
662
+ * @example
663
+ * import { negate, unsafeFromString } from "effect/BigDecimal"
664
+ *
665
+ * assert.deepStrictEqual(negate(unsafeFromString("3")), unsafeFromString("-3"))
666
+ * assert.deepStrictEqual(negate(unsafeFromString("-6")), unsafeFromString("6"))
667
+ *
668
+ * @since 2.0.0
669
+ * @category math
670
+ */
671
+ export const negate = (n: BigDecimal): BigDecimal => make(-n.value, n.scale)
672
+
673
+ /**
674
+ * Returns the remainder left over when one operand is divided by a second operand.
675
+ *
676
+ * If the divisor is `0`, the result will be `None`.
677
+ *
678
+ * @param self - The dividend.
679
+ * @param divisor - The divisor.
680
+ *
681
+ * @example
682
+ * import { remainder, unsafeFromString } from "effect/BigDecimal"
683
+ * import { some, none } from "effect/Option"
684
+ *
685
+ * assert.deepStrictEqual(remainder(unsafeFromString("2"), unsafeFromString("2")), some(unsafeFromString("0")))
686
+ * assert.deepStrictEqual(remainder(unsafeFromString("3"), unsafeFromString("2")), some(unsafeFromString("1")))
687
+ * assert.deepStrictEqual(remainder(unsafeFromString("-4"), unsafeFromString("2")), some(unsafeFromString("0")))
688
+ *
689
+ * @since 2.0.0
690
+ * @category math
691
+ */
692
+ export const remainder: {
693
+ (divisor: BigDecimal): (self: BigDecimal) => Option.Option<BigDecimal>
694
+ (self: BigDecimal, divisor: BigDecimal): Option.Option<BigDecimal>
695
+ } = dual(2, (self: BigDecimal, divisor: BigDecimal): Option.Option<BigDecimal> => {
696
+ if (divisor.value === bigint0) {
697
+ return Option.none()
698
+ }
699
+
700
+ const max = Math.max(self.scale, divisor.scale)
701
+ return Option.some(make(scale(self, max).value % scale(divisor, max).value, max))
702
+ })
703
+
704
+ /**
705
+ * Returns the remainder left over when one operand is divided by a second operand.
706
+ *
707
+ * Throws a `RangeError` if the divisor is `0`.
708
+ *
709
+ * @param self - The dividend.
710
+ * @param divisor - The divisor.
711
+ *
712
+ * @example
713
+ * import { unsafeRemainder, unsafeFromString } from "effect/BigDecimal"
714
+ *
715
+ * assert.deepStrictEqual(unsafeRemainder(unsafeFromString("2"), unsafeFromString("2")), unsafeFromString("0"))
716
+ * assert.deepStrictEqual(unsafeRemainder(unsafeFromString("3"), unsafeFromString("2")), unsafeFromString("1"))
717
+ * assert.deepStrictEqual(unsafeRemainder(unsafeFromString("-4"), unsafeFromString("2")), unsafeFromString("0"))
718
+ *
719
+ * @since 2.0.0
720
+ * @category math
721
+ */
722
+ export const unsafeRemainder: {
723
+ (divisor: BigDecimal): (self: BigDecimal) => BigDecimal
724
+ (self: BigDecimal, divisor: BigDecimal): BigDecimal
725
+ } = dual(2, (self: BigDecimal, divisor: BigDecimal): BigDecimal => {
726
+ if (divisor.value === bigint0) {
727
+ throw new RangeError("Division by zero")
728
+ }
729
+
730
+ const max = Math.max(self.scale, divisor.scale)
731
+ return make(scale(self, max).value % scale(divisor, max).value, max)
732
+ })
733
+
734
+ /**
735
+ * @category instances
736
+ * @since 2.0.0
737
+ */
738
+ export const Equivalence: equivalence.Equivalence<BigDecimal> = equivalence.make((self, that) => {
739
+ if (self.scale > that.scale) {
740
+ return scale(that, self.scale).value === self.value
741
+ }
742
+
743
+ if (self.scale < that.scale) {
744
+ return scale(self, that.scale).value === that.value
745
+ }
746
+
747
+ return self.value === that.value
748
+ })
749
+
750
+ /**
751
+ * Checks if two `BigDecimal`s are equal.
752
+ *
753
+ * @since 2.0.0
754
+ * @category predicates
755
+ */
756
+ export const equals: {
757
+ (that: BigDecimal): (self: BigDecimal) => boolean
758
+ (self: BigDecimal, that: BigDecimal): boolean
759
+ } = dual(2, (self: BigDecimal, that: BigDecimal): boolean => Equivalence(self, that))
760
+
761
+ /**
762
+ * Creates a `BigDecimal` from a `bigint` value.
763
+ *
764
+ * @param value - The `bigint` value to create a `BigDecimal` from.
765
+ *
766
+ * @since 2.0.0
767
+ * @category constructors
768
+ */
769
+ export const fromBigInt = (n: bigint): BigDecimal => make(n, 0)
770
+
771
+ /**
772
+ * Creates a `BigDecimal` from a `number` value.
773
+ *
774
+ * It is not recommended to convert a floating point number to a decimal directly,
775
+ * as the floating point representation may be unexpected.
776
+ *
777
+ * @param value - The `number` value to create a `BigDecimal` from.
778
+ *
779
+ * @example
780
+ * import { fromNumber, make } from "effect/BigDecimal"
781
+ *
782
+ * assert.deepStrictEqual(fromNumber(123), make(123n, 0))
783
+ * assert.deepStrictEqual(fromNumber(123.456), make(123456n, 3))
784
+ *
785
+ * @since 2.0.0
786
+ * @category constructors
787
+ */
788
+ export const fromNumber = (n: number): BigDecimal => {
789
+ const [lead, trail = ""] = `${n}`.split(".")
790
+ return make(BigInt(`${lead}${trail}`), trail.length)
791
+ }
792
+
793
+ /**
794
+ * Parses a numerical `string` into a `BigDecimal`.
795
+ *
796
+ * @param s - The `string` to parse.
797
+ *
798
+ * @example
799
+ * import { fromString, make } from "effect/BigDecimal"
800
+ * import { some, none } from "effect/Option"
801
+ *
802
+ * assert.deepStrictEqual(fromString("123"), some(make(123n, 0)))
803
+ * assert.deepStrictEqual(fromString("123.456"), some(make(123456n, 3)))
804
+ * assert.deepStrictEqual(fromString("123.abc"), none())
805
+ *
806
+ * @since 2.0.0
807
+ * @category constructors
808
+ */
809
+ export const fromString = (s: string): Option.Option<BigDecimal> => {
810
+ let digits: string
811
+ let scale: number
812
+
813
+ const dot = s.search(/\./)
814
+ if (dot !== -1) {
815
+ const lead = s.slice(0, dot)
816
+ const trail = s.slice(dot + 1)
817
+ digits = `${lead}${trail}`
818
+ scale = trail.length
819
+ } else {
820
+ digits = s
821
+ scale = 0
822
+ }
823
+
824
+ if (digits === "") {
825
+ // TODO: This mimics the BigInt constructor behavior. Should this be `Option.none()`?
826
+ return Option.some(zero)
827
+ }
828
+
829
+ if (!/^(?:\+|-)?\d+$/.test(digits)) {
830
+ return Option.none()
831
+ }
832
+
833
+ return Option.some(make(BigInt(digits), scale))
834
+ }
835
+
836
+ /**
837
+ * Parses a numerical `string` into a `BigDecimal`.
838
+ *
839
+ * @param s - The `string` to parse.
840
+ *
841
+ * @example
842
+ * import { unsafeFromString, make } from "effect/BigDecimal"
843
+ *
844
+ * assert.deepStrictEqual(unsafeFromString("123"), make(123n, 0))
845
+ * assert.deepStrictEqual(unsafeFromString("123.456"), make(123456n, 3))
846
+ * assert.throws(() => unsafeFromString("123.abc"))
847
+ *
848
+ * @since 2.0.0
849
+ * @category constructors
850
+ */
851
+ export const unsafeFromString = (s: string): BigDecimal =>
852
+ Option.getOrThrowWith(fromString(s), () => new Error("Invalid numerical string"))
853
+
854
+ /**
855
+ * Formats a given `BigDecimal` as a `string`.
856
+ *
857
+ * @param normalized - The `BigDecimal` to format.
858
+ *
859
+ * @example
860
+ * import { toString, unsafeFromString } from "effect/BigDecimal"
861
+ *
862
+ * assert.deepStrictEqual(toString(unsafeFromString("-5")), "-5")
863
+ * assert.deepStrictEqual(toString(unsafeFromString("123.456")), "123.456")
864
+ * assert.deepStrictEqual(toString(unsafeFromString("-0.00000123")), "-0.00000123")
865
+ *
866
+ * @since 2.0.0
867
+ * @category conversions
868
+ */
869
+ export const toString = (n: BigDecimal): string => {
870
+ const negative = n.value < bigint0
871
+ const absolute = negative ? `${n.value}`.substring(1) : `${n.value}`
872
+
873
+ let before: string
874
+ let after: string
875
+
876
+ if (n.scale >= absolute.length) {
877
+ before = "0"
878
+ after = "0".repeat(n.scale - absolute.length) + absolute
879
+ } else {
880
+ const location = absolute.length - n.scale
881
+ if (location > absolute.length) {
882
+ const zeros = location - absolute.length
883
+ before = `${absolute}${"0".repeat(zeros)}`
884
+ after = ""
885
+ } else {
886
+ after = absolute.slice(location)
887
+ before = absolute.slice(0, location)
888
+ }
889
+ }
890
+
891
+ const complete = after === "" ? before : `${before}.${after}`
892
+ return negative ? `-${complete}` : complete
893
+ }
894
+
895
+ /**
896
+ * Converts a `BigDecimal` to a `number`.
897
+ *
898
+ * This function will produce incorrect results if the `BigDecimal` exceeds the 64-bit range of a `number`.
899
+ *
900
+ * @param n - The `BigDecimal` to convert.
901
+ *
902
+ * @example
903
+ * import { unsafeToNumber, unsafeFromString } from "effect/BigDecimal"
904
+ *
905
+ * assert.deepStrictEqual(unsafeToNumber(unsafeFromString("123.456")), 123.456)
906
+ *
907
+ * @since 2.0.0
908
+ * @category conversions
909
+ */
910
+ export const unsafeToNumber = (n: BigDecimal): number => Number(toString(n))
911
+
912
+ /**
913
+ * Checks if a given `BigDecimal` is an integer.
914
+ *
915
+ * @param n - The `BigDecimal` to check.
916
+ *
917
+ * @example
918
+ * import { isInteger, unsafeFromString } from "effect/BigDecimal"
919
+ *
920
+ * assert.deepStrictEqual(isInteger(unsafeFromString("0")), true)
921
+ * assert.deepStrictEqual(isInteger(unsafeFromString("1")), true)
922
+ * assert.deepStrictEqual(isInteger(unsafeFromString("1.1")), false)
923
+ *
924
+ * @since 2.0.0
925
+ * @category predicates
926
+ */
927
+ export const isInteger = (n: BigDecimal): boolean => normalize(n).scale <= 0
928
+
929
+ /**
930
+ * Checks if a given `BigDecimal` is `0`.
931
+ *
932
+ * @param n - The `BigDecimal` to check.
933
+ *
934
+ * @example
935
+ * import { isZero, unsafeFromString } from "effect/BigDecimal"
936
+ *
937
+ * assert.deepStrictEqual(isZero(unsafeFromString("0")), true)
938
+ * assert.deepStrictEqual(isZero(unsafeFromString("1")), false)
939
+ *
940
+ * @since 2.0.0
941
+ * @category predicates
942
+ */
943
+ export const isZero = (n: BigDecimal): boolean => n.value === bigint0
944
+
945
+ /**
946
+ * Checks if a given `BigDecimal` is negative.
947
+ *
948
+ * @param n - The `BigDecimal` to check.
949
+ *
950
+ * @example
951
+ * import { isNegative, unsafeFromString } from "effect/BigDecimal"
952
+ *
953
+ * assert.deepStrictEqual(isNegative(unsafeFromString("-1")), true)
954
+ * assert.deepStrictEqual(isNegative(unsafeFromString("0")), false)
955
+ * assert.deepStrictEqual(isNegative(unsafeFromString("1")), false)
956
+ *
957
+ * @since 2.0.0
958
+ * @category predicates
959
+ */
960
+ export const isNegative = (n: BigDecimal): boolean => n.value < bigint0
961
+
962
+ /**
963
+ * Checks if a given `BigDecimal` is positive.
964
+ *
965
+ * @param n - The `BigDecimal` to check.
966
+ *
967
+ * @example
968
+ * import { isPositive, unsafeFromString } from "effect/BigDecimal"
969
+ *
970
+ * assert.deepStrictEqual(isPositive(unsafeFromString("-1")), false)
971
+ * assert.deepStrictEqual(isPositive(unsafeFromString("0")), false)
972
+ * assert.deepStrictEqual(isPositive(unsafeFromString("1")), true)
973
+ *
974
+ * @since 2.0.0
975
+ * @category predicates
976
+ */
977
+ export const isPositive = (n: BigDecimal): boolean => n.value > bigint0