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

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