@blazetrails/ruby-compat 0.0.0-stage → 0.1.0-alpha0.1

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 (622) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +6 -0
  3. package/README.md +440 -2
  4. package/dist/argument-error.d.ts +15 -0
  5. package/dist/argument-error.js +15 -0
  6. package/dist/argument-error.js.map +1 -0
  7. package/dist/array.d.ts +415 -0
  8. package/dist/array.js +1330 -0
  9. package/dist/array.js.map +1 -0
  10. package/dist/async-context-adapter.d.ts +19 -0
  11. package/dist/async-context-adapter.js +139 -0
  12. package/dist/async-context-adapter.js.map +1 -0
  13. package/dist/backtrace-location.d.ts +77 -0
  14. package/dist/backtrace-location.js +155 -0
  15. package/dist/backtrace-location.js.map +1 -0
  16. package/dist/base64.d.ts +73 -0
  17. package/dist/base64.js +164 -0
  18. package/dist/base64.js.map +1 -0
  19. package/dist/benchmark.d.ts +19 -0
  20. package/dist/benchmark.js +16 -0
  21. package/dist/benchmark.js.map +1 -0
  22. package/dist/big-decimal.d.ts +110 -0
  23. package/dist/big-decimal.js +582 -0
  24. package/dist/big-decimal.js.map +1 -0
  25. package/dist/bundler.d.ts +44 -0
  26. package/dist/bundler.js +101 -0
  27. package/dist/bundler.js.map +1 -0
  28. package/dist/cgi.d.ts +89 -0
  29. package/dist/cgi.js +168 -0
  30. package/dist/cgi.js.map +1 -0
  31. package/dist/child-process-adapter.d.ts +110 -0
  32. package/dist/child-process-adapter.js +272 -0
  33. package/dist/child-process-adapter.js.map +1 -0
  34. package/dist/class-module.d.ts +10 -0
  35. package/dist/class-module.js +10 -0
  36. package/dist/class-module.js.map +1 -0
  37. package/dist/classpath.d.ts +90 -0
  38. package/dist/classpath.js +207 -0
  39. package/dist/classpath.js.map +1 -0
  40. package/dist/closed-queue-error.d.ts +10 -0
  41. package/dist/closed-queue-error.js +10 -0
  42. package/dist/closed-queue-error.js.map +1 -0
  43. package/dist/comparable.d.ts +127 -0
  44. package/dist/comparable.js +376 -0
  45. package/dist/comparable.js.map +1 -0
  46. package/dist/complex.d.ts +48 -0
  47. package/dist/complex.js +162 -0
  48. package/dist/complex.js.map +1 -0
  49. package/dist/concurrent/atomic-boolean.d.ts +24 -0
  50. package/dist/concurrent/atomic-boolean.js +43 -0
  51. package/dist/concurrent/atomic-boolean.js.map +1 -0
  52. package/dist/concurrent/atomic-fixnum.d.ts +21 -0
  53. package/dist/concurrent/atomic-fixnum.js +35 -0
  54. package/dist/concurrent/atomic-fixnum.js.map +1 -0
  55. package/dist/concurrent/count-down-latch.d.ts +20 -0
  56. package/dist/concurrent/count-down-latch.js +50 -0
  57. package/dist/concurrent/count-down-latch.js.map +1 -0
  58. package/dist/concurrent/cyclic-barrier.d.ts +18 -0
  59. package/dist/concurrent/cyclic-barrier.js +50 -0
  60. package/dist/concurrent/cyclic-barrier.js.map +1 -0
  61. package/dist/concurrent/event.d.ts +19 -0
  62. package/dist/concurrent/event.js +31 -0
  63. package/dist/concurrent/event.js.map +1 -0
  64. package/dist/concurrent/map.d.ts +149 -0
  65. package/dist/concurrent/map.js +202 -0
  66. package/dist/concurrent/map.js.map +1 -0
  67. package/dist/concurrent/read-write-lock.d.ts +25 -0
  68. package/dist/concurrent/read-write-lock.js +70 -0
  69. package/dist/concurrent/read-write-lock.js.map +1 -0
  70. package/dist/concurrent/semaphore.d.ts +24 -0
  71. package/dist/concurrent/semaphore.js +74 -0
  72. package/dist/concurrent/semaphore.js.map +1 -0
  73. package/dist/concurrent/timer-task.d.ts +52 -0
  74. package/dist/concurrent/timer-task.js +112 -0
  75. package/dist/concurrent/timer-task.js.map +1 -0
  76. package/dist/constants.generated.d.ts +2 -0
  77. package/dist/constants.generated.js +64 -0
  78. package/dist/constants.generated.js.map +1 -0
  79. package/dist/converter-not-found-error.d.ts +14 -0
  80. package/dist/converter-not-found-error.js +14 -0
  81. package/dist/converter-not-found-error.js.map +1 -0
  82. package/dist/crypto-adapter.d.ts +64 -0
  83. package/dist/crypto-adapter.js +365 -0
  84. package/dist/crypto-adapter.js.map +1 -0
  85. package/dist/delegate.d.ts +156 -0
  86. package/dist/delegate.js +306 -0
  87. package/dist/delegate.js.map +1 -0
  88. package/dist/digest.d.ts +99 -0
  89. package/dist/digest.js +131 -0
  90. package/dist/digest.js.map +1 -0
  91. package/dist/dir.d.ts +218 -0
  92. package/dist/dir.js +599 -0
  93. package/dist/dir.js.map +1 -0
  94. package/dist/encoding-error.d.ts +14 -0
  95. package/dist/encoding-error.js +17 -0
  96. package/dist/encoding-error.js.map +1 -0
  97. package/dist/encoding.d.ts +121 -0
  98. package/dist/encoding.js +306 -0
  99. package/dist/encoding.js.map +1 -0
  100. package/dist/ensure.d.ts +15 -0
  101. package/dist/ensure.js +35 -0
  102. package/dist/ensure.js.map +1 -0
  103. package/dist/enumerable.d.ts +375 -0
  104. package/dist/enumerable.js +1100 -0
  105. package/dist/enumerable.js.map +1 -0
  106. package/dist/enumerator.d.ts +321 -0
  107. package/dist/enumerator.js +642 -0
  108. package/dist/enumerator.js.map +1 -0
  109. package/dist/eof-error.d.ts +14 -0
  110. package/dist/eof-error.js +14 -0
  111. package/dist/eof-error.js.map +1 -0
  112. package/dist/errno.d.ts +327 -0
  113. package/dist/errno.js +452 -0
  114. package/dist/errno.js.map +1 -0
  115. package/dist/exc-detailed-message.d.ts +15 -0
  116. package/dist/exc-detailed-message.js +106 -0
  117. package/dist/exc-detailed-message.js.map +1 -0
  118. package/dist/exc-to-s.d.ts +10 -0
  119. package/dist/exc-to-s.js +21 -0
  120. package/dist/exc-to-s.js.map +1 -0
  121. package/dist/exception.d.ts +34 -0
  122. package/dist/exception.js +99 -0
  123. package/dist/exception.js.map +1 -0
  124. package/dist/fiber-error.d.ts +12 -0
  125. package/dist/fiber-error.js +12 -0
  126. package/dist/fiber-error.js.map +1 -0
  127. package/dist/fiber.d.ts +51 -0
  128. package/dist/fiber.js +178 -0
  129. package/dist/fiber.js.map +1 -0
  130. package/dist/file-utils.d.ts +480 -0
  131. package/dist/file-utils.js +1823 -0
  132. package/dist/file-utils.js.map +1 -0
  133. package/dist/file.d.ts +635 -0
  134. package/dist/file.js +1312 -0
  135. package/dist/file.js.map +1 -0
  136. package/dist/float-domain-error.d.ts +17 -0
  137. package/dist/float-domain-error.js +17 -0
  138. package/dist/float-domain-error.js.map +1 -0
  139. package/dist/fork-children.d.ts +23 -0
  140. package/dist/fork-children.js +32 -0
  141. package/dist/fork-children.js.map +1 -0
  142. package/dist/frozen-error.d.ts +33 -0
  143. package/dist/frozen-error.js +42 -0
  144. package/dist/frozen-error.js.map +1 -0
  145. package/dist/fs-adapter.d.ts +158 -0
  146. package/dist/fs-adapter.js +253 -0
  147. package/dist/fs-adapter.js.map +1 -0
  148. package/dist/gem/deprecate.d.ts +10 -0
  149. package/dist/gem/deprecate.js +8 -0
  150. package/dist/gem/deprecate.js.map +1 -0
  151. package/dist/gem/requirement.d.ts +64 -0
  152. package/dist/gem/requirement.js +91 -0
  153. package/dist/gem/requirement.js.map +1 -0
  154. package/dist/gem/version.d.ts +50 -0
  155. package/dist/gem/version.js +148 -0
  156. package/dist/gem/version.js.map +1 -0
  157. package/dist/gem.d.ts +59 -0
  158. package/dist/gem.js +82 -0
  159. package/dist/gem.js.map +1 -0
  160. package/dist/hash.d.ts +967 -0
  161. package/dist/hash.js +1572 -0
  162. package/dist/hash.js.map +1 -0
  163. package/dist/http-adapter.d.ts +123 -0
  164. package/dist/http-adapter.js +220 -0
  165. package/dist/http-adapter.js.map +1 -0
  166. package/dist/immediate-executor.d.ts +20 -0
  167. package/dist/immediate-executor.js +39 -0
  168. package/dist/immediate-executor.js.map +1 -0
  169. package/dist/include.d.ts +778 -0
  170. package/dist/include.js +2195 -0
  171. package/dist/include.js.map +1 -0
  172. package/dist/index-error.d.ts +13 -0
  173. package/dist/index-error.js +13 -0
  174. package/dist/index-error.js.map +1 -0
  175. package/dist/index.d.ts +174 -0
  176. package/dist/index.js +166 -0
  177. package/dist/index.js.map +1 -0
  178. package/dist/invalid-byte-sequence-error.d.ts +62 -0
  179. package/dist/invalid-byte-sequence-error.js +75 -0
  180. package/dist/invalid-byte-sequence-error.js.map +1 -0
  181. package/dist/io-error.d.ts +14 -0
  182. package/dist/io-error.js +17 -0
  183. package/dist/io-error.js.map +1 -0
  184. package/dist/io.d.ts +867 -0
  185. package/dist/io.js +1960 -0
  186. package/dist/io.js.map +1 -0
  187. package/dist/ipaddr.d.ts +79 -0
  188. package/dist/ipaddr.js +405 -0
  189. package/dist/ipaddr.js.map +1 -0
  190. package/dist/json.d.ts +67 -0
  191. package/dist/json.js +185 -0
  192. package/dist/json.js.map +1 -0
  193. package/dist/kernel-catch.d.ts +59 -0
  194. package/dist/kernel-catch.js +184 -0
  195. package/dist/kernel-catch.js.map +1 -0
  196. package/dist/kernel-float.d.ts +19 -0
  197. package/dist/kernel-float.js +54 -0
  198. package/dist/kernel-float.js.map +1 -0
  199. package/dist/kernel-fork.d.ts +30 -0
  200. package/dist/kernel-fork.js +72 -0
  201. package/dist/kernel-fork.js.map +1 -0
  202. package/dist/kernel-format.d.ts +27 -0
  203. package/dist/kernel-format.js +901 -0
  204. package/dist/kernel-format.js.map +1 -0
  205. package/dist/kernel-hash.d.ts +7 -0
  206. package/dist/kernel-hash.js +33 -0
  207. package/dist/kernel-hash.js.map +1 -0
  208. package/dist/kernel-integer.d.ts +49 -0
  209. package/dist/kernel-integer.js +170 -0
  210. package/dist/kernel-integer.js.map +1 -0
  211. package/dist/kernel-rand.d.ts +16 -0
  212. package/dist/kernel-rand.js +237 -0
  213. package/dist/kernel-rand.js.map +1 -0
  214. package/dist/kernel-system.d.ts +40 -0
  215. package/dist/kernel-system.js +97 -0
  216. package/dist/kernel-system.js.map +1 -0
  217. package/dist/kernel-warn.d.ts +35 -0
  218. package/dist/kernel-warn.js +73 -0
  219. package/dist/kernel-warn.js.map +1 -0
  220. package/dist/key-error.d.ts +44 -0
  221. package/dist/key-error.js +59 -0
  222. package/dist/key-error.js.map +1 -0
  223. package/dist/keyword-splat.d.ts +41 -0
  224. package/dist/keyword-splat.js +65 -0
  225. package/dist/keyword-splat.js.map +1 -0
  226. package/dist/load-error.d.ts +19 -0
  227. package/dist/load-error.js +19 -0
  228. package/dist/load-error.js.map +1 -0
  229. package/dist/load.d.ts +121 -0
  230. package/dist/load.js +263 -0
  231. package/dist/load.js.map +1 -0
  232. package/dist/loaded-features.d.ts +13 -0
  233. package/dist/loaded-features.js +15 -0
  234. package/dist/loaded-features.js.map +1 -0
  235. package/dist/local-jump-error.d.ts +12 -0
  236. package/dist/local-jump-error.js +12 -0
  237. package/dist/local-jump-error.js.map +1 -0
  238. package/dist/logger/formatter.d.ts +21 -0
  239. package/dist/logger/formatter.js +43 -0
  240. package/dist/logger/formatter.js.map +1 -0
  241. package/dist/logger/log-device.d.ts +52 -0
  242. package/dist/logger/log-device.js +104 -0
  243. package/dist/logger/log-device.js.map +1 -0
  244. package/dist/logger/severity.d.ts +23 -0
  245. package/dist/logger/severity.js +42 -0
  246. package/dist/logger/severity.js.map +1 -0
  247. package/dist/logger.d.ts +127 -0
  248. package/dist/logger.js +215 -0
  249. package/dist/logger.js.map +1 -0
  250. package/dist/marshal.d.ts +83 -0
  251. package/dist/marshal.js +1487 -0
  252. package/dist/marshal.js.map +1 -0
  253. package/dist/match-data.d.ts +161 -0
  254. package/dist/match-data.js +284 -0
  255. package/dist/match-data.js.map +1 -0
  256. package/dist/method-cache.d.ts +17 -0
  257. package/dist/method-cache.js +19 -0
  258. package/dist/method-cache.js.map +1 -0
  259. package/dist/method-missing-proxy.d.ts +53 -0
  260. package/dist/method-missing-proxy.js +154 -0
  261. package/dist/method-missing-proxy.js.map +1 -0
  262. package/dist/method.d.ts +132 -0
  263. package/dist/method.js +320 -0
  264. package/dist/method.js.map +1 -0
  265. package/dist/monitor.d.ts +114 -0
  266. package/dist/monitor.js +270 -0
  267. package/dist/monitor.js.map +1 -0
  268. package/dist/mutex.d.ts +51 -0
  269. package/dist/mutex.js +150 -0
  270. package/dist/mutex.js.map +1 -0
  271. package/dist/name-error.d.ts +45 -0
  272. package/dist/name-error.js +54 -0
  273. package/dist/name-error.js.map +1 -0
  274. package/dist/net/http/exceptions.d.ts +31 -0
  275. package/dist/net/http/exceptions.js +46 -0
  276. package/dist/net/http/exceptions.js.map +1 -0
  277. package/dist/net/http/request.d.ts +137 -0
  278. package/dist/net/http/request.js +559 -0
  279. package/dist/net/http/request.js.map +1 -0
  280. package/dist/net/http/requests.d.ts +197 -0
  281. package/dist/net/http/requests.js +197 -0
  282. package/dist/net/http/requests.js.map +1 -0
  283. package/dist/net/http/response.d.ts +141 -0
  284. package/dist/net/http/response.js +416 -0
  285. package/dist/net/http/response.js.map +1 -0
  286. package/dist/net/http/responses.d.ts +345 -0
  287. package/dist/net/http/responses.js +486 -0
  288. package/dist/net/http/responses.js.map +1 -0
  289. package/dist/net/http.d.ts +278 -0
  290. package/dist/net/http.js +760 -0
  291. package/dist/net/http.js.map +1 -0
  292. package/dist/net/protocol.d.ts +227 -0
  293. package/dist/net/protocol.js +392 -0
  294. package/dist/net/protocol.js.map +1 -0
  295. package/dist/nil-class.d.ts +10 -0
  296. package/dist/nil-class.js +27 -0
  297. package/dist/nil-class.js.map +1 -0
  298. package/dist/no-method-error.d.ts +38 -0
  299. package/dist/no-method-error.js +45 -0
  300. package/dist/no-method-error.js.map +1 -0
  301. package/dist/not-implemented-error.d.ts +13 -0
  302. package/dist/not-implemented-error.js +14 -0
  303. package/dist/not-implemented-error.js.map +1 -0
  304. package/dist/numeric.d.ts +211 -0
  305. package/dist/numeric.js +802 -0
  306. package/dist/numeric.js.map +1 -0
  307. package/dist/object-space.d.ts +34 -0
  308. package/dist/object-space.js +152 -0
  309. package/dist/object-space.js.map +1 -0
  310. package/dist/object.d.ts +908 -0
  311. package/dist/object.js +2238 -0
  312. package/dist/object.js.map +1 -0
  313. package/dist/open-uri.d.ts +180 -0
  314. package/dist/open-uri.js +402 -0
  315. package/dist/open-uri.js.map +1 -0
  316. package/dist/open3.d.ts +69 -0
  317. package/dist/open3.js +134 -0
  318. package/dist/open3.js.map +1 -0
  319. package/dist/openssl.d.ts +479 -0
  320. package/dist/openssl.js +1052 -0
  321. package/dist/openssl.js.map +1 -0
  322. package/dist/optparse.d.ts +130 -0
  323. package/dist/optparse.js +457 -0
  324. package/dist/optparse.js.map +1 -0
  325. package/dist/os-adapter.d.ts +20 -0
  326. package/dist/os-adapter.js +95 -0
  327. package/dist/os-adapter.js.map +1 -0
  328. package/dist/pathname.d.ts +71 -0
  329. package/dist/pathname.js +394 -0
  330. package/dist/pathname.js.map +1 -0
  331. package/dist/pp.d.ts +60 -0
  332. package/dist/pp.js +195 -0
  333. package/dist/pp.js.map +1 -0
  334. package/dist/pretty-print.d.ts +89 -0
  335. package/dist/pretty-print.js +232 -0
  336. package/dist/pretty-print.js.map +1 -0
  337. package/dist/process-adapter.d.ts +224 -0
  338. package/dist/process-adapter.js +878 -0
  339. package/dist/process-adapter.js.map +1 -0
  340. package/dist/process.d.ts +192 -0
  341. package/dist/process.js +403 -0
  342. package/dist/process.js.map +1 -0
  343. package/dist/psych/class-loader.d.ts +92 -0
  344. package/dist/psych/class-loader.js +139 -0
  345. package/dist/psych/class-loader.js.map +1 -0
  346. package/dist/psych/coder.d.ts +144 -0
  347. package/dist/psych/coder.js +176 -0
  348. package/dist/psych/coder.js.map +1 -0
  349. package/dist/psych/core-ext.d.ts +8 -0
  350. package/dist/psych/core-ext.js +10 -0
  351. package/dist/psych/core-ext.js.map +1 -0
  352. package/dist/psych/emitter.d.ts +116 -0
  353. package/dist/psych/emitter.js +1130 -0
  354. package/dist/psych/emitter.js.map +1 -0
  355. package/dist/psych/exception.d.ts +43 -0
  356. package/dist/psych/exception.js +54 -0
  357. package/dist/psych/exception.js.map +1 -0
  358. package/dist/psych/handler.d.ts +59 -0
  359. package/dist/psych/handler.js +95 -0
  360. package/dist/psych/handler.js.map +1 -0
  361. package/dist/psych/handlers/document-stream.d.ts +17 -0
  362. package/dist/psych/handlers/document-stream.js +26 -0
  363. package/dist/psych/handlers/document-stream.js.map +1 -0
  364. package/dist/psych/nodes/alias.d.ts +15 -0
  365. package/dist/psych/nodes/alias.js +22 -0
  366. package/dist/psych/nodes/alias.js.map +1 -0
  367. package/dist/psych/nodes/document.d.ts +23 -0
  368. package/dist/psych/nodes/document.js +35 -0
  369. package/dist/psych/nodes/document.js.map +1 -0
  370. package/dist/psych/nodes/mapping.d.ts +25 -0
  371. package/dist/psych/nodes/mapping.js +35 -0
  372. package/dist/psych/nodes/mapping.js.map +1 -0
  373. package/dist/psych/nodes/node.d.ts +59 -0
  374. package/dist/psych/nodes/node.js +79 -0
  375. package/dist/psych/nodes/node.js.map +1 -0
  376. package/dist/psych/nodes/scalar.d.ts +35 -0
  377. package/dist/psych/nodes/scalar.js +47 -0
  378. package/dist/psych/nodes/scalar.js.map +1 -0
  379. package/dist/psych/nodes/sequence.d.ts +25 -0
  380. package/dist/psych/nodes/sequence.js +35 -0
  381. package/dist/psych/nodes/sequence.js.map +1 -0
  382. package/dist/psych/nodes/stream.d.ts +23 -0
  383. package/dist/psych/nodes/stream.js +31 -0
  384. package/dist/psych/nodes/stream.js.map +1 -0
  385. package/dist/psych/omap.d.ts +9 -0
  386. package/dist/psych/omap.js +9 -0
  387. package/dist/psych/omap.js.map +1 -0
  388. package/dist/psych/parser.d.ts +41 -0
  389. package/dist/psych/parser.js +139 -0
  390. package/dist/psych/parser.js.map +1 -0
  391. package/dist/psych/scalar-scanner.d.ts +35 -0
  392. package/dist/psych/scalar-scanner.js +173 -0
  393. package/dist/psych/scalar-scanner.js.map +1 -0
  394. package/dist/psych/syntax-error.d.ts +23 -0
  395. package/dist/psych/syntax-error.js +35 -0
  396. package/dist/psych/syntax-error.js.map +1 -0
  397. package/dist/psych/tree-builder.d.ts +51 -0
  398. package/dist/psych/tree-builder.js +118 -0
  399. package/dist/psych/tree-builder.js.map +1 -0
  400. package/dist/psych/visitors/depth-first.d.ts +27 -0
  401. package/dist/psych/visitors/depth-first.js +37 -0
  402. package/dist/psych/visitors/depth-first.js.map +1 -0
  403. package/dist/psych/visitors/emitter.d.ts +32 -0
  404. package/dist/psych/visitors/emitter.js +63 -0
  405. package/dist/psych/visitors/emitter.js.map +1 -0
  406. package/dist/psych/visitors/to-ruby.d.ts +110 -0
  407. package/dist/psych/visitors/to-ruby.js +396 -0
  408. package/dist/psych/visitors/to-ruby.js.map +1 -0
  409. package/dist/psych/visitors/visitor.d.ts +11 -0
  410. package/dist/psych/visitors/visitor.js +17 -0
  411. package/dist/psych/visitors/visitor.js.map +1 -0
  412. package/dist/psych/visitors/yaml-tree.d.ts +182 -0
  413. package/dist/psych/visitors/yaml-tree.js +593 -0
  414. package/dist/psych/visitors/yaml-tree.js.map +1 -0
  415. package/dist/psych-adapter.d.ts +65 -0
  416. package/dist/psych-adapter.js +121 -0
  417. package/dist/psych-adapter.js.map +1 -0
  418. package/dist/psych-yaml.d.ts +2 -0
  419. package/dist/psych-yaml.js +5 -0
  420. package/dist/psych-yaml.js.map +1 -0
  421. package/dist/psych.d.ts +257 -0
  422. package/dist/psych.js +332 -0
  423. package/dist/psych.js.map +1 -0
  424. package/dist/queue.d.ts +129 -0
  425. package/dist/queue.js +215 -0
  426. package/dist/queue.js.map +1 -0
  427. package/dist/racc/parser.d.ts +70 -0
  428. package/dist/racc/parser.js +206 -0
  429. package/dist/racc/parser.js.map +1 -0
  430. package/dist/range-error.d.ts +15 -0
  431. package/dist/range-error.js +15 -0
  432. package/dist/range-error.js.map +1 -0
  433. package/dist/range.d.ts +166 -0
  434. package/dist/range.js +421 -0
  435. package/dist/range.js.map +1 -0
  436. package/dist/rational.d.ts +167 -0
  437. package/dist/rational.js +379 -0
  438. package/dist/rational.js.map +1 -0
  439. package/dist/rb-config.d.ts +33 -0
  440. package/dist/rb-config.js +53 -0
  441. package/dist/rb-config.js.map +1 -0
  442. package/dist/rb-equal.d.ts +66 -0
  443. package/dist/rb-equal.js +261 -0
  444. package/dist/rb-equal.js.map +1 -0
  445. package/dist/rb-hash.d.ts +26 -0
  446. package/dist/rb-hash.js +108 -0
  447. package/dist/rb-hash.js.map +1 -0
  448. package/dist/regexp.d.ts +82 -0
  449. package/dist/regexp.js +191 -0
  450. package/dist/regexp.js.map +1 -0
  451. package/dist/repl-adapter.d.ts +188 -0
  452. package/dist/repl-adapter.js +388 -0
  453. package/dist/repl-adapter.js.map +1 -0
  454. package/dist/resolv.d.ts +30 -0
  455. package/dist/resolv.js +48 -0
  456. package/dist/resolv.js.map +1 -0
  457. package/dist/ruby-empty.d.ts +28 -0
  458. package/dist/ruby-empty.js +40 -0
  459. package/dist/ruby-empty.js.map +1 -0
  460. package/dist/ruby-platform.d.ts +39 -0
  461. package/dist/ruby-platform.js +49 -0
  462. package/dist/ruby-platform.js.map +1 -0
  463. package/dist/runtime-error.d.ts +15 -0
  464. package/dist/runtime-error.js +16 -0
  465. package/dist/runtime-error.js.map +1 -0
  466. package/dist/scheduled-task.d.ts +73 -0
  467. package/dist/scheduled-task.js +150 -0
  468. package/dist/scheduled-task.js.map +1 -0
  469. package/dist/secure-random.d.ts +33 -0
  470. package/dist/secure-random.js +78 -0
  471. package/dist/secure-random.js.map +1 -0
  472. package/dist/set.d.ts +158 -0
  473. package/dist/set.js +352 -0
  474. package/dist/set.js.map +1 -0
  475. package/dist/shellwords.d.ts +27 -0
  476. package/dist/shellwords.js +53 -0
  477. package/dist/shellwords.js.map +1 -0
  478. package/dist/signal-exception.d.ts +21 -0
  479. package/dist/signal-exception.js +21 -0
  480. package/dist/signal-exception.js.map +1 -0
  481. package/dist/socket.d.ts +230 -0
  482. package/dist/socket.js +484 -0
  483. package/dist/socket.js.map +1 -0
  484. package/dist/standard-error.d.ts +18 -0
  485. package/dist/standard-error.js +23 -0
  486. package/dist/standard-error.js.map +1 -0
  487. package/dist/stop-iteration.d.ts +10 -0
  488. package/dist/stop-iteration.js +10 -0
  489. package/dist/stop-iteration.js.map +1 -0
  490. package/dist/string/b.d.ts +19 -0
  491. package/dist/string/b.js +28 -0
  492. package/dist/string/b.js.map +1 -0
  493. package/dist/string/byte-methods.d.ts +57 -0
  494. package/dist/string/byte-methods.js +266 -0
  495. package/dist/string/byte-methods.js.map +1 -0
  496. package/dist/string/bytes.d.ts +35 -0
  497. package/dist/string/bytes.js +123 -0
  498. package/dist/string/bytes.js.map +1 -0
  499. package/dist/string/case-mapping.d.ts +57 -0
  500. package/dist/string/case-mapping.js +192 -0
  501. package/dist/string/case-mapping.js.map +1 -0
  502. package/dist/string/chomp.d.ts +15 -0
  503. package/dist/string/chomp.js +32 -0
  504. package/dist/string/chomp.js.map +1 -0
  505. package/dist/string/convert.d.ts +55 -0
  506. package/dist/string/convert.js +316 -0
  507. package/dist/string/convert.js.map +1 -0
  508. package/dist/string/delete.d.ts +14 -0
  509. package/dist/string/delete.js +17 -0
  510. package/dist/string/delete.js.map +1 -0
  511. package/dist/string/each.d.ts +108 -0
  512. package/dist/string/each.js +305 -0
  513. package/dist/string/each.js.map +1 -0
  514. package/dist/string/encode.d.ts +37 -0
  515. package/dist/string/encode.js +268 -0
  516. package/dist/string/encode.js.map +1 -0
  517. package/dist/string/force-encoding.d.ts +72 -0
  518. package/dist/string/force-encoding.js +147 -0
  519. package/dist/string/force-encoding.js.map +1 -0
  520. package/dist/string/inspect.d.ts +17 -0
  521. package/dist/string/inspect.js +81 -0
  522. package/dist/string/inspect.js.map +1 -0
  523. package/dist/string/method-table.d.ts +174 -0
  524. package/dist/string/method-table.js +805 -0
  525. package/dist/string/method-table.js.map +1 -0
  526. package/dist/string/scrub.d.ts +12 -0
  527. package/dist/string/scrub.js +33 -0
  528. package/dist/string/scrub.js.map +1 -0
  529. package/dist/string/slice.d.ts +26 -0
  530. package/dist/string/slice.js +73 -0
  531. package/dist/string/slice.js.map +1 -0
  532. package/dist/string/split.d.ts +11 -0
  533. package/dist/string/split.js +44 -0
  534. package/dist/string/split.js.map +1 -0
  535. package/dist/string/sub.d.ts +114 -0
  536. package/dist/string/sub.js +371 -0
  537. package/dist/string/sub.js.map +1 -0
  538. package/dist/string/succ.d.ts +14 -0
  539. package/dist/string/succ.js +118 -0
  540. package/dist/string/succ.js.map +1 -0
  541. package/dist/string/support.d.ts +135 -0
  542. package/dist/string/support.js +283 -0
  543. package/dist/string/support.js.map +1 -0
  544. package/dist/string/tr.d.ts +46 -0
  545. package/dist/string/tr.js +156 -0
  546. package/dist/string/tr.js.map +1 -0
  547. package/dist/string-io.d.ts +166 -0
  548. package/dist/string-io.js +248 -0
  549. package/dist/string-io.js.map +1 -0
  550. package/dist/string-scanner.d.ts +133 -0
  551. package/dist/string-scanner.js +248 -0
  552. package/dist/string-scanner.js.map +1 -0
  553. package/dist/struct.d.ts +54 -0
  554. package/dist/struct.js +222 -0
  555. package/dist/struct.js.map +1 -0
  556. package/dist/symbol.d.ts +48 -0
  557. package/dist/symbol.js +107 -0
  558. package/dist/symbol.js.map +1 -0
  559. package/dist/tempfile.d.ts +173 -0
  560. package/dist/tempfile.js +290 -0
  561. package/dist/tempfile.js.map +1 -0
  562. package/dist/temporal-tag.d.ts +23 -0
  563. package/dist/temporal-tag.js +29 -0
  564. package/dist/temporal-tag.js.map +1 -0
  565. package/dist/thread-error.d.ts +13 -0
  566. package/dist/thread-error.js +13 -0
  567. package/dist/thread-error.js.map +1 -0
  568. package/dist/thread-pool-executor.d.ts +119 -0
  569. package/dist/thread-pool-executor.js +250 -0
  570. package/dist/thread-pool-executor.js.map +1 -0
  571. package/dist/thread.d.ts +211 -0
  572. package/dist/thread.js +495 -0
  573. package/dist/thread.js.map +1 -0
  574. package/dist/timeout.d.ts +29 -0
  575. package/dist/timeout.js +41 -0
  576. package/dist/timeout.js.map +1 -0
  577. package/dist/tse.d.ts +40 -0
  578. package/dist/tse.js +62 -0
  579. package/dist/tse.js.map +1 -0
  580. package/dist/type-error.d.ts +14 -0
  581. package/dist/type-error.js +15 -0
  582. package/dist/type-error.js.map +1 -0
  583. package/dist/undefined-conversion-error.d.ts +10 -0
  584. package/dist/undefined-conversion-error.js +10 -0
  585. package/dist/undefined-conversion-error.js.map +1 -0
  586. package/dist/uri/common.d.ts +209 -0
  587. package/dist/uri/common.js +369 -0
  588. package/dist/uri/common.js.map +1 -0
  589. package/dist/uri/generic.d.ts +283 -0
  590. package/dist/uri/generic.js +810 -0
  591. package/dist/uri/generic.js.map +1 -0
  592. package/dist/uri/http.d.ts +23 -0
  593. package/dist/uri/http.js +30 -0
  594. package/dist/uri/http.js.map +1 -0
  595. package/dist/uri/https.d.ts +13 -0
  596. package/dist/uri/https.js +15 -0
  597. package/dist/uri/https.js.map +1 -0
  598. package/dist/uri/rfc2396-parser.d.ts +70 -0
  599. package/dist/uri/rfc2396-parser.js +264 -0
  600. package/dist/uri/rfc2396-parser.js.map +1 -0
  601. package/dist/uri/rfc3986-parser.d.ts +46 -0
  602. package/dist/uri/rfc3986-parser.js +171 -0
  603. package/dist/uri/rfc3986-parser.js.map +1 -0
  604. package/dist/uri.d.ts +13 -0
  605. package/dist/uri.js +13 -0
  606. package/dist/uri.js.map +1 -0
  607. package/dist/variable.d.ts +183 -0
  608. package/dist/variable.js +463 -0
  609. package/dist/variable.js.map +1 -0
  610. package/dist/verbose.d.ts +21 -0
  611. package/dist/verbose.js +26 -0
  612. package/dist/verbose.js.map +1 -0
  613. package/dist/yaml.d.ts +9 -0
  614. package/dist/yaml.js +9 -0
  615. package/dist/yaml.js.map +1 -0
  616. package/dist/zlib-adapter.d.ts +117 -0
  617. package/dist/zlib-adapter.js +250 -0
  618. package/dist/zlib-adapter.js.map +1 -0
  619. package/dist/zlib.d.ts +248 -0
  620. package/dist/zlib.js +362 -0
  621. package/dist/zlib.js.map +1 -0
  622. package/package.json +82 -3
@@ -0,0 +1,1100 @@
1
+ /**
2
+ * Ruby's core `Enumerable` module (`vendor/ruby/v3.3.11/enum.c:5047` `Init_Enumerable`):
3
+ * members derived from the including class's `each`, mixed in with
4
+ * `include(Klass, Enumerable)`. Where `each` answers a promise, each member
5
+ * answers a promise of its result.
6
+ *
7
+ * Only the members a trails includer reaches are ported; the rest of
8
+ * `Init_Enumerable` joins as a caller needs it.
9
+ */
10
+ import { classModule } from "./class-module.js";
11
+ import { ArgumentError } from "./argument-error.js";
12
+ import { TypeError as RbTypeError } from "./type-error.js";
13
+ import { Hash } from "./hash.js";
14
+ import { numericPlus, rbBigNorm, rbDbl2num, rbFloatTypeP, rbIntegerTypeP, rbPlus, } from "./numeric.js";
15
+ import { rbCheckFuncall, rbFSend, rbObjClassname, rbProcCall } from "./object.js";
16
+ import { Enumerator } from "./enumerator.js";
17
+ import { Thread } from "./thread.js";
18
+ import { Rational } from "./rational.js";
19
+ import { checkArity } from "./string/support.js";
20
+ import { cmp, rbCmpint } from "./comparable.js";
21
+ import { rbEqq, rbEqual } from "./rb-equal.js";
22
+ import { isSymbol, stringToSym, symbolToS } from "./symbol.js";
23
+ const iterBreak = Symbol("rb_iter_break");
24
+ /**
25
+ * `rb_block_call(obj, id_each, …)`: an `each` member where the receiver has
26
+ * one, else its JS iterator, which is how an Array (`rb_ary_each`,
27
+ * `vendor/ruby/v3.3.11/array.c:2532`), a Set or a generator yields, and a Map
28
+ * yields `[key, value]` as `rb_hash_each_pair` does (`vendor/ruby/v3.3.11/hash.c:3149`).
29
+ * An `each` member's multi-value yield reaches the block packed into one
30
+ * Array, as `ENUM_WANT_SVALUE` packs it (`rb_enum_values_pack`,
31
+ * `vendor/ruby/v3.3.11/enum.c:53`).
32
+ */
33
+ function rbBlockCall(obj, block, result, awaiting = false) {
34
+ const rescue = (e) => {
35
+ if (e !== iterBreak)
36
+ throw e;
37
+ return result();
38
+ };
39
+ if (awaiting && typeof obj.each === "function") {
40
+ let pending = null;
41
+ const rest = [];
42
+ return rbBlockCall(obj, (i, argv) => {
43
+ if (pending)
44
+ return void rest.push([i, argv]);
45
+ const r = block(i, argv);
46
+ if (r != null && typeof r.then === "function") {
47
+ pending = r;
48
+ }
49
+ }, () => {
50
+ if (!pending)
51
+ return result();
52
+ const awaited = pending;
53
+ return (async () => {
54
+ await awaited;
55
+ for (const [i, argv] of rest)
56
+ await block(i, argv);
57
+ return result();
58
+ })();
59
+ });
60
+ }
61
+ let each;
62
+ try {
63
+ if (typeof obj.each === "function") {
64
+ each = obj.each((...argv) => block(argv.length === 0 ? null : argv.length === 1 ? argv[0] : argv, argv));
65
+ }
66
+ else if (awaiting) {
67
+ const it = obj[Symbol.iterator]();
68
+ for (let step = it.next(); !step.done; step = it.next()) {
69
+ const r = block(step.value, [step.value]);
70
+ if (r != null && typeof r.then === "function") {
71
+ each = (async () => {
72
+ await r;
73
+ for (let step = it.next(); !step.done; step = it.next())
74
+ await block(step.value, [step.value]);
75
+ })();
76
+ break;
77
+ }
78
+ }
79
+ }
80
+ else {
81
+ for (const i of obj)
82
+ block(i, [i]);
83
+ }
84
+ }
85
+ catch (e) {
86
+ return rescue(e);
87
+ }
88
+ if (each instanceof Promise)
89
+ return each.then(result, rescue);
90
+ if (each != null && typeof each.then === "function") {
91
+ return Promise.resolve(each).then(result, rescue);
92
+ }
93
+ return result();
94
+ }
95
+ /**
96
+ * `rb_yield` (`vendor/ruby/v3.3.11/vm_eval.c:1376`): one value to the block,
97
+ * splatted across its parameters when it is an Array and the block takes more
98
+ * than one, as `vm_callee_setup_block_arg_arg0_splat`
99
+ * (`vendor/ruby/v3.3.11/vm_insnhelper.c:4807`) does. A JS function's `length`
100
+ * stands in for the iseq's `lead_num`; it does not count a defaulted or rest
101
+ * parameter (CLAUDE.md, "Runtime facts Node does not expose", arity -1).
102
+ * @noRailsEquivalent PERMANENT
103
+ */
104
+ export function rbYield(block, val) {
105
+ const yielder = block;
106
+ if (Array.isArray(val) && block.length > 1)
107
+ return yielder(...val);
108
+ return yielder(val);
109
+ }
110
+ /**
111
+ * `enum_to_a` (`vendor/ruby/v3.3.11/enum.c:711`): the elements `each` yields,
112
+ * which is what a block-less member's enumerator (`RETURN_ENUMERATOR`) holds.
113
+ * @noRailsEquivalent PERMANENT
114
+ */
115
+ function enumToA(obj) {
116
+ const ary = [];
117
+ return rbBlockCall(obj, (i) => {
118
+ ary.push(i);
119
+ }, () => ary);
120
+ }
121
+ /** @noRailsEquivalent PERMANENT */
122
+ export function partition(obj, block) {
123
+ if (!block)
124
+ return enumToA(obj);
125
+ const memo = { v1: [], v2: [] };
126
+ return rbBlockCall(obj, (i) => {
127
+ const result = rbYield(block, i);
128
+ if (result != null && result !== false)
129
+ memo.v1.push(i);
130
+ else
131
+ memo.v2.push(i);
132
+ }, () => [memo.v1, memo.v2]);
133
+ }
134
+ /** @noRailsEquivalent PERMANENT */
135
+ export function groupBy(obj, block) {
136
+ if (!block)
137
+ return enumToA(obj);
138
+ const hash = new Hash();
139
+ return rbBlockCall(obj, (i) => {
140
+ const group = rbYield(block, i);
141
+ const values = hash.get(group);
142
+ if (values === undefined)
143
+ hash.set(group, [i]);
144
+ else
145
+ values.push(i);
146
+ }, () => hash);
147
+ }
148
+ /**
149
+ * Mirrors: Ruby's Enumerable#tally — `vendor/ruby/v3.3.11/enum.c:1229` `enum_tally`: a
150
+ * Hash counting each element (`tally_up`, `:1165`). The `hash` argument arm is
151
+ * not ported: nothing passes one.
152
+ * @noRailsEquivalent PERMANENT
153
+ */
154
+ export function tally(obj) {
155
+ const hash = new Hash();
156
+ return rbBlockCall(obj, (i) => {
157
+ const tally = hash.get(i);
158
+ hash.set(i, tally === undefined ? 1 : tally + 1);
159
+ }, () => hash);
160
+ }
161
+ /**
162
+ * Mirrors: Ruby's Enumerable#find_all — `vendor/ruby/v3.3.11/enum.c:509` `enum_find_all`,
163
+ * pushing each element whose block result `RTEST`s (`find_all_i`, `:456`).
164
+ * @noRailsEquivalent PERMANENT
165
+ */
166
+ function enumFindAll(obj, block) {
167
+ if (!block)
168
+ return enumToA(obj);
169
+ const ary = [];
170
+ return rbBlockCall(obj, (i) => {
171
+ const result = rbYield(block, i);
172
+ if (result != null && result !== false)
173
+ ary.push(i);
174
+ }, () => ary);
175
+ }
176
+ export { enumFindAll as findAll, enumFindAll as select };
177
+ /**
178
+ * Mirrors: Ruby's Enumerable#grep — `vendor/ruby/v3.3.11/enum.c:173` `enum_grep`: each
179
+ * element for which `pattern === elem` holds (`grep_i`), mapped through the block when
180
+ * one is given (`grep_iter_i`).
181
+ * @noRailsEquivalent PERMANENT
182
+ */
183
+ export function grep(obj, pattern, block) {
184
+ const ary = [];
185
+ return rbBlockCall(obj, (i) => {
186
+ if (rbEqq(pattern, i))
187
+ ary.push(block ? rbYield(block, i) : i);
188
+ }, () => ary);
189
+ }
190
+ export { enumToA as toA };
191
+ /**
192
+ * Mirrors: Ruby's Enumerable#reject — `vendor/ruby/v3.3.11/enum.c:593` `enum_reject`,
193
+ * pushing each element whose block result does not `RTEST` (`reject_i`, `:564`).
194
+ * @noRailsEquivalent PERMANENT
195
+ */
196
+ export function reject(obj, block) {
197
+ if (!block)
198
+ return enumToA(obj);
199
+ const ary = [];
200
+ return rbBlockCall(obj, (i) => {
201
+ const result = rbYield(block, i);
202
+ if (result == null || result === false)
203
+ ary.push(i);
204
+ }, () => ary);
205
+ }
206
+ /**
207
+ * Mirrors: Ruby's Enumerable#count — `vendor/ruby/v3.3.11/enum.c:298` `enum_count`:
208
+ * every element (`count_all_i`, `:263`), those `rb_equal` to the argument
209
+ * (`count_i`, `:239`), or those whose block result `RTEST`s (`count_iter_i`,
210
+ * `:252`). The block is the trailing function argument.
211
+ * @noRailsEquivalent PERMANENT
212
+ */
213
+ export function count(obj, ...argv) {
214
+ const block = argv.length === 1 && typeof argv[0] === "function"
215
+ ? argv.pop()
216
+ : undefined;
217
+ checkArity(argv.length, 0, 1);
218
+ const item = argv[0];
219
+ let func;
220
+ if (argv.length === 0) {
221
+ if (block !== undefined) {
222
+ func = (i) => {
223
+ const result = rbYield(block, i);
224
+ return result != null && result !== false;
225
+ };
226
+ }
227
+ else {
228
+ func = () => true;
229
+ }
230
+ }
231
+ else {
232
+ func = (i) => rbEqual(i, item);
233
+ }
234
+ let n = 0;
235
+ return rbBlockCall(obj, (i) => {
236
+ if (func(i))
237
+ n++;
238
+ }, () => n);
239
+ }
240
+ /**
241
+ * Mirrors: Ruby's Enumerable#filter_map — `vendor/ruby/v3.3.11/enum.c:550` `enum_filter_map`,
242
+ * pushing each block result that `RTEST`s (`filter_map_i`, `:522`).
243
+ * @noRailsEquivalent PERMANENT
244
+ */
245
+ export function filterMap(obj, block) {
246
+ const ary = [];
247
+ return rbBlockCall(obj, (i) => {
248
+ const result = rbYield(block, i);
249
+ if (result != null && result !== false)
250
+ ary.push(result);
251
+ }, () => ary);
252
+ }
253
+ /**
254
+ * Mirrors: Ruby's Enumerable#find — `vendor/ruby/v3.3.11/enum.c:361` `enum_find`,
255
+ * breaking out of `each` at the first element whose block result `RTEST`s
256
+ * (`find_i`, `:324`). The block is the last argument.
257
+ * @noRailsEquivalent PERMANENT
258
+ */
259
+ export function find(obj, ...argv) {
260
+ const block = argv.pop();
261
+ checkArity(argv.length, 0, 1);
262
+ const ifNone = argv.length > 0 ? argv[0] : null;
263
+ const memo = { v1: null, cnt: 0 };
264
+ return rbBlockCall(obj, (i) => {
265
+ const result = rbYield(block, i);
266
+ if (result != null && result !== false) {
267
+ memo.v1 = i;
268
+ memo.cnt = 1;
269
+ throw iterBreak;
270
+ }
271
+ }, () => {
272
+ if (memo.cnt)
273
+ return memo.v1;
274
+ if (ifNone != null)
275
+ return rbProcCall(ifNone);
276
+ return null;
277
+ });
278
+ }
279
+ /** @noRailsEquivalent PERMANENT */
280
+ export function map(obj, block) {
281
+ if (!block) {
282
+ return new Enumerator({ map: (block) => map(obj, block) }, "map", [], () => enumSize(obj));
283
+ }
284
+ const ary = [];
285
+ return rbBlockCall(obj, (_i, argv) => {
286
+ const args = argv.length === 1 && Array.isArray(argv[0]) && block.length > 1 ? argv[0] : argv;
287
+ ary.push(block(...args));
288
+ }, () => ary);
289
+ }
290
+ /** @noRailsEquivalent PERMANENT */
291
+ export function first(obj, n) {
292
+ if (n !== undefined) {
293
+ if (n < 0)
294
+ throw new ArgumentError("attempt to take negative size");
295
+ const result = [];
296
+ if (n === 0)
297
+ return result;
298
+ return rbBlockCall(obj, (i) => {
299
+ result.push(i);
300
+ if (result.length >= n)
301
+ throw iterBreak;
302
+ }, () => result);
303
+ }
304
+ let memo = null;
305
+ return rbBlockCall(obj, (i) => {
306
+ memo = i;
307
+ throw iterBreak;
308
+ }, () => memo);
309
+ }
310
+ /**
311
+ * Mirrors: Ruby's Enumerable#take — `vendor/ruby/v3.3.11/enum.c:3514` `enum_take`, whose
312
+ * `take_i` (`:3490`) breaks once `n` elements are pushed, so an endless `each` stops.
313
+ * @noRailsEquivalent PERMANENT
314
+ */
315
+ export function take(obj, n) {
316
+ if (n < 0)
317
+ throw new ArgumentError("attempt to take negative size");
318
+ const result = [];
319
+ if (n === 0)
320
+ return result;
321
+ return rbBlockCall(obj, (i) => {
322
+ result.push(i);
323
+ if (result.length >= n)
324
+ throw iterBreak;
325
+ }, () => result);
326
+ }
327
+ /**
328
+ * Mirrors: Ruby's Enumerable#take_while — `vendor/ruby/v3.3.11/enum.c:3560` `enum_take_while`,
329
+ * whose `take_while_i` (`:3533`) breaks at the first element the block answers falsy for.
330
+ * @noRailsEquivalent PERMANENT
331
+ */
332
+ export function takeWhile(obj, block) {
333
+ const ary = [];
334
+ return rbBlockCall(obj, (i) => {
335
+ const r = rbYield(block, i);
336
+ if (r == null || r === false)
337
+ throw iterBreak;
338
+ ary.push(i);
339
+ }, () => ary);
340
+ }
341
+ /**
342
+ * Mirrors: Ruby's Enumerable#drop — `vendor/ruby/v3.3.11/enum.c:3603` `enum_drop`, whose
343
+ * `drop_i` (`:3571`) counts `n` elements down before it pushes.
344
+ * @noRailsEquivalent PERMANENT
345
+ */
346
+ export function drop(obj, n) {
347
+ let len = n;
348
+ if (len < 0) {
349
+ throw new ArgumentError("attempt to drop negative size");
350
+ }
351
+ const result = [];
352
+ return rbBlockCall(obj, (i) => {
353
+ if (len === 0) {
354
+ result.push(i);
355
+ }
356
+ else {
357
+ len--;
358
+ }
359
+ }, () => result);
360
+ }
361
+ /** @noRailsEquivalent PERMANENT */
362
+ export function eachWithIndex(obj, block) {
363
+ if (!block) {
364
+ return new Enumerator({ eachWithIndex: (block) => eachWithIndex(obj, block) }, "eachWithIndex", [], () => enumSize(obj));
365
+ }
366
+ let n = 0;
367
+ return rbBlockCall(obj, (i) => block(i, n++), () => obj, true);
368
+ }
369
+ /** @noRailsEquivalent PERMANENT */
370
+ export function eachWithObject(obj, memo, block) {
371
+ if (!block) {
372
+ return new Enumerator({
373
+ eachWithObject: (memo, block) => eachWithObject(obj, memo, block),
374
+ }, "eachWithObject", [memo], () => enumSize(obj));
375
+ }
376
+ return rbBlockCall(obj, (i) => block(i, memo), () => memo, true);
377
+ }
378
+ /**
379
+ * Mirrors: Ruby's Enumerable#sort_by — `vendor/ruby/v3.3.11/enum.c:1651` `enum_sort_by`,
380
+ * which pairs each element with its block value (`sort_by_i`) and sorts the
381
+ * pairs by `<=>` on the values (`sort_by_cmp`, `:1379`).
382
+ * @noRailsEquivalent PERMANENT
383
+ */
384
+ export function sortBy(obj, block) {
385
+ if (!block)
386
+ return enumToA(obj);
387
+ const buf = [];
388
+ return rbBlockCall(obj, (i) => {
389
+ buf.push([rbYield(block, i), i]);
390
+ }, () => buf.sort(([a], [b]) => rbCmpint(cmp(a, b), a, b)).map(([, i]) => i));
391
+ }
392
+ /** @noRailsEquivalent PERMANENT */
393
+ export function eachSlice(obj, n, block) {
394
+ const size = Math.trunc(n);
395
+ if (size <= 0)
396
+ throw new ArgumentError("invalid slice size");
397
+ if (!block) {
398
+ return new Enumerator({ eachSlice: (n, block) => eachSlice(obj, n, block) }, "eachSlice", [n], (...args) => enumEachSliceSize(obj, args));
399
+ }
400
+ let ary = [];
401
+ return rbBlockCall(obj, (i) => {
402
+ ary.push(i);
403
+ if (ary.length === size) {
404
+ block(ary);
405
+ ary = [];
406
+ }
407
+ }, () => {
408
+ if (ary.length > 0)
409
+ block(ary);
410
+ return obj;
411
+ });
412
+ }
413
+ /** @noRailsEquivalent PERMANENT */
414
+ export function minBy(obj, ...argv) {
415
+ const block = typeof argv.at(-1) === "function" ? argv.pop() : null;
416
+ checkArity(argv.length, 0, 1);
417
+ if (!block) {
418
+ return new Enumerator({ minBy: (...argv) => minBy(obj, ...argv) }, "minBy", argv, () => enumSize(obj));
419
+ }
420
+ const num = argv[0];
421
+ if (argv.length > 0 && num != null) {
422
+ const size = Math.trunc(num);
423
+ if (size < 0)
424
+ throw new ArgumentError(`negative size (${size})`);
425
+ const buf = [];
426
+ return rbBlockCall(obj, (i) => {
427
+ buf.push([rbYield(block, i), i]);
428
+ }, () => buf
429
+ .sort(([a], [b]) => rbCmpint(cmp(a, b), a, b))
430
+ .slice(0, size)
431
+ .map(([, i]) => i));
432
+ }
433
+ let v1;
434
+ let v2 = null;
435
+ let seen = false;
436
+ return rbBlockCall(obj, (i) => {
437
+ const v = rbYield(block, i);
438
+ if (!seen) {
439
+ seen = true;
440
+ v1 = v;
441
+ v2 = i;
442
+ }
443
+ else if (rbCmpint(cmp(v, v1), v, v1) < 0) {
444
+ v1 = v;
445
+ v2 = i;
446
+ }
447
+ }, () => v2);
448
+ }
449
+ /** @noRailsEquivalent PERMANENT */
450
+ export function maxBy(obj, ...argv) {
451
+ const block = typeof argv.at(-1) === "function" ? argv.pop() : null;
452
+ checkArity(argv.length, 0, 1);
453
+ if (!block) {
454
+ return new Enumerator({ maxBy: (...argv) => maxBy(obj, ...argv) }, "maxBy", argv, () => enumSize(obj));
455
+ }
456
+ const num = argv[0];
457
+ if (argv.length > 0 && num != null) {
458
+ const size = Math.trunc(num);
459
+ if (size < 0)
460
+ throw new ArgumentError(`negative size (${size})`);
461
+ const buf = [];
462
+ return rbBlockCall(obj, (i) => {
463
+ buf.push([rbYield(block, i), i]);
464
+ }, () => buf
465
+ .sort(([a], [b]) => rbCmpint(cmp(b, a), b, a))
466
+ .slice(0, size)
467
+ .map(([, i]) => i));
468
+ }
469
+ let v1;
470
+ let v2 = null;
471
+ let seen = false;
472
+ return rbBlockCall(obj, (i) => {
473
+ const v = rbYield(block, i);
474
+ if (!seen) {
475
+ seen = true;
476
+ v1 = v;
477
+ v2 = i;
478
+ }
479
+ else if (rbCmpint(cmp(v, v1), v, v1) > 0) {
480
+ v1 = v;
481
+ v2 = i;
482
+ }
483
+ }, () => v2);
484
+ }
485
+ /** @noRailsEquivalent PERMANENT */
486
+ export function eachCons(obj, n, block) {
487
+ const size = Math.trunc(n);
488
+ if (size <= 0)
489
+ throw new ArgumentError("invalid size");
490
+ if (!block) {
491
+ return new Enumerator({ eachCons: (n, block) => eachCons(obj, n, block) }, "eachCons", [n], (...args) => enumEachConsSize(obj, args));
492
+ }
493
+ const ary = [];
494
+ return rbBlockCall(obj, (i) => {
495
+ if (ary.length === size)
496
+ ary.shift();
497
+ ary.push(i);
498
+ if (ary.length === size)
499
+ block([...ary]);
500
+ }, () => obj);
501
+ }
502
+ /** Mirrors MRI `enum_size` (`vendor/ruby/v3.3.11/enum.c:467`). */
503
+ function enumSize(obj) {
504
+ return Array.isArray(obj) ? obj.length : (rbCheckFuncall(obj, "size") ?? null);
505
+ }
506
+ /** Mirrors MRI `enum_each_slice_size` (`vendor/ruby/v3.3.11/enum.c:3127`). */
507
+ function enumEachSliceSize(obj, args) {
508
+ const sliceSize = Math.trunc(args[0]);
509
+ if (sliceSize <= 0)
510
+ throw new ArgumentError("invalid slice size");
511
+ const size = enumSize(obj);
512
+ if (size == null)
513
+ return null;
514
+ if (size === Infinity)
515
+ return size;
516
+ return Math.floor((size + sliceSize - 1) / sliceSize);
517
+ }
518
+ /** Mirrors MRI `enum_each_cons_size` (`vendor/ruby/v3.3.11/enum.c:3209`). */
519
+ function enumEachConsSize(obj, args) {
520
+ const consSize = Math.trunc(args[0]);
521
+ if (consSize <= 0)
522
+ throw new ArgumentError("invalid size");
523
+ const size = enumSize(obj);
524
+ if (size == null)
525
+ return null;
526
+ return Math.max(size + 1 - consSize, 0);
527
+ }
528
+ function enumfunc(args) {
529
+ checkArity(args.length, 0, 1);
530
+ return args.length > 0 ? (i) => rbEqq(args[0], i) : (i) => i;
531
+ }
532
+ /**
533
+ * Mirrors: Ruby's Enumerable#all? — `vendor/ruby/v3.3.11/enum.c:1799` `enum_all`,
534
+ * breaking on the first element whose `pattern === element`, or the element
535
+ * itself with no argument, fails `RTEST`.
536
+ * @noRailsEquivalent PERMANENT
537
+ */
538
+ export function isAll(obj, ...args) {
539
+ const func = enumfunc(args);
540
+ let memo = true;
541
+ return rbBlockCall(obj, (i) => {
542
+ const result = func(i);
543
+ if (result == null || result === false) {
544
+ memo = false;
545
+ throw iterBreak;
546
+ }
547
+ }, () => memo);
548
+ }
549
+ /**
550
+ * Mirrors: Ruby's Enumerable#any? — `vendor/ruby/v3.3.11/enum.c:1861` `enum_any`,
551
+ * `RTEST`ing `pattern === element`, or the element itself with no argument.
552
+ * @noRailsEquivalent PERMANENT
553
+ */
554
+ export function isAny(obj, ...args) {
555
+ const func = enumfunc(args);
556
+ let memo = false;
557
+ return rbBlockCall(obj, (i) => {
558
+ const result = func(i);
559
+ if (result != null && result !== false) {
560
+ memo = true;
561
+ throw iterBreak;
562
+ }
563
+ }, () => memo);
564
+ }
565
+ /**
566
+ * Mirrors: Ruby's Enumerable#one? — `vendor/ruby/v3.3.11/enum.c:2148` `enum_one`, which
567
+ * breaks on the second match (`:1869`).
568
+ * @noRailsEquivalent PERMANENT
569
+ */
570
+ export function isOne(obj, ...args) {
571
+ const func = enumfunc(args);
572
+ let memo = undefined;
573
+ return rbBlockCall(obj, (i) => {
574
+ const result = func(i);
575
+ if (result != null && result !== false) {
576
+ if (memo === undefined) {
577
+ memo = true;
578
+ }
579
+ else if (memo === true) {
580
+ memo = false;
581
+ throw iterBreak;
582
+ }
583
+ }
584
+ }, () => memo === true);
585
+ }
586
+ /**
587
+ * Mirrors: Ruby's Enumerable#none? — `vendor/ruby/v3.3.11/enum.c:2210` `enum_none`
588
+ * (`:2160`).
589
+ * @noRailsEquivalent PERMANENT
590
+ */
591
+ export function isNone(obj, ...args) {
592
+ const func = enumfunc(args);
593
+ let memo = true;
594
+ return rbBlockCall(obj, (i) => {
595
+ const result = func(i);
596
+ if (result != null && result !== false) {
597
+ memo = false;
598
+ throw iterBreak;
599
+ }
600
+ }, () => memo);
601
+ }
602
+ /**
603
+ * Mirrors: Ruby's Enumerable#include? — `vendor/ruby/v3.3.11/enum.c:2921` `enum_member`,
604
+ * whose `member_i` (`:2892`) asks `rb_equal(element, val)` and breaks on the first hit.
605
+ * @noRailsEquivalent PERMANENT
606
+ */
607
+ export function isInclude(obj, val) {
608
+ let memo = false;
609
+ return rbBlockCall(obj, (i) => {
610
+ if (rbEqual(i, val)) {
611
+ memo = true;
612
+ throw iterBreak;
613
+ }
614
+ }, () => memo);
615
+ }
616
+ /**
617
+ * The JS spelling of what `for x in enum` / `*enum` read off `each`:
618
+ * `vendor/ruby/v3.3.11/enum.c:711` `enum_to_a`, iterated. An `each` that
619
+ * answers a promise has yielded nothing yet, so it raises.
620
+ * @noRailsEquivalent PERMANENT
621
+ */
622
+ function iterator() {
623
+ const ary = enumToA(this);
624
+ if (ary instanceof Promise) {
625
+ new Thread(() => ary);
626
+ throw new TypeError("each is asynchronous: await it before iterating");
627
+ }
628
+ return ary[Symbol.iterator]();
629
+ }
630
+ function sumIterNormalizeMemo(memo) {
631
+ memo.v = numericPlus(memo.n, memo.v);
632
+ memo.n = 0;
633
+ if (memo.r !== undefined)
634
+ memo.v = numericPlus(memo.r, memo.v);
635
+ memo.r = undefined;
636
+ }
637
+ function sumIterFixnum(i, memo) {
638
+ if (Number.isSafeInteger(memo.n + i)) {
639
+ memo.n += i;
640
+ }
641
+ else {
642
+ memo.v = numericPlus(rbBigNorm(BigInt(memo.n) + BigInt(i)), memo.v);
643
+ memo.n = 0;
644
+ }
645
+ }
646
+ function sumIterBignum(i, memo) {
647
+ memo.v = numericPlus(i, memo.v);
648
+ }
649
+ function sumIterRational(i, memo) {
650
+ if (memo.r === undefined)
651
+ memo.r = i;
652
+ else
653
+ memo.r = memo.r.add(i);
654
+ }
655
+ /** `sum_iter_some_value` (`vendor/ruby/v3.3.11/enum.c:4581`): `memo->v + i`. */
656
+ function sumIterSomeValue(i, memo) {
657
+ memo.v = rbPlus(memo.v, i);
658
+ }
659
+ function sumIterKahanBabuska(i, memo) {
660
+ let x;
661
+ if (rbFloatTypeP(i))
662
+ x = i.valueOf();
663
+ else if (typeof i === "number")
664
+ x = i;
665
+ else if (typeof i === "bigint")
666
+ x = Number(i);
667
+ else if (i instanceof Rational)
668
+ x = i.toF();
669
+ else {
670
+ memo.v = rbDbl2num(memo.f);
671
+ memo.floatValue = false;
672
+ sumIterSomeValue(i, memo);
673
+ return;
674
+ }
675
+ const f = memo.f;
676
+ if (Number.isNaN(f))
677
+ return;
678
+ else if (!Number.isFinite(x)) {
679
+ if (!Number.isNaN(x) && !Number.isFinite(f) && x > 0 !== f > 0) {
680
+ i = rbDbl2num(f);
681
+ x = NaN;
682
+ }
683
+ memo.v = i;
684
+ memo.f = x;
685
+ return;
686
+ }
687
+ else if (!Number.isFinite(f))
688
+ return;
689
+ let c = memo.c;
690
+ const t = f + x;
691
+ if (Math.abs(f) >= Math.abs(x))
692
+ c += f - t + x;
693
+ else
694
+ c += x - t + f;
695
+ memo.f = t;
696
+ memo.c = c;
697
+ }
698
+ function sumIter(i, memo) {
699
+ if (memo.floatValue) {
700
+ sumIterKahanBabuska(i, memo);
701
+ }
702
+ else if (rbIntegerTypeP(memo.v) || rbFloatTypeP(memo.v) || memo.v instanceof Rational) {
703
+ if (typeof i === "number" && Number.isInteger(i))
704
+ sumIterFixnum(i, memo);
705
+ else if (typeof i === "bigint")
706
+ sumIterBignum(i, memo);
707
+ else if (i instanceof Rational)
708
+ sumIterRational(i, memo);
709
+ else if (rbFloatTypeP(i)) {
710
+ sumIterNormalizeMemo(memo);
711
+ memo.f = memo.v instanceof Rational ? memo.v.toF() : Number(memo.v.valueOf());
712
+ memo.c = 0.0;
713
+ memo.floatValue = true;
714
+ sumIterKahanBabuska(i, memo);
715
+ }
716
+ else {
717
+ sumIterNormalizeMemo(memo);
718
+ sumIterSomeValue(i, memo);
719
+ }
720
+ }
721
+ else {
722
+ sumIterSomeValue(i, memo);
723
+ }
724
+ }
725
+ function enumSumMemo(args) {
726
+ const block = typeof args[args.length - 1] === "function"
727
+ ? args.pop()
728
+ : undefined;
729
+ if (args.length > 1) {
730
+ throw new ArgumentError(`wrong number of arguments (given ${args.length}, expected 0..1)`);
731
+ }
732
+ const memo = {
733
+ v: args.length === 0 ? 0 : args[0],
734
+ blockGiven: block !== undefined,
735
+ n: 0,
736
+ r: undefined,
737
+ f: 0.0,
738
+ c: 0.0,
739
+ floatValue: false,
740
+ };
741
+ if ((memo.floatValue = rbFloatTypeP(memo.v))) {
742
+ memo.f = memo.v.valueOf();
743
+ memo.c = 0.0;
744
+ }
745
+ return [memo, block];
746
+ }
747
+ function enumSumValue(memo) {
748
+ if (memo.floatValue) {
749
+ return rbDbl2num(memo.f + memo.c);
750
+ }
751
+ else {
752
+ if (memo.n !== 0)
753
+ memo.v = numericPlus(memo.n, memo.v);
754
+ if (memo.r !== undefined)
755
+ memo.v = numericPlus(memo.r, memo.v);
756
+ return memo.v;
757
+ }
758
+ }
759
+ /**
760
+ * Mirrors: Ruby's Enumerable#sum — `vendor/ruby/v3.3.11/enum.c:4753` `enum_sum`. The
761
+ * block is the trailing function argument, so a function cannot be the initial
762
+ * value. The Range arm (`int_range_sum`, `:4706`) is the caller's, and no
763
+ * includer is a Hash.
764
+ * @noRailsEquivalent PERMANENT
765
+ */
766
+ export function sum(obj, ...args) {
767
+ const [memo, block] = enumSumMemo(args);
768
+ return rbBlockCall(obj, (i) => {
769
+ sumIter(memo.blockGiven ? block(i) : i, memo);
770
+ }, () => enumSumValue(memo));
771
+ }
772
+ const undef = Symbol("Qundef");
773
+ /** `inject_i` (`vendor/ruby/v3.3.11/enum.c:775`). */
774
+ function injectI(i, memo) {
775
+ if (memo.v1 === undef) {
776
+ memo.v1 = i;
777
+ }
778
+ else {
779
+ memo.v1 = memo.block(memo.v1, i);
780
+ }
781
+ }
782
+ /** `inject_op_i` (`vendor/ruby/v3.3.11/enum.c:791`). */
783
+ function injectOpI(i, memo) {
784
+ const name = memo.op;
785
+ if (memo.v1 === undef) {
786
+ memo.v1 = i;
787
+ }
788
+ else if (isSymbol(name)) {
789
+ memo.v1 = rbFSend(memo.v1, name, i);
790
+ }
791
+ else {
792
+ memo.v1 = rbFSend(memo.v1, name, i);
793
+ }
794
+ }
795
+ /** `ary_inject_op` (`vendor/ruby/v3.3.11/enum.c:815`). */
796
+ function aryInjectOp(ary, init, op) {
797
+ let v;
798
+ let i;
799
+ if (ary.length === 0)
800
+ return init === undef ? null : init;
801
+ if (init === undef) {
802
+ v = ary[0];
803
+ i = 1;
804
+ if (ary.length === 1)
805
+ return v;
806
+ }
807
+ else {
808
+ v = init;
809
+ i = 0;
810
+ }
811
+ if (symbolToS(op) === "+") {
812
+ if (rbIntegerTypeP(v)) {
813
+ for (; i < ary.length; i++) {
814
+ const e = ary[i];
815
+ if (!rbIntegerTypeP(e))
816
+ break;
817
+ v = numericPlus(v, e);
818
+ }
819
+ }
820
+ }
821
+ for (; i < ary.length; i++) {
822
+ v = rbFSend(v, op, ary[i]);
823
+ }
824
+ return v;
825
+ }
826
+ /**
827
+ * Mirrors: Ruby's Enumerable#reduce — `vendor/ruby/v3.3.11/enum.c:1005` `enum_inject`,
828
+ * bound as `reduce` at `:5085`. The receiver is the first argument, and the
829
+ * block is the trailing function argument. `rb_check_id` turns a String naming a method into its Symbol,
830
+ * which every String here does; `rb_warning("given block not used")` prints
831
+ * only under `$VERBOSE`.
832
+ * Unported: the `rb_method_basic_definition_p` checks on `each` (`:1044`) and
833
+ * on `Integer#+` (`:836`), which ask whether a core method was redefined.
834
+ * @noRailsEquivalent PERMANENT
835
+ */
836
+ export function reduce(obj, ...argv) {
837
+ const block = typeof argv[argv.length - 1] === "function"
838
+ ? argv.pop()
839
+ : undefined;
840
+ let init;
841
+ let op;
842
+ let iter = injectI;
843
+ if (block !== undefined) {
844
+ checkArity(argv.length, 0, 2);
845
+ }
846
+ else {
847
+ checkArity(argv.length, 1, 2);
848
+ }
849
+ [init, op] = argv;
850
+ switch (argv.length) {
851
+ case 0:
852
+ init = undef;
853
+ break;
854
+ case 1:
855
+ if (block !== undefined) {
856
+ break;
857
+ }
858
+ op = typeof init === "string" ? stringToSym(init) : init;
859
+ init = undef;
860
+ iter = injectOpI;
861
+ break;
862
+ case 2:
863
+ if (typeof op === "string")
864
+ op = stringToSym(op);
865
+ iter = injectOpI;
866
+ break;
867
+ }
868
+ if (iter === injectOpI && isSymbol(op) && Array.isArray(obj)) {
869
+ return aryInjectOp(obj, init, op);
870
+ }
871
+ const memo = { v1: init, block, op };
872
+ return rbBlockCall(obj, (i) => iter(i, memo), () => (memo.v1 === undef ? null : memo.v1));
873
+ }
874
+ /**
875
+ * Ruby's `Enumerable` (`vendor/ruby/v3.3.11/enum.c:5047` `Init_Enumerable`) as
876
+ * a class module: `include(Klass, Enumerable)` copies its prototype members
877
+ * onto `Klass`, and `new Enumerable(xs)` wraps any Array, Set, Map, generator
878
+ * or `each`-answerer, so `new Enumerable(xs).partition(fn)` is Ruby's
879
+ * `xs.partition(&fn)`. Every member is the free function of the same name over
880
+ * `this`, and one answering a collection answers an Array or `Hash`.
881
+ * @noRailsEquivalent PERMANENT
882
+ */
883
+ export class Enumerable {
884
+ /** @noRailsEquivalent PERMANENT */
885
+ static [classModule] = true;
886
+ /** @noRailsEquivalent PERMANENT */
887
+ constructor(obj) {
888
+ Object.defineProperty(this, "each", {
889
+ value: (block) => {
890
+ if (typeof obj.each === "function") {
891
+ return obj.each(block);
892
+ }
893
+ for (const i of obj)
894
+ block(i);
895
+ return obj;
896
+ },
897
+ });
898
+ Object.defineProperty(this, Symbol.asyncIterator, {
899
+ value: async function* () {
900
+ yield* (await enumToA(this));
901
+ },
902
+ });
903
+ }
904
+ find(...argv) {
905
+ return find(this, ...argv);
906
+ }
907
+ /** @noRailsEquivalent PERMANENT */
908
+ findAll(block) {
909
+ return enumFindAll(this, block);
910
+ }
911
+ grep(pattern, block) {
912
+ return grep(this, pattern, block);
913
+ }
914
+ map(block) {
915
+ return block ? map(this, block) : map(this);
916
+ }
917
+ groupBy(block) {
918
+ return groupBy(this, block);
919
+ }
920
+ partition(block) {
921
+ return block ? partition(this, block) : partition(this);
922
+ }
923
+ tally() {
924
+ return tally(this);
925
+ }
926
+ reject(block) {
927
+ return reject(this, block);
928
+ }
929
+ filterMap(block) {
930
+ return filterMap(this, block);
931
+ }
932
+ first(n) {
933
+ return n === undefined ? first(this) : first(this, n);
934
+ }
935
+ drop(n) {
936
+ return drop(this, n);
937
+ }
938
+ take(n) {
939
+ return take(this, n);
940
+ }
941
+ takeWhile(block) {
942
+ return takeWhile(this, block);
943
+ }
944
+ eachSlice(n, block) {
945
+ return block ? eachSlice(this, n, block) : eachSlice(this, n);
946
+ }
947
+ sortBy(block) {
948
+ return sortBy(this, block);
949
+ }
950
+ isAll(...args) {
951
+ return isAll(this, ...args);
952
+ }
953
+ isAny(...args) {
954
+ return isAny(this, ...args);
955
+ }
956
+ isOne(...args) {
957
+ return isOne(this, ...args);
958
+ }
959
+ isNone(...args) {
960
+ return isNone(this, ...args);
961
+ }
962
+ isInclude(val) {
963
+ return isInclude(this, val);
964
+ }
965
+ sum(...args) {
966
+ return sum(this, ...args);
967
+ }
968
+ /** Mirrors: Ruby's Enumerable#to_a — `vendor/ruby/v3.3.11/enum.c:711` `enum_to_a`. */
969
+ toA() {
970
+ return enumToA(this);
971
+ }
972
+ /**
973
+ * Mirrors: Ruby's Enumerable#to_h — `vendor/ruby/v3.3.11/enum.c:767` `enum_to_h`, each
974
+ * pair set by `rb_hash_set_pair` (`vendor/ruby/v3.3.11/hash.c:3503`).
975
+ *
976
+ * @noRailsEquivalent PERMANENT
977
+ */
978
+ toH(block) {
979
+ const hash = {};
980
+ this.each((...argv) => {
981
+ const arg = block ? block(...argv) : argv.length === 1 ? argv[0] : argv;
982
+ if (!Array.isArray(arg)) {
983
+ throw new RbTypeError(`wrong element type ${rbObjClassname(arg)} (expected array)`);
984
+ }
985
+ if (arg.length !== 2) {
986
+ throw new ArgumentError(`element has wrong array length (expected 2, was ${arg.length})`);
987
+ }
988
+ Object.defineProperty(hash, arg[0], {
989
+ value: arg[1],
990
+ enumerable: true,
991
+ writable: true,
992
+ configurable: true,
993
+ });
994
+ });
995
+ return hash;
996
+ }
997
+ /** @noRailsEquivalent PERMANENT */
998
+ [Symbol.iterator]() {
999
+ return iterator.call(this);
1000
+ }
1001
+ }
1002
+ /** `select` is `enum_find_all` under a second name (`vendor/ruby/v3.3.11/enum.c:5076`). */
1003
+ Object.defineProperty(Enumerable.prototype, "select", {
1004
+ value: Enumerable.prototype.findAll,
1005
+ writable: true,
1006
+ configurable: true,
1007
+ });
1008
+ /**
1009
+ * `Enumerable` (`vendor/ruby/v3.3.11/enum.c:5047` `Init_Enumerable`) for a class
1010
+ * whose `each` awaits: every member awaits `each`, and `each` awaits the block
1011
+ * before it yields the next element.
1012
+ * @noRailsEquivalent PERMANENT
1013
+ */
1014
+ export const AsyncEnumerable = {
1015
+ /**
1016
+ * Mirrors: Ruby's Enumerable#to_a — `vendor/ruby/v3.3.11/enum.c:711` `enum_to_a`.
1017
+ * @noRailsEquivalent PERMANENT
1018
+ */
1019
+ toA() {
1020
+ return enumToA(this);
1021
+ },
1022
+ /**
1023
+ * Mirrors: Ruby's Enumerable#sum — `vendor/ruby/v3.3.11/enum.c:4753` `enum_sum`, awaiting
1024
+ * the block's result before it is added (`sum_iter`'s `rb_yield`, `:4645`).
1025
+ * @noRailsEquivalent PERMANENT
1026
+ */
1027
+ async sum(...args) {
1028
+ const [memo, block] = enumSumMemo(args);
1029
+ await this.each(async (i) => {
1030
+ sumIter(memo.blockGiven ? await block(i) : i, memo);
1031
+ });
1032
+ return enumSumValue(memo);
1033
+ },
1034
+ /**
1035
+ * Mirrors: Ruby's Enumerable#map — `vendor/ruby/v3.3.11/enum.c:638` `enum_collect`,
1036
+ * awaiting the block before the next element, so side effects keep Ruby's
1037
+ * order. An Array receiver is read directly, having no `each` member.
1038
+ * @noRailsEquivalent PERMANENT
1039
+ */
1040
+ async map(block) {
1041
+ const ary = [];
1042
+ const collectI = async (i) => {
1043
+ ary.push(await block(i));
1044
+ };
1045
+ if (Array.isArray(this)) {
1046
+ for (const i of this)
1047
+ await collectI(i);
1048
+ }
1049
+ else {
1050
+ await this.each(collectI);
1051
+ }
1052
+ return ary;
1053
+ },
1054
+ /**
1055
+ * Mirrors: Ruby's Enumerable#any? — `vendor/ruby/v3.3.11/enum.c:1861` `enum_any`,
1056
+ * awaiting the block and stopping at its first truthy result. An Array
1057
+ * receiver is read directly, having no `each` member.
1058
+ * @noRailsEquivalent PERMANENT
1059
+ */
1060
+ async isAny(block) {
1061
+ for (const i of this) {
1062
+ const result = await block(i);
1063
+ if (result != null && result !== false)
1064
+ return true;
1065
+ }
1066
+ return false;
1067
+ },
1068
+ first: Enumerable.prototype.first,
1069
+ /**
1070
+ * Mirrors: Ruby's Enumerable#reverse_each — `vendor/ruby/v3.3.11/enum.c:3006`
1071
+ * `enum_reverse_each`: `to_a`, then the block over it from the last element.
1072
+ * With no block it answers the enumerator `RETURN_SIZED_ENUMERATOR` builds.
1073
+ * @noRailsEquivalent PERMANENT
1074
+ */
1075
+ reverseEach(block) {
1076
+ const toA = () => AsyncEnumerable.toA.call(this);
1077
+ async function* reverseEach() {
1078
+ const ary = await toA();
1079
+ let len = ary.length;
1080
+ while (len--)
1081
+ yield ary[len];
1082
+ }
1083
+ const each = async (block) => {
1084
+ for await (const i of reverseEach())
1085
+ await block(i);
1086
+ return this;
1087
+ };
1088
+ if (!block) {
1089
+ return Object.assign(Object.create(AsyncEnumerable), {
1090
+ each: (block) => (block ? each(block) : reverseEach()),
1091
+ });
1092
+ }
1093
+ return each(block);
1094
+ },
1095
+ /** @noRailsEquivalent PERMANENT */
1096
+ [Symbol.asyncIterator]() {
1097
+ return this.each()[Symbol.asyncIterator]();
1098
+ },
1099
+ };
1100
+ //# sourceMappingURL=enumerable.js.map