rubico 2.0.1 → 2.2.0

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 (501) hide show
  1. package/README.md +10 -8
  2. package/Transducer.js +28 -0
  3. package/_internal/genericTransform.js +30 -28
  4. package/_internal/reducerTryCatch.js +55 -0
  5. package/dist/Transducer.es.js +28 -1
  6. package/dist/Transducer.es.min.js +2 -2
  7. package/dist/Transducer.js +28 -1
  8. package/dist/Transducer.min.js +2 -2
  9. package/dist/Transducer.mjs +28 -1
  10. package/dist/__.es.js +1 -1
  11. package/dist/__.es.min.js +1 -1
  12. package/dist/__.js +1 -1
  13. package/dist/__.min.js +1 -1
  14. package/dist/__.mjs +1 -1
  15. package/dist/all.es.js +1 -1
  16. package/dist/all.es.min.js +1 -1
  17. package/dist/all.js +1 -1
  18. package/dist/all.min.js +1 -1
  19. package/dist/all.mjs +1 -1
  20. package/dist/always.es.js +1 -1
  21. package/dist/always.es.min.js +1 -1
  22. package/dist/always.js +1 -1
  23. package/dist/always.min.js +1 -1
  24. package/dist/always.mjs +1 -1
  25. package/dist/and.es.js +1 -1
  26. package/dist/and.es.min.js +1 -1
  27. package/dist/and.js +1 -1
  28. package/dist/and.min.js +1 -1
  29. package/dist/and.mjs +1 -1
  30. package/dist/assign.es.js +1 -1
  31. package/dist/assign.es.min.js +1 -1
  32. package/dist/assign.js +1 -1
  33. package/dist/assign.min.js +1 -1
  34. package/dist/assign.mjs +1 -1
  35. package/dist/compose.es.js +1 -1
  36. package/dist/compose.es.min.js +1 -1
  37. package/dist/compose.js +1 -1
  38. package/dist/compose.min.js +1 -1
  39. package/dist/compose.mjs +1 -1
  40. package/dist/curry.es.js +1 -1
  41. package/dist/curry.es.min.js +1 -1
  42. package/dist/curry.js +1 -1
  43. package/dist/curry.min.js +1 -1
  44. package/dist/curry.mjs +1 -1
  45. package/dist/eq.es.js +1 -1
  46. package/dist/eq.es.min.js +1 -1
  47. package/dist/eq.js +1 -1
  48. package/dist/eq.min.js +1 -1
  49. package/dist/eq.mjs +1 -1
  50. package/dist/every.es.js +1 -1
  51. package/dist/every.es.min.js +1 -1
  52. package/dist/every.js +1 -1
  53. package/dist/every.min.js +1 -1
  54. package/dist/every.mjs +1 -1
  55. package/dist/filter.es.js +1 -1
  56. package/dist/filter.es.min.js +1 -1
  57. package/dist/filter.js +1 -1
  58. package/dist/filter.min.js +1 -1
  59. package/dist/filter.mjs +1 -1
  60. package/dist/flatMap.es.js +1 -1
  61. package/dist/flatMap.es.min.js +1 -1
  62. package/dist/flatMap.js +1 -1
  63. package/dist/flatMap.min.js +1 -1
  64. package/dist/flatMap.mjs +1 -1
  65. package/dist/forEach.es.js +1 -1
  66. package/dist/forEach.es.min.js +1 -1
  67. package/dist/forEach.js +1 -1
  68. package/dist/forEach.min.js +1 -1
  69. package/dist/forEach.mjs +1 -1
  70. package/dist/get.es.js +1 -1
  71. package/dist/get.es.min.js +1 -1
  72. package/dist/get.js +1 -1
  73. package/dist/get.min.js +1 -1
  74. package/dist/get.mjs +1 -1
  75. package/dist/gt.es.js +1 -1
  76. package/dist/gt.es.min.js +1 -1
  77. package/dist/gt.js +1 -1
  78. package/dist/gt.min.js +1 -1
  79. package/dist/gt.mjs +1 -1
  80. package/dist/gte.es.js +1 -1
  81. package/dist/gte.es.min.js +1 -1
  82. package/dist/gte.js +1 -1
  83. package/dist/gte.min.js +1 -1
  84. package/dist/gte.mjs +1 -1
  85. package/dist/lt.es.js +1 -1
  86. package/dist/lt.es.min.js +1 -1
  87. package/dist/lt.js +1 -1
  88. package/dist/lt.min.js +1 -1
  89. package/dist/lt.mjs +1 -1
  90. package/dist/lte.es.js +1 -1
  91. package/dist/lte.es.min.js +1 -1
  92. package/dist/lte.js +1 -1
  93. package/dist/lte.min.js +1 -1
  94. package/dist/lte.mjs +1 -1
  95. package/dist/map.es.js +1 -1
  96. package/dist/map.es.min.js +1 -1
  97. package/dist/map.js +1 -1
  98. package/dist/map.min.js +1 -1
  99. package/dist/map.mjs +1 -1
  100. package/dist/not.es.js +1 -1
  101. package/dist/not.es.min.js +1 -1
  102. package/dist/not.js +1 -1
  103. package/dist/not.min.js +1 -1
  104. package/dist/not.mjs +1 -1
  105. package/dist/omit.es.js +1 -1
  106. package/dist/omit.es.min.js +1 -1
  107. package/dist/omit.js +1 -1
  108. package/dist/omit.min.js +1 -1
  109. package/dist/omit.mjs +1 -1
  110. package/dist/or.es.js +1 -1
  111. package/dist/or.es.min.js +1 -1
  112. package/dist/or.js +1 -1
  113. package/dist/or.min.js +1 -1
  114. package/dist/or.mjs +1 -1
  115. package/dist/pick.es.js +1 -1
  116. package/dist/pick.es.min.js +1 -1
  117. package/dist/pick.js +1 -1
  118. package/dist/pick.min.js +1 -1
  119. package/dist/pick.mjs +1 -1
  120. package/dist/pipe.es.js +1 -1
  121. package/dist/pipe.es.min.js +1 -1
  122. package/dist/pipe.js +1 -1
  123. package/dist/pipe.min.js +1 -1
  124. package/dist/pipe.mjs +1 -1
  125. package/dist/reduce.es.js +1 -1
  126. package/dist/reduce.es.min.js +1 -1
  127. package/dist/reduce.js +1 -1
  128. package/dist/reduce.min.js +1 -1
  129. package/dist/reduce.mjs +1 -1
  130. package/dist/rubico.es.js +57 -46
  131. package/dist/rubico.es.min.js +2 -2
  132. package/dist/rubico.global.js +57 -46
  133. package/dist/rubico.global.min.js +2 -2
  134. package/dist/rubico.js +57 -46
  135. package/dist/rubico.min.js +2 -2
  136. package/dist/rubico.mjs +57 -46
  137. package/dist/set.es.js +1 -1
  138. package/dist/set.es.min.js +1 -1
  139. package/dist/set.js +1 -1
  140. package/dist/set.min.js +1 -1
  141. package/dist/set.mjs +1 -1
  142. package/dist/some.es.js +1 -1
  143. package/dist/some.es.min.js +1 -1
  144. package/dist/some.js +1 -1
  145. package/dist/some.min.js +1 -1
  146. package/dist/some.mjs +1 -1
  147. package/dist/switchCase.es.js +1 -1
  148. package/dist/switchCase.es.min.js +1 -1
  149. package/dist/switchCase.js +1 -1
  150. package/dist/switchCase.min.js +1 -1
  151. package/dist/switchCase.mjs +1 -1
  152. package/dist/tap.es.js +32 -2
  153. package/dist/tap.es.min.js +2 -2
  154. package/dist/tap.js +32 -2
  155. package/dist/tap.min.js +2 -2
  156. package/dist/tap.mjs +32 -2
  157. package/dist/thunkify.es.js +1 -1
  158. package/dist/thunkify.es.min.js +1 -1
  159. package/dist/thunkify.js +1 -1
  160. package/dist/thunkify.min.js +1 -1
  161. package/dist/thunkify.mjs +1 -1
  162. package/dist/transform.es.js +26 -24
  163. package/dist/transform.es.min.js +2 -2
  164. package/dist/transform.js +26 -24
  165. package/dist/transform.min.js +2 -2
  166. package/dist/transform.mjs +26 -24
  167. package/dist/tryCatch.es.js +1 -1
  168. package/dist/tryCatch.es.min.js +1 -1
  169. package/dist/tryCatch.js +1 -1
  170. package/dist/tryCatch.min.js +1 -1
  171. package/dist/tryCatch.mjs +1 -1
  172. package/dist/x/append.es.js +1 -1
  173. package/dist/x/append.es.min.js +1 -1
  174. package/dist/x/append.js +1 -1
  175. package/dist/x/append.min.js +1 -1
  176. package/dist/x/append.mjs +1 -1
  177. package/dist/x/callProp.es.js +1 -1
  178. package/dist/x/callProp.es.min.js +1 -1
  179. package/dist/x/callProp.js +1 -1
  180. package/dist/x/callProp.min.js +1 -1
  181. package/dist/x/callProp.mjs +1 -1
  182. package/dist/x/defaultsDeep.es.js +1 -1
  183. package/dist/x/defaultsDeep.es.min.js +1 -1
  184. package/dist/x/defaultsDeep.js +1 -1
  185. package/dist/x/defaultsDeep.min.js +1 -1
  186. package/dist/x/defaultsDeep.mjs +1 -1
  187. package/dist/x/differenceWith.es.js +1 -1
  188. package/dist/x/differenceWith.es.min.js +1 -1
  189. package/dist/x/differenceWith.js +1 -1
  190. package/dist/x/differenceWith.min.js +1 -1
  191. package/dist/x/differenceWith.mjs +1 -1
  192. package/dist/x/filterOut.es.js +1 -1
  193. package/dist/x/filterOut.es.min.js +1 -1
  194. package/dist/x/filterOut.js +1 -1
  195. package/dist/x/filterOut.min.js +1 -1
  196. package/dist/x/filterOut.mjs +1 -1
  197. package/dist/x/find.es.js +1 -1
  198. package/dist/x/find.es.min.js +1 -1
  199. package/dist/x/find.js +1 -1
  200. package/dist/x/find.min.js +1 -1
  201. package/dist/x/find.mjs +1 -1
  202. package/dist/x/findIndex.es.js +1 -1
  203. package/dist/x/findIndex.es.min.js +1 -1
  204. package/dist/x/findIndex.js +1 -1
  205. package/dist/x/findIndex.min.js +1 -1
  206. package/dist/x/findIndex.mjs +1 -1
  207. package/dist/x/first.es.js +1 -1
  208. package/dist/x/first.es.min.js +1 -1
  209. package/dist/x/first.js +1 -1
  210. package/dist/x/first.min.js +1 -1
  211. package/dist/x/first.mjs +1 -1
  212. package/dist/x/flatten.es.js +1 -1
  213. package/dist/x/flatten.es.min.js +1 -1
  214. package/dist/x/flatten.js +1 -1
  215. package/dist/x/flatten.min.js +1 -1
  216. package/dist/x/flatten.mjs +1 -1
  217. package/dist/x/groupBy.es.js +1 -1
  218. package/dist/x/groupBy.es.min.js +1 -1
  219. package/dist/x/groupBy.js +1 -1
  220. package/dist/x/groupBy.min.js +1 -1
  221. package/dist/x/groupBy.mjs +1 -1
  222. package/dist/x/has.es.js +1 -1
  223. package/dist/x/has.es.min.js +1 -1
  224. package/dist/x/has.js +1 -1
  225. package/dist/x/has.min.js +1 -1
  226. package/dist/x/has.mjs +1 -1
  227. package/dist/x/identity.es.js +1 -1
  228. package/dist/x/identity.es.min.js +1 -1
  229. package/dist/x/identity.js +1 -1
  230. package/dist/x/identity.min.js +1 -1
  231. package/dist/x/identity.mjs +1 -1
  232. package/dist/x/includes.es.js +1 -1
  233. package/dist/x/includes.es.min.js +1 -1
  234. package/dist/x/includes.js +1 -1
  235. package/dist/x/includes.min.js +1 -1
  236. package/dist/x/includes.mjs +1 -1
  237. package/dist/x/isDeepEqual.es.js +1 -1
  238. package/dist/x/isDeepEqual.es.min.js +1 -1
  239. package/dist/x/isDeepEqual.js +1 -1
  240. package/dist/x/isDeepEqual.min.js +1 -1
  241. package/dist/x/isDeepEqual.mjs +1 -1
  242. package/dist/x/isEmpty.es.js +1 -1
  243. package/dist/x/isEmpty.es.min.js +1 -1
  244. package/dist/x/isEmpty.js +1 -1
  245. package/dist/x/isEmpty.min.js +1 -1
  246. package/dist/x/isEmpty.mjs +1 -1
  247. package/dist/x/isEqual.es.js +1 -1
  248. package/dist/x/isEqual.es.min.js +1 -1
  249. package/dist/x/isEqual.js +1 -1
  250. package/dist/x/isEqual.min.js +1 -1
  251. package/dist/x/isEqual.mjs +1 -1
  252. package/dist/x/isFunction.es.js +1 -1
  253. package/dist/x/isFunction.es.min.js +1 -1
  254. package/dist/x/isFunction.js +1 -1
  255. package/dist/x/isFunction.min.js +1 -1
  256. package/dist/x/isFunction.mjs +1 -1
  257. package/dist/x/isIn.es.js +1 -1
  258. package/dist/x/isIn.es.min.js +1 -1
  259. package/dist/x/isIn.js +1 -1
  260. package/dist/x/isIn.min.js +1 -1
  261. package/dist/x/isIn.mjs +1 -1
  262. package/dist/x/isObject.es.js +1 -1
  263. package/dist/x/isObject.es.min.js +1 -1
  264. package/dist/x/isObject.js +1 -1
  265. package/dist/x/isObject.min.js +1 -1
  266. package/dist/x/isObject.mjs +1 -1
  267. package/dist/x/isString.es.js +1 -1
  268. package/dist/x/isString.es.min.js +1 -1
  269. package/dist/x/isString.js +1 -1
  270. package/dist/x/isString.min.js +1 -1
  271. package/dist/x/isString.mjs +1 -1
  272. package/dist/x/keys.es.js +1 -1
  273. package/dist/x/keys.es.min.js +1 -1
  274. package/dist/x/keys.js +1 -1
  275. package/dist/x/keys.min.js +1 -1
  276. package/dist/x/keys.mjs +1 -1
  277. package/dist/x/last.es.js +1 -1
  278. package/dist/x/last.es.min.js +1 -1
  279. package/dist/x/last.js +1 -1
  280. package/dist/x/last.min.js +1 -1
  281. package/dist/x/last.mjs +1 -1
  282. package/dist/x/maxBy.es.js +1 -1
  283. package/dist/x/maxBy.es.min.js +1 -1
  284. package/dist/x/maxBy.js +1 -1
  285. package/dist/x/maxBy.min.js +1 -1
  286. package/dist/x/maxBy.mjs +1 -1
  287. package/dist/x/noop.es.js +1 -1
  288. package/dist/x/noop.es.min.js +1 -1
  289. package/dist/x/noop.js +1 -1
  290. package/dist/x/noop.min.js +1 -1
  291. package/dist/x/noop.mjs +1 -1
  292. package/dist/x/pluck.es.js +1 -1
  293. package/dist/x/pluck.es.min.js +1 -1
  294. package/dist/x/pluck.js +1 -1
  295. package/dist/x/pluck.min.js +1 -1
  296. package/dist/x/pluck.mjs +1 -1
  297. package/dist/x/prepend.es.js +1 -1
  298. package/dist/x/prepend.es.min.js +1 -1
  299. package/dist/x/prepend.js +1 -1
  300. package/dist/x/prepend.min.js +1 -1
  301. package/dist/x/prepend.mjs +1 -1
  302. package/dist/x/size.es.js +1 -1
  303. package/dist/x/size.es.min.js +1 -1
  304. package/dist/x/size.js +1 -1
  305. package/dist/x/size.min.js +1 -1
  306. package/dist/x/size.mjs +1 -1
  307. package/dist/x/trace.es.js +32 -2
  308. package/dist/x/trace.es.min.js +2 -2
  309. package/dist/x/trace.js +32 -2
  310. package/dist/x/trace.min.js +2 -2
  311. package/dist/x/trace.mjs +32 -2
  312. package/dist/x/unionWith.es.js +1 -1
  313. package/dist/x/unionWith.es.min.js +1 -1
  314. package/dist/x/unionWith.js +1 -1
  315. package/dist/x/unionWith.min.js +1 -1
  316. package/dist/x/unionWith.mjs +1 -1
  317. package/dist/x/uniq.es.js +1 -1
  318. package/dist/x/uniq.es.min.js +1 -1
  319. package/dist/x/uniq.js +1 -1
  320. package/dist/x/uniq.min.js +1 -1
  321. package/dist/x/uniq.mjs +1 -1
  322. package/dist/x/unless.es.js +1 -1
  323. package/dist/x/unless.es.min.js +1 -1
  324. package/dist/x/unless.js +1 -1
  325. package/dist/x/unless.min.js +1 -1
  326. package/dist/x/unless.mjs +1 -1
  327. package/dist/x/values.es.js +1 -1
  328. package/dist/x/values.es.min.js +1 -1
  329. package/dist/x/values.js +1 -1
  330. package/dist/x/values.min.js +1 -1
  331. package/dist/x/values.mjs +1 -1
  332. package/dist/x/when.es.js +1 -1
  333. package/dist/x/when.es.min.js +1 -1
  334. package/dist/x/when.js +1 -1
  335. package/dist/x/when.min.js +1 -1
  336. package/dist/x/when.mjs +1 -1
  337. package/es.js +57 -46
  338. package/index.js +57 -46
  339. package/package.json +43 -2
  340. package/tap.js +15 -4
  341. package/.eslintignore +0 -5
  342. package/.eslintrc.js +0 -330
  343. package/.github/workflows/nodejs.yml +0 -27
  344. package/.vscode/launch.json +0 -25
  345. package/AggregateReducer.test.js +0 -82
  346. package/CHANGELOG.md +0 -310
  347. package/CNAME +0 -1
  348. package/CODE_OF_CONDUCT.md +0 -128
  349. package/CONTRIBUTING.md +0 -4
  350. package/Transducer.test.js +0 -117
  351. package/_config.yml +0 -1
  352. package/_internal/improvedGenericTransform.js +0 -93
  353. package/archive/FlatMappingIterator-2020-09-28.js +0 -68
  354. package/archive/_Promise-2023-05-29.js +0 -93
  355. package/archive/arrayMap2-2023-05-29.js +0 -73
  356. package/archive/benchmarks-v1.9.7/all.js +0 -34
  357. package/archive/benchmarks-v1.9.7/and.js +0 -24
  358. package/archive/benchmarks-v1.9.7/any.js +0 -32
  359. package/archive/benchmarks-v1.9.7/assign.js +0 -174
  360. package/archive/benchmarks-v1.9.7/curry.js +0 -55
  361. package/archive/benchmarks-v1.9.7/eq.js +0 -25
  362. package/archive/benchmarks-v1.9.7/filter.js +0 -1322
  363. package/archive/benchmarks-v1.9.7/flatMap.js +0 -48
  364. package/archive/benchmarks-v1.9.7/forEach.js +0 -33
  365. package/archive/benchmarks-v1.9.7/fork.js +0 -123
  366. package/archive/benchmarks-v1.9.7/get.js +0 -44
  367. package/archive/benchmarks-v1.9.7/gt.js +0 -25
  368. package/archive/benchmarks-v1.9.7/gte.js +0 -25
  369. package/archive/benchmarks-v1.9.7/integration.js +0 -88
  370. package/archive/benchmarks-v1.9.7/lt.js +0 -25
  371. package/archive/benchmarks-v1.9.7/lte.js +0 -25
  372. package/archive/benchmarks-v1.9.7/map.js +0 -892
  373. package/archive/benchmarks-v1.9.7/misc.js +0 -470
  374. package/archive/benchmarks-v1.9.7/omit.js +0 -28
  375. package/archive/benchmarks-v1.9.7/or.js +0 -51
  376. package/archive/benchmarks-v1.9.7/pick.js +0 -24
  377. package/archive/benchmarks-v1.9.7/pipe.js +0 -152
  378. package/archive/benchmarks-v1.9.7/reduce.js +0 -739
  379. package/archive/benchmarks-v1.9.7/switchCase.js +0 -256
  380. package/archive/benchmarks-v1.9.7/tap.js +0 -90
  381. package/archive/benchmarks-v1.9.7/transform.js +0 -218
  382. package/archive/benchmarks-v1.9.7/tryCatch.js +0 -108
  383. package/archive/curry.js +0 -13
  384. package/archive/examples-v1.6.11/browserModule.html +0 -31
  385. package/archive/examples-v1.6.11/browserScript.html +0 -32
  386. package/archive/examples-v1.6.11/coolTransformToConsole.js +0 -1
  387. package/archive/examples-v1.6.11/denoLargeGasMap.js +0 -85
  388. package/archive/examples-v1.6.11/denoServer.js +0 -9
  389. package/archive/examples-v1.6.11/denoServerWithMiddleware.js +0 -55
  390. package/archive/examples-v1.6.11/logTodosRange.js +0 -21
  391. package/archive/examples-v1.6.11/makeARequest.html +0 -46
  392. package/archive/examples-v1.6.11/nodeComplexTransformation.js +0 -106
  393. package/archive/examples-v1.6.11/nodeConditionallyExtractIDs.js +0 -50
  394. package/archive/examples-v1.6.11/nodeFloatingPoint.js +0 -55
  395. package/archive/examples-v1.6.11/nodeGetAllJiraBoards.js +0 -45
  396. package/archive/examples-v1.6.11/nodeGetSocketIOClientsTotalCount.js +0 -34
  397. package/archive/examples-v1.6.11/nodeKafkaConsumer.js +0 -63
  398. package/archive/examples-v1.6.11/nodeMakeMultipleRequests.js +0 -55
  399. package/archive/examples-v1.6.11/nodeOnRecordAddTask.js +0 -34
  400. package/archive/examples-v1.6.11/nodePostRequestWithAuth.js +0 -36
  401. package/archive/examples-v1.6.11/nodeSpeedbackMatchmakingAlgorithm.js +0 -96
  402. package/archive/examples-v1.6.11/nodeTireData.js +0 -36
  403. package/archive/examples-v1.6.11/nodeTripleMap.js +0 -85
  404. package/archive/examples-v1.6.11/squaredOdds.ts +0 -16
  405. package/archive/examples-v1.6.11/transducerMaxBuyer.js +0 -67
  406. package/archive/examples-v1.6.11/transformLogTodosRange.js +0 -31
  407. package/archive/examples-v1.6.11/transformStreamRandomInts.js +0 -19
  408. package/archive/genericReduceConcurrent.js +0 -277
  409. package/archive/index.v0.2.9.js +0 -1685
  410. package/archive/objectValuesGenerator.js +0 -13
  411. package/archive/test.v0.2.9.js +0 -2334
  412. package/bench +0 -65
  413. package/benchmark-output/v1.9.7 +0 -268
  414. package/benchmarks/all.async.js +0 -43
  415. package/benchmarks/all.js +0 -43
  416. package/benchmarks/always.js +0 -15
  417. package/benchmarks/and.async.js +0 -25
  418. package/benchmarks/and.js +0 -25
  419. package/benchmarks/assign.async.js +0 -27
  420. package/benchmarks/assign.js +0 -27
  421. package/benchmarks/curry.js +0 -35
  422. package/benchmarks/eq.async.js +0 -23
  423. package/benchmarks/eq.js +0 -23
  424. package/benchmarks/every.async.js +0 -19
  425. package/benchmarks/every.js +0 -19
  426. package/benchmarks/filter.async.js +0 -32
  427. package/benchmarks/filter.js +0 -38
  428. package/benchmarks/flatMap.async.js +0 -26
  429. package/benchmarks/flatMap.js +0 -38
  430. package/benchmarks/get.async.js +0 -19
  431. package/benchmarks/get.js +0 -39
  432. package/benchmarks/gt.async.js +0 -23
  433. package/benchmarks/gt.js +0 -23
  434. package/benchmarks/gte.async.js +0 -23
  435. package/benchmarks/gte.js +0 -23
  436. package/benchmarks/lt.async.js +0 -23
  437. package/benchmarks/lt.js +0 -23
  438. package/benchmarks/lte.async.js +0 -23
  439. package/benchmarks/lte.js +0 -23
  440. package/benchmarks/map.async.js +0 -43
  441. package/benchmarks/map.js +0 -40
  442. package/benchmarks/misc/Promise.js +0 -26
  443. package/benchmarks/misc/isPromise.js +0 -30
  444. package/benchmarks/misc/promiseAll.js +0 -36
  445. package/benchmarks/not.js +0 -23
  446. package/benchmarks/omit.js +0 -38
  447. package/benchmarks/or.async.js +0 -25
  448. package/benchmarks/or.js +0 -25
  449. package/benchmarks/pick.js +0 -38
  450. package/benchmarks/pipe.async.js +0 -47
  451. package/benchmarks/pipe.js +0 -47
  452. package/benchmarks/reduce.async.js +0 -32
  453. package/benchmarks/reduce.js +0 -38
  454. package/benchmarks/set.async.js +0 -19
  455. package/benchmarks/set.js +0 -41
  456. package/benchmarks/some.async.js +0 -19
  457. package/benchmarks/some.js +0 -19
  458. package/benchmarks/switchCase.async.js +0 -27
  459. package/benchmarks/switchCase.js +0 -55
  460. package/benchmarks/tap.js +0 -15
  461. package/benchmarks/thunkify.js +0 -15
  462. package/benchmarks/transform.async.js +0 -27
  463. package/benchmarks/transform.js +0 -40
  464. package/benchmarks/tryCatch.async.js +0 -25
  465. package/benchmarks/tryCatch.js +0 -32
  466. package/build +0 -472
  467. package/dist-test.js +0 -37
  468. package/examples/type-to-search-wiki/README.md +0 -19
  469. package/examples/type-to-search-wiki/package.json +0 -13
  470. package/examples/type-to-search-wiki/src/app.js +0 -46
  471. package/examples/type-to-search-wiki/src/index.html +0 -18
  472. package/import-test.html +0 -73
  473. package/memory-usage/reduce.js +0 -40
  474. package/monad/AsyncPool.js +0 -0
  475. package/monad/BrokenPromise.js +0 -63
  476. package/monad/BrokenPromise.test.js +0 -22
  477. package/monad/Cancellable.js +0 -84
  478. package/monad/Cancellable.memoryUsage.js +0 -60
  479. package/monad/Cancellable.test.js +0 -20
  480. package/monad/Function.js +0 -0
  481. package/monad/Instance.benchmark.js +0 -378
  482. package/monad/Instance.js +0 -351
  483. package/monad/Instance.test.js +0 -445
  484. package/monad/Mux.benchmark.js +0 -29
  485. package/monad/Mux.js +0 -589
  486. package/monad/Mux.test.js +0 -512
  487. package/monad/PossiblePromise.benchmark.js +0 -87
  488. package/monad/PossiblePromise.js +0 -144
  489. package/monad/PossiblePromise.test.js +0 -89
  490. package/monad/README.md +0 -75
  491. package/monad/Reducer.js +0 -0
  492. package/monad/Sequence.benchmark.js +0 -42
  493. package/monad/Sequence.js +0 -36
  494. package/monad/SpecScript.js +0 -0
  495. package/monad/Stack.js +0 -0
  496. package/monad/Struct.benchmark.js +0 -154
  497. package/monad/Struct.js +0 -249
  498. package/monad/Struct.test.js +0 -237
  499. package/rubico.js +0 -66
  500. package/test.js +0 -4242
  501. package/tmp.js +0 -1
@@ -1,1685 +0,0 @@
1
- const util = require('util')
2
- const crypto = require('crypto')
3
-
4
- const _ = {}
5
-
6
- const setProp = prop => (x, value) => Object.defineProperty(x, prop, { value })
7
- _.setProp = setProp
8
-
9
- const setName = setProp('name')
10
- _.setName = setName
11
-
12
- const getName = fn => fn.name || 'anonymous'
13
- _.getName = getName
14
-
15
- _.exists = x => x !== undefined && x !== null
16
- setName(_.exists, 'exists')
17
-
18
- _.dne = x => x === undefined || x === null
19
- setName(_.dne, 'dne')
20
-
21
- _.isFn = x => typeof x === 'function'
22
- setName(_.isFn, 'isFn')
23
-
24
- _.isString = x => typeof x === 'string'
25
- setName(_.isString, 'isString')
26
-
27
- _.isNumber = x => typeof x === 'number'
28
- setName(_.isNumber, 'isNumber')
29
-
30
- _.isBigInt = x => typeof x === 'bigint'
31
- setName(_.isBigInt, 'isBigInt')
32
-
33
- _.isBoolean = x => typeof x === 'boolean'
34
- setName(_.isBoolean, 'isBoolean')
35
-
36
- _.is = fn => {
37
- const ret = x => _.exists(x) && _.exists(x.constructor) && x.constructor === fn
38
- setName(ret, `is(${getName(fn)})`)
39
- return ret
40
- }
41
- setName(_.is, 'is')
42
-
43
- _.isArray = _.is(Array)
44
- setName(_.isArray, 'isArray')
45
-
46
- _.isObject = _.is(Object)
47
- setName(_.isObject, 'isObject')
48
-
49
- _.isSet = _.is(Set)
50
- setName(_.isSet, 'isSet')
51
-
52
- _.isMap = _.is(Map)
53
- setName(_.isMap, 'isMap')
54
-
55
- _.isBuffer = _.is(Buffer)
56
- setName(_.isBuffer, 'isBuffer')
57
-
58
- _.isSymbol = _.is(Symbol)
59
- setName(_.isSymbol, 'isSymbol')
60
-
61
- _.isPromise = _.is(Promise)
62
- setName(_.isPromise, 'isPromise')
63
-
64
- _.isRegExp = _.is(RegExp)
65
- setName(_.isRegExp, 'isRegExp')
66
-
67
- _.id = x => x
68
- setName(_.id, 'id')
69
-
70
- _.noop = () => {}
71
- setName(_.noop, 'noop')
72
-
73
- _.inspect = x => util.inspect(x, { depth: Infinity })
74
- setName(_.inspect, 'inspect')
75
-
76
- _.shorthand = x => {
77
- if (_.isFn(x)) return getName(x)
78
- if (_.isString(x)) {
79
- if (x.length === 0) return '\'\''
80
- if (x.length > 10) return `'${x.slice(0, 10)}...'{${x.length}}`
81
- return `'${x}'`
82
- }
83
- if (_.isBigInt(x)) return `${x}n`
84
- if (_.isArray(x)) return x.length === 0 ? '[]' : `[...]{${x.length}}`
85
- if (_.isObject(x)) {
86
- const l = Object.keys(x).length
87
- if (l === 0) return '{}'
88
- return `{...}{${l}}`
89
- }
90
- if (_.isSet(x)) {
91
- if (x.size === 0) return 'Set{}'
92
- return `Set{...}{${x.size}}`
93
- }
94
- if (_.isMap(x)) {
95
- if (x.size === 0) return 'Map{}'
96
- return `Map{...}{${x.size}}`
97
- }
98
- if (_.isBuffer(x)) {
99
- if (x.length === 0) return 'Buffer<>'
100
- return `Buffer<...>{${x.length}}`
101
- }
102
- return `${_.inspect(x)}`.slice(0, 20)
103
- }
104
- setName(_.shorthand, 'shorthand')
105
-
106
- _.spread = fn => {
107
- const ret = x => fn(...x)
108
- setName(ret, `spread(${getName(fn)})`)
109
- return ret
110
- }
111
- setName(_.spread, 'spread')
112
-
113
- _.throw = e => { throw e }
114
- setName(_.throw, 'throw')
115
-
116
- // TODO: apply multiple to arities > 1
117
- _.apply = fn => {
118
- const ret = x => {
119
- let y = fn
120
- for (const a of x) y = y(a)
121
- if (typeof y === 'function') {
122
- setName(y, getName(fn) + x.map(y => `(${_.shorthand(y)})`).join(''))
123
- }
124
- return y
125
- }
126
- setName(ret, `apply(${getName(fn)})`)
127
- return ret
128
- }
129
- setName(_.apply, 'apply')
130
-
131
- _.new = x => {
132
- if (_.isString(x)) return ''
133
- if (_.isNumber(x)) return 0
134
- if (_.isArray(x)) return []
135
- if (_.isObject(x)) return {}
136
- if (_.isSet(x)) return new Set()
137
- if (_.isMap(x)) return new Map()
138
- if (_.isBuffer(x)) return Buffer.from('')
139
- throw new TypeError(`cannot new ${x}`)
140
- }
141
- setName(_.new, 'new')
142
-
143
- _.copy = x => {
144
- if (_.isString(x)) return x
145
- if (_.isNumber(x)) return x
146
- if (_.isArray(x)) return x.slice(0)
147
- if (_.isObject(x)) return Object.assign({}, x)
148
- if (_.isSet(x)) return new Set(x)
149
- if (_.isMap(x)) return new Map(x)
150
- if (_.isBuffer(x)) return Buffer.from(x)
151
- throw new TypeError(`cannot copy ${x}`)
152
- }
153
- setName(_.copy, 'copy')
154
-
155
- _.toFn = x => {
156
- if (_.isFn(x)) return x
157
- const ret = () => x
158
- setName(ret, `() => ${_.shorthand(x)}`)
159
- return ret
160
- }
161
- setName(_.toFn, 'toFn')
162
-
163
- _.toString = x => `${x}`
164
- setName(_.toString, 'toString')
165
-
166
- _.toInt = x => x === Infinity ? x : parseInt(x, 10)
167
- setName(_.toInt, 'toInt')
168
-
169
- _.toFloat = parseFloat
170
- setName(_.toFloat, 'toFloat')
171
-
172
- _.toArray = x => {
173
- if (_.dne(x)) return []
174
- if (_.isString(x)) return Array.of(x)
175
- if (_.isNumber(x)) return Array.of(x)
176
- return Array.from(x)
177
- }
178
- setName(_.toArray, 'toArray')
179
-
180
- _.toSet = x => new Set(_.toArray(x))
181
- setName(_.toSet, 'toSet')
182
-
183
- const escapeRegex = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
184
-
185
- _.toRegExp = (x, flags = '') => {
186
- if (_.isRegExp(x)) return new RegExp(x, flags)
187
- if (_.isString(x)) return new RegExp(escapeRegex(x), flags)
188
- throw new TypeError(`cannot coerce to RegExp ${x}`)
189
- }
190
- setName(_.toRegExp, 'toRegExp')
191
-
192
- // TODO: what if x was a fn? a fn that returned bits off a stream or an item from a large list
193
- // consider: second argument is accum
194
- _.flow = (...fns) => {
195
- if (!fns.every(_.isFn)) throw new TypeError('not all fns are fns')
196
- const ret = async (...x) => {
197
- if (fns.length === 0) return x[0]
198
- let y = await fns[0](...x), i = 1
199
- while (i < fns.length) {
200
- y = await fns[i](y)
201
- i += 1
202
- }
203
- return y
204
- }
205
- setName(ret, `${fns.map(_.shorthand).join('→')}`)
206
- return ret
207
- }
208
- setName(_.flow, 'flow')
209
-
210
- _.flow.sync = (...fns) => {
211
- if (!fns.every(_.isFn)) throw new TypeError('not all fns are fns')
212
- const ret = (...x) => {
213
- if (fns.length === 0) return x[0]
214
- let y = fns[0](...x), i = 1
215
- while (i < fns.length) {
216
- y = fns[i](y)
217
- i += 1
218
- }
219
- return y
220
- }
221
- setName(ret, `${fns.map(_.shorthand).join('→')}`)
222
- return ret
223
- }
224
- setName(_.flow.sync, 'flow')
225
-
226
- _.series = (...fns) => {
227
- if (!fns.every(_.isFn)) throw new TypeError('not all fns are fns')
228
- const ret = async (...x) => {
229
- const y = []
230
- for (const fn of fns) y.push(await _.toFn(fn)(...x))
231
- return y
232
- }
233
- setName(ret, `series(${fns.map(_.shorthand).join(', ')})`)
234
- return ret
235
- }
236
- setName(_.series, 'series')
237
-
238
- _.series.sync = (...fns) => {
239
- if (!fns.every(_.isFn)) throw new TypeError('not all fns are fns')
240
- const ret = (...x) => {
241
- const y = []
242
- for (const fn of fns) y.push(_.toFn(fn)(...x))
243
- return y
244
- }
245
- setName(ret, `series(${fns.map(_.shorthand).join(', ')})`)
246
- return ret
247
- }
248
- setName(_.series.sync, 'series')
249
-
250
- _.switch = (...fns) => {
251
- if (fns.length < 3) throw new Error('3 or more fns required')
252
- if (fns.length % 2 === 0) throw new Error('odd number of fns required')
253
- fns = fns.map(_.toFn)
254
- const lastFn = fns.pop()
255
- const ret = async x => {
256
- let i = 0
257
- while (i < fns.length) {
258
- if (await fns[i](x)) return fns[i + 1](x)
259
- i += 2
260
- }
261
- return lastFn(x)
262
- }
263
- setName(ret, `switch(${fns.map(_.shorthand).join(', ')}, ${_.shorthand(lastFn)})`)
264
- return ret
265
- }
266
- setName(_.switch, 'switch')
267
-
268
- _.switch.sync = (...fns) => {
269
- if (fns.length < 3) throw new Error('3 or more fns required')
270
- if (fns.length % 2 === 0) throw new Error('odd number of fns required')
271
- fns = fns.map(_.toFn)
272
- const lastFn = fns.pop()
273
- const ret = x => {
274
- let i = 0
275
- while (i < fns.length) {
276
- if (fns[i](x)) return fns[i + 1](x)
277
- i += 2
278
- }
279
- return lastFn(x)
280
- }
281
- setName(ret, `switch(${fns.map(_.shorthand).join(', ')}, ${_.shorthand(lastFn)})`)
282
- return ret
283
- }
284
- setName(_.switch.sync, 'switch')
285
-
286
- _.effect = fn => {
287
- fn = _.toFn(fn)
288
- const ret = async x => { await fn(x); return x }
289
- setName(ret, `effect(${_.shorthand(fn)})`)
290
- return ret
291
- }
292
- setName(_.effect, 'effect')
293
-
294
- _.effect.sync = fn => {
295
- fn = _.toFn(fn)
296
- const ret = x => { fn(x); return x }
297
- setName(ret, `effect(${_.shorthand(fn)})`)
298
- return ret
299
- }
300
- setName(_.effect.sync, 'effect')
301
-
302
- _.sleep = ms => {
303
- const ret = _.effect(
304
- () => new Promise(resolve => setTimeout(resolve, ms))
305
- )
306
- setName(ret, `sleep(${ms})`)
307
- return ret
308
- }
309
- setName(_.sleep, 'sleep')
310
-
311
- _.tryCatch = (tryFn, catchFn) => {
312
- if (!_.isFn(tryFn)) throw new TypeError('try fn not a fn')
313
- if (!_.isFn(catchFn)) throw new TypeError('catch fn not a fn')
314
- const ret = async (...x) => {
315
- try {
316
- return await tryFn(...x)
317
- } catch (e) {
318
- e._args = x
319
- return await catchFn(e)
320
- }
321
- }
322
- setName(ret, `tryCatch(${_.shorthand(tryFn)}, ${_.shorthand(catchFn)})`)
323
- return ret
324
- }
325
- setName(_.tryCatch, 'tryCatch')
326
-
327
- _.tryCatch.sync = (tryFn, catchFn) => {
328
- if (!_.isFn(tryFn)) throw new TypeError('try fn not a fn')
329
- if (!_.isFn(catchFn)) throw new TypeError('catch fn not a fn')
330
- const ret = (...x) => {
331
- try {
332
- return tryFn(...x)
333
- } catch (e) {
334
- e._args = x
335
- return catchFn(e)
336
- }
337
- }
338
- setName(ret, `tryCatch(${_.shorthand(tryFn)}, ${_.shorthand(catchFn)})`)
339
- return ret
340
- }
341
- setName(_.tryCatch.sync, 'tryCatch')
342
-
343
- // TODO: account for AsyncIterator, Iterator, and Stream points
344
- _.map = (fn, opts = {}) => {
345
- const e = new TypeError()
346
- Error.captureStackTrace(e)
347
- const ret = async x => {
348
- if (_.isArray(x)) {
349
- const tasks = []
350
- let i = 0
351
- for await (const a of x) {
352
- tasks.push(fn(a, i))
353
- i += 1
354
- }
355
- return await Promise.all(tasks)
356
- }
357
- if (_.isSet(x)) {
358
- const tasks = []
359
- let i = 0
360
- for await (const a of x) {
361
- tasks.push(fn(a, i))
362
- i += 1
363
- }
364
- return new Set(await Promise.all(tasks))
365
- }
366
- if (_.isMap(x)) {
367
- const tasks = [], y = new Map()
368
- let i = 0
369
- for await (const [k, v] of x) {
370
- const a = fn(v, i)
371
- if (_.isPromise(a)) tasks.push(a.then(b => y.set(k, b)))
372
- else y.set(k, a)
373
- i += 1
374
- }
375
- await Promise.all(tasks)
376
- return y
377
- }
378
- if (_.isObject(x)) {
379
- const tasks = [], y = {}
380
- let i = 0
381
- for (const k in x) {
382
- const a = fn(x[k], i)
383
- if (_.isPromise(a)) tasks.push(a.then(b => y[k] = b))
384
- else y[k] = a
385
- i += 1
386
- }
387
- await Promise.all(tasks)
388
- return y
389
- }
390
- e.message = `cannot map ${x}`
391
- throw e
392
- }
393
- setName(ret, `map(${_.shorthand(fn)})`)
394
- return ret
395
- }
396
- setName(_.map, 'map')
397
-
398
- _.map.sync = fn => {
399
- const e = new TypeError()
400
- Error.captureStackTrace(e)
401
- const ret = x => {
402
- if (_.isArray(x)) return x.map(fn)
403
- if (_.isSet(x)) {
404
- const y = new Set()
405
- let i = 0
406
- for (const a of x) {
407
- y.add(fn(a, i))
408
- i += 1
409
- }
410
- return y
411
- }
412
- if (_.isMap(x)) {
413
- const y = new Map()
414
- let i = 0
415
- for (const [k, v] of x) {
416
- y.set(k, fn(v, i))
417
- i += 1
418
- }
419
- return y
420
- }
421
- if (_.isObject(x)) {
422
- const y = {}
423
- let i = 0
424
- for (const k in x) {
425
- y[k] = fn(x[k], i)
426
- i += 1
427
- }
428
- return y
429
- }
430
- e.message = `cannot map ${x}`
431
- throw e
432
- }
433
- setName(ret, `map(${_.shorthand(fn)})`)
434
- return ret
435
- }
436
- setName(_.map.sync, 'map')
437
-
438
- // TODO: only support [] and {}
439
- _.diverge = fns => {
440
- if (_.isArray(fns)) {
441
- fns = _.map.sync(_.toFn)(fns)
442
- const ret = async (...x) => (
443
- await Promise.all(fns.map(fn => fn(...x)))
444
- )
445
- setName(ret, `diverge(${_.shorthand(fns)})`)
446
- return ret
447
- }
448
- if (_.isSet(fns)) {
449
- fns = _.map.sync(_.toFn)(fns)
450
- const ret = async (...x) => {
451
- const y = new Set(), tasks = []
452
- for (const fn of fns) {
453
- const p = fn(...x)
454
- if (_.isPromise(p)) tasks.push(p.then(a => y.add(a)))
455
- else y.add(p)
456
- }
457
- await Promise.all(tasks)
458
- return y
459
- }
460
- setName(ret, `diverge(${_.shorthand(fns)})`)
461
- return ret
462
- }
463
- if (_.isMap(fns)) {
464
- fns = _.map.sync(_.toFn)(fns)
465
- const ret = async (...x) => {
466
- const y = new Map(), tasks = []
467
- for (const [k, fn] of fns) {
468
- const p = _.toFn(fn)(...x)
469
- if (_.isPromise(p)) tasks.push(p.then(a => y.set(k, a)))
470
- else y.set(k, p)
471
- }
472
- await Promise.all(tasks)
473
- return y
474
- }
475
- setName(ret, `diverge(${_.shorthand(fns)})`)
476
- return ret
477
- }
478
- if (_.isObject(fns)) {
479
- fns = _.map.sync(_.toFn)(fns)
480
- const ret = async (...x) => {
481
- const y = {}, tasks = []
482
- for (const k in fns) {
483
- const p = fns[k](...x)
484
- if (_.isPromise(p)) tasks.push(p.then(a => { y[k] = a }))
485
- else { y[k] = p }
486
- }
487
- await Promise.all(tasks)
488
- return y
489
- }
490
- setName(ret, `diverge(${_.shorthand(fns)})`)
491
- return ret
492
- }
493
- throw new TypeError(`cannot diverge ${fns}`)
494
- }
495
- setName(_.diverge, 'diverge')
496
-
497
- _.diverge.sync = fns => {
498
- if (_.isArray(fns)) {
499
- fns = _.map.sync(_.toFn)(fns)
500
- const ret = (...x) => fns.map(fn => fn(...x))
501
- setName(ret, `diverge(${_.shorthand(fns)})`)
502
- return ret
503
- }
504
- if (_.isSet(fns)) {
505
- fns = _.map.sync(_.toFn)(fns)
506
- const ret = (...x) => {
507
- const y = new Set()
508
- for (const fn of fns) y.add(fn(...x))
509
- return y
510
- }
511
- setName(ret, `diverge(${_.shorthand(fns)})`)
512
- return ret
513
- }
514
- if (_.isMap(fns)) {
515
- fns = _.map.sync(_.toFn)(fns)
516
- const ret = (...x) => {
517
- const y = new Map()
518
- for (const [k, fn] of fns) y.set(k, fn(...x))
519
- return y
520
- }
521
- setName(ret, `diverge(${_.shorthand(fns)})`)
522
- return ret
523
- }
524
- if (_.isObject(fns)) {
525
- fns = _.map.sync(_.toFn)(fns)
526
- const ret = (...x) => {
527
- const y = {}
528
- for (const k in fns) y[k] = fns[k](...x)
529
- return y
530
- }
531
- setName(ret, `diverge(${_.shorthand(fns)})`)
532
- return ret
533
- }
534
- throw new TypeError(`cannot diverge ${fns}`)
535
- }
536
- setName(_.diverge.sync, 'diverge')
537
-
538
- _.serialMap = fn => {
539
- const e = new TypeError()
540
- Error.captureStackTrace(e)
541
- const ret = async x => {
542
- if (_.isArray(x)) {
543
- const y = []
544
- for (const a of x) y.push(await fn(a))
545
- return y
546
- }
547
- if (_.isSet(x)) {
548
- const y = new Set()
549
- for (const a of x) y.add(await fn(a))
550
- return y
551
- }
552
- if (_.isMap(x)) {
553
- const y = new Map()
554
- for (const [k, v] of x) y.set(k, await fn(v))
555
- return y
556
- }
557
- if (_.isObject(x)) {
558
- const y = {}
559
- for (const k in x) y[k] = await fn(x[k])
560
- return y
561
- }
562
- e.message = `cannot serialMap ${x}`
563
- throw e
564
- }
565
- setName(ret, `serialMap(${_.shorthand(fn)})`)
566
- return ret
567
- }
568
- setName(_.serialMap, 'serialMap')
569
-
570
- _.entryMap = fn => {
571
- const e = new TypeError()
572
- Error.captureStackTrace(e)
573
- const ret = async x => {
574
- if (_.isArray(x)) {
575
- const tasks = []
576
- for (const a of x) tasks.push(fn(a))
577
- return await Promise.all(tasks)
578
- }
579
- if (_.isSet(x)) {
580
- const tasks = []
581
- for (const a of x) tasks.push(fn(a))
582
- return new Set(await Promise.all(tasks))
583
- }
584
- if (_.isMap(x)) {
585
- const tasks = []
586
- for (const a of x) tasks.push(fn(a))
587
- return new Map(await Promise.all(tasks))
588
- }
589
- if (_.isObject(x)) {
590
- const tasks = []
591
- for (const k in x) tasks.push(fn([k, x[k]]))
592
- const y = {}
593
- for (const [k, v] of await Promise.all(tasks)) y[k] = v
594
- return y
595
- }
596
- e.message = `cannot entryMap ${x}`
597
- throw e
598
- }
599
- setName(ret, `entryMap(${_.shorthand(fn)})`)
600
- return ret
601
- }
602
- setName(_.entryMap, 'entryMap')
603
-
604
- _.entryMap.sync = fn => {
605
- const e = new TypeError()
606
- Error.captureStackTrace(e)
607
- const ret = x => {
608
- if (_.isArray(x)) return x.map(fn)
609
- if (_.isSet(x)) {
610
- const y = new Set()
611
- for (const a of x) y.add(fn(a))
612
- return y
613
- }
614
- if (_.isMap(x)) {
615
- const y = new Map()
616
- for (const a of x) y.set(...fn(a))
617
- return y
618
- }
619
- if (_.isObject(x)) {
620
- const y = {}
621
- for (const k in x) {
622
- const [kn, vn] = fn([k, x[k]])
623
- y[kn] = vn
624
- }
625
- return y
626
- }
627
- e.message = `cannot entryMap ${x}`
628
- throw e
629
- }
630
- setName(ret, `entryMap(${_.shorthand(fn)})`)
631
- return ret
632
- }
633
- setName(_.entryMap.sync, 'entryMap')
634
-
635
- _.filter = fn => {
636
- const e = new TypeError()
637
- Error.captureStackTrace(e)
638
- const ret = async x => {
639
- if (_.isArray(x)) {
640
- const tasks = []
641
- for await (const a of x) tasks.push((async () => (await fn(a)) && a)())
642
- return (await Promise.all(tasks)).filter(_.id)
643
- }
644
- if (_.isSet(x)) {
645
- const tasks = []
646
- for await (const a of x) tasks.push((async () => (await fn(a)) && a)())
647
- return new Set((await Promise.all(tasks)).filter(_.id))
648
- }
649
- if (_.isMap(x)) {
650
- const tasks = [], y = new Map()
651
- for await (const [k, v] of x) tasks.push(
652
- (async () => { if (await fn(v)) { y.set(k, v) } })()
653
- )
654
- await Promise.all(tasks)
655
- return y
656
- }
657
- if (_.isObject(x)) {
658
- const tasks = [], y = {}
659
- for (const k in x) tasks.push(
660
- (async () => { if (await fn(x[k])) { y[k] = x[k] } })()
661
- )
662
- await Promise.all(tasks)
663
- return y
664
- }
665
- e.message = `cannot filter ${x}`
666
- throw e
667
- }
668
- setName(ret, `filter(${_.shorthand(fn)})`)
669
- return ret
670
- }
671
- setName(_.filter, 'filter')
672
-
673
- _.filter.sync = fn => {
674
- const e = new TypeError()
675
- Error.captureStackTrace(e)
676
- const ret = x => {
677
- if (_.isArray(x)) return x.filter(fn)
678
- if (_.isSet(x)) {
679
- const y = new Set()
680
- for (const a of x) { if (!fn(a)) continue; y.add(a) }
681
- return y
682
- }
683
- if (_.isMap(x)) {
684
- const y = new Map()
685
- for (const [k, v] of x) { if (!fn(v)) continue; y.set(k, v) }
686
- return y
687
- }
688
- if (_.isObject(x)) {
689
- const y = {}
690
- for (const k in x) { if (!fn(x[k])) continue; y[k] = x[k] }
691
- return y
692
- }
693
- e.message = `cannot filter ${x}`
694
- throw e
695
- }
696
- setName(ret, `filter(${_.shorthand(fn)})`)
697
- return ret
698
- }
699
- setName(_.filter.sync, 'filter')
700
-
701
- const nameReduce = (fn, x0) => {
702
- let name = `reduce(${_.shorthand(fn)}`
703
- if (_.exists(x0)) name += `, ${_.shorthand(x0)}`
704
- name += ')'
705
- return name
706
- }
707
-
708
- _.reduce = (fn, x0) => {
709
- const e = new TypeError()
710
- Error.captureStackTrace(e)
711
- const ret = async x => {
712
- if (_.isArray(x)) {
713
- } else if (_.isSet(x)) {
714
- x = Array.from(x)
715
- } else if (_.isMap(x)) {
716
- x = [...x.values()]
717
- } else if (_.isObject(x)) {
718
- x = Object.values(x)
719
- } else {
720
- e.message = `cannot reduce ${x}`
721
- throw e
722
- }
723
- let [y, i] = _.exists(x0) ? [x0, 0] : [x[0], 1]
724
- while (i < x.length) {
725
- y = await fn(y, x[i], i)
726
- i += 1
727
- }
728
- return y
729
- }
730
- setName(ret, nameReduce(fn, x0))
731
- return ret
732
- }
733
- setName(_.reduce, 'reduce')
734
-
735
- _.reduce.sync = (fn, x0) => {
736
- const e = new TypeError()
737
- Error.captureStackTrace(e)
738
- const ret = x => {
739
- if (_.isArray(x)) {
740
- } else if (_.isSet(x)) {
741
- x = Array.from(x)
742
- } else if (_.isMap(x)) {
743
- x = [...x.values()]
744
- } else if (_.isObject(x)) {
745
- x = Object.values(x)
746
- } else {
747
- e.message = `cannot reduce ${x}`
748
- throw e
749
- }
750
- let [y, i] = x0 ? [x0, 0] : [x[0], 1]
751
- while (i < x.length) {
752
- y = fn(y, x[i], i)
753
- i += 1
754
- }
755
- return y
756
- }
757
- setName(ret, nameReduce(fn, x0))
758
- return ret
759
- }
760
- setName(_.reduce.sync, 'reduce')
761
-
762
- _.not = fn => {
763
- fn = _.toFn(fn)
764
- const ret = async x => !(await fn(x))
765
- setName(ret, `not(${_.shorthand(fn)})`)
766
- return ret
767
- }
768
- setName(_.not, 'not')
769
-
770
- _.not.sync = fn => {
771
- fn = _.toFn(fn)
772
- const ret = x => !fn(x)
773
- setName(ret, `not(${_.shorthand(fn)})`)
774
- return ret
775
- }
776
- setName(_.not.sync, 'not')
777
-
778
- _.any = fn => {
779
- const e = new TypeError()
780
- Error.captureStackTrace(e)
781
- const ret = async x => {
782
- if (_.isObject(x)) {
783
- for (const k in await _.map(_.toFn(fn))(x)) {
784
- if (x[k]) return true
785
- }
786
- return false
787
- }
788
- if (_.isArray(x) || _.isSet(x) || _.isMap(x)) {
789
- for (const a of await _.map(_.toFn(fn))(x)) {
790
- if (a) return true
791
- }
792
- return false
793
- }
794
- e.message = `cannot any ${x}`
795
- throw e
796
- }
797
- setName(ret, `any(${_.shorthand(fn)})`)
798
- return ret
799
- }
800
- setName(_.any, 'any')
801
-
802
- _.any.sync = fn => {
803
- const e = new TypeError()
804
- Error.captureStackTrace(e)
805
- const ret = x => {
806
- if (_.isArray(x) || _.isSet(x) || _.isMap(x)) {
807
- for (const a of x) {
808
- if (_.toFn(fn)(a)) return true
809
- }
810
- return false
811
- }
812
- if (_.isObject(x)) {
813
- for (const k in x) {
814
- if (_.toFn(fn)(x[k])) return true
815
- }
816
- return false
817
- }
818
- e.message = `cannot any ${x}`
819
- throw e
820
- }
821
- setName(ret, `any(${_.shorthand(fn)})`)
822
- return ret
823
- }
824
- setName(_.any.sync, 'any')
825
-
826
- _.every = fn => {
827
- const e = new TypeError()
828
- Error.captureStackTrace(e)
829
- const ret = async x => {
830
- if (_.isArray(x) || _.isSet(x) || _.isMap(x)) {
831
- for (const a of await _.map(_.toFn(fn))(x)) {
832
- if (!a) return false
833
- }
834
- return true
835
- }
836
- if (_.isObject(x)) {
837
- for (const k in await _.map(_.toFn(fn))(x)) {
838
- if (!x[k]) return false
839
- }
840
- return true
841
- }
842
- e.message = `cannot every ${x}`
843
- throw e
844
- }
845
- setName(ret, `every(${_.shorthand(fn)})`)
846
- return ret
847
- }
848
- setName(_.every, 'every')
849
-
850
- _.every.sync = fn => {
851
- const e = new TypeError()
852
- Error.captureStackTrace(e)
853
- const ret = x => {
854
- if (_.isArray(x) || _.isSet(x) || _.isMap(x)) {
855
- for (const a of x) {
856
- if (!_.toFn(fn)(a)) return false
857
- }
858
- return true
859
- }
860
- if (_.isObject(x)) {
861
- for (const k in x) {
862
- if (!_.toFn(fn)(x[k])) return false
863
- }
864
- return true
865
- }
866
- e.message = `cannot every ${x}`
867
- throw e
868
- }
869
- setName(ret, `every(${_.shorthand(fn)})`)
870
- return ret
871
- }
872
- setName(_.every.sync, 'every')
873
-
874
- _.and = (...fns) => {
875
- fns = _.map.sync(_.toFn)(fns)
876
- const ret = (...x) => _.every(fn => fn(...x))(fns)
877
- setName(ret, `and(${fns.map(_.shorthand).join(', ')})`)
878
- return ret
879
- }
880
- setName(_.and, 'and')
881
-
882
- _.and.sync = (...fns) => {
883
- fns = _.map.sync(_.toFn)(fns)
884
- const ret = (...x) => _.every.sync(fn => fn(...x))(fns)
885
- setName(ret, `and(${fns.map(_.shorthand).join(', ')})`)
886
- return ret
887
- }
888
- setName(_.and.sync, 'and')
889
-
890
- _.or = (...fns) => {
891
- fns = _.map.sync(_.toFn)(fns)
892
- const ret = (...x) => _.any(fn => fn(...x))(fns)
893
- setName(ret, `or(${fns.map(_.shorthand).join(', ')})`)
894
- return ret
895
- }
896
- setName(_.or, 'or')
897
-
898
- _.or.sync = (...fns) => {
899
- fns = _.map.sync(_.toFn)(fns)
900
- const ret = (...x) => _.any.sync(fn => fn(...x))(fns)
901
- setName(ret, `or(${fns.map(_.shorthand).join(', ')})`)
902
- return ret
903
- }
904
- setName(_.or.sync, 'or')
905
-
906
- _.eq = (...fns) => {
907
- fns = _.map.sync(_.toFn)(fns)
908
- const ret = _.flow(
909
- _.diverge(fns),
910
- x => {
911
- for (let i = 1; i < x.length; i++) {
912
- if (x[i] !== x[0]) return false
913
- }
914
- return true
915
- },
916
- )
917
- setName(ret, `eq(${fns.map(_.shorthand).join(', ')})`)
918
- return ret
919
- }
920
- setName(_.eq, 'eq')
921
-
922
- _.eq.sync = (...fns) => {
923
- fns = _.map.sync(_.toFn)(fns)
924
- const ret = _.flow.sync(
925
- _.diverge.sync(fns),
926
- x => {
927
- for (let i = 1; i < x.length; i++) {
928
- if (x[i] !== x[0]) return false
929
- }
930
- return true
931
- },
932
- )
933
- setName(ret, `eq(${fns.map(_.shorthand).join(', ')})`)
934
- return ret
935
- }
936
- setName(_.eq.sync, 'eq')
937
-
938
- _.lt = (...fns) => {
939
- fns = _.map.sync(_.toFn)(fns)
940
- const ret = _.flow(
941
- _.diverge(fns),
942
- x => {
943
- for (let i = 1; i < x.length; i++) {
944
- if (x[i - 1] >= x[i]) return false
945
- }
946
- return true
947
- },
948
- )
949
- setName(ret, `lt(${fns.map(_.shorthand).join(', ')})`)
950
- return ret
951
- }
952
- setName(_.lt, 'lt')
953
-
954
- _.lt.sync = (...fns) => {
955
- fns = _.map.sync(_.toFn)(fns)
956
- const ret = _.flow.sync(
957
- _.diverge.sync(fns),
958
- x => {
959
- for (let i = 1; i < x.length; i++) {
960
- if (x[i - 1] >= x[i]) return false
961
- }
962
- return true
963
- },
964
- )
965
- setName(ret, `lt(${fns.map(_.shorthand).join(', ')})`)
966
- return ret
967
- }
968
- setName(_.lt.sync, 'lt')
969
-
970
- _.lte = (...fns) => {
971
- fns = _.map.sync(_.toFn)(fns)
972
- const ret = _.flow(
973
- _.diverge(fns),
974
- x => {
975
- for (let i = 1; i < x.length; i++) {
976
- if (x[i - 1] > x[i]) return false
977
- }
978
- return true
979
- },
980
- )
981
- setName(ret, `lte(${fns.map(_.shorthand).join(', ')})`)
982
- return ret
983
- }
984
- setName(_.lte, 'lte')
985
-
986
- _.lte.sync = (...fns) => {
987
- fns = _.map.sync(_.toFn)(fns)
988
- const ret = _.flow.sync(
989
- _.diverge.sync(fns),
990
- x => {
991
- for (let i = 1; i < x.length; i++) {
992
- if (x[i - 1] > x[i]) return false
993
- }
994
- return true
995
- },
996
- )
997
- setName(ret, `lte(${fns.map(_.shorthand).join(', ')})`)
998
- return ret
999
- }
1000
- setName(_.lte.sync, 'lte')
1001
-
1002
- _.gt = (...fns) => {
1003
- fns = _.map.sync(_.toFn)(fns)
1004
- const ret = _.flow(
1005
- _.diverge(fns),
1006
- x => {
1007
- for (let i = 1; i < x.length; i++) {
1008
- if (x[i - 1] <= x[i]) return false
1009
- }
1010
- return true
1011
- },
1012
- )
1013
- setName(ret, `gt(${fns.map(_.shorthand).join(', ')})`)
1014
- return ret
1015
- }
1016
- setName(_.gt, 'gt')
1017
-
1018
- _.gt.sync = (...fns) => {
1019
- fns = _.map.sync(_.toFn)(fns)
1020
- const ret = _.flow.sync(
1021
- _.diverge.sync(fns),
1022
- x => {
1023
- for (let i = 1; i < x.length; i++) {
1024
- if (x[i - 1] <= x[i]) return false
1025
- }
1026
- return true
1027
- },
1028
- )
1029
- setName(ret, `gt(${fns.map(_.shorthand).join(', ')})`)
1030
- return ret
1031
- }
1032
- setName(_.gt.sync, 'gt')
1033
-
1034
- _.gte = (...fns) => {
1035
- fns = _.map.sync(_.toFn)(fns)
1036
- const ret = _.flow(
1037
- _.diverge(fns),
1038
- x => {
1039
- for (let i = 1; i < x.length; i++) {
1040
- if (x[i - 1] < x[i]) return false
1041
- }
1042
- return true
1043
- },
1044
- )
1045
- setName(ret, `gte(${fns.map(_.shorthand).join(', ')})`)
1046
- return ret
1047
- }
1048
- setName(_.gte, 'gte')
1049
-
1050
- _.gte.sync = (...fns) => {
1051
- fns = _.map.sync(_.toFn)(fns)
1052
- const ret = _.flow.sync(
1053
- _.diverge.sync(fns),
1054
- x => {
1055
- for (let i = 1; i < x.length; i++) {
1056
- if (x[i - 1] < x[i]) return false
1057
- }
1058
- return true
1059
- },
1060
- )
1061
- setName(ret, `gte(${fns.map(_.shorthand).join(', ')})`)
1062
- return ret
1063
- }
1064
- setName(_.gte.sync, 'gte')
1065
-
1066
- const simpleGet = k => x => {
1067
- if (typeof x !== 'object') return undefined
1068
- if (_.isMap(x)) return x.get(k)
1069
- return x[k]
1070
- }
1071
-
1072
- const keyToPath = k => {
1073
- if (_.isString(k)) return k.split('.')
1074
- if (_.isArray(k)) return k
1075
- return [k]
1076
- }
1077
-
1078
- _.get = (key, defaultValue) => {
1079
- const path = keyToPath(key)
1080
- const ret = x => {
1081
- let y = x
1082
- for (const k of path) {
1083
- y = simpleGet(k)(y)
1084
- if (_.dne(y)) return defaultValue
1085
- }
1086
- return y
1087
- }
1088
- const nameArgs = [_.shorthand(key)]
1089
- if (_.exists(defaultValue)) nameArgs.push(_.shorthand(defaultValue))
1090
- setName(ret, `get(${nameArgs.join(', ')})`)
1091
- return ret
1092
- }
1093
- setName(_.get, 'get')
1094
-
1095
- _.lookup = x => {
1096
- const ret = k => _.get(k)(x)
1097
- setName(ret, `lookup(${_.shorthand(x)})`)
1098
- return ret
1099
- }
1100
- setName(_.lookup, 'lookup')
1101
-
1102
- const namePut = ents => {
1103
- const nameArgs = []
1104
- for (const [k, fn] of ents) {
1105
- nameArgs.push(`[${k}, ${_.shorthand(_.toFn(fn))}]`)
1106
- }
1107
- return `put(${nameArgs.join(', ')})`
1108
- }
1109
-
1110
- _.put = (...ents) => {
1111
- const ret = async x => {
1112
- const y = _.copy(x), tasks = []
1113
- for (const [k, fn] of ents) {
1114
- const a = _.toFn(fn)(x)
1115
- if (_.isPromise(a)) tasks.push(a.then(b => { y[k] = b }))
1116
- else { y[k] = a }
1117
- }
1118
- await Promise.all(tasks)
1119
- return y
1120
- }
1121
- setName(ret, namePut(ents))
1122
- return ret
1123
- }
1124
- setName(_.put, 'put')
1125
-
1126
- _.put.sync = (...ents) => {
1127
- const ret = x => {
1128
- const y = _.copy(x)
1129
- for (const [k, fn] of ents) {
1130
- y[k] = _.toFn(fn)(x)
1131
- }
1132
- return y
1133
- }
1134
- setName(ret, namePut(ents))
1135
- return ret
1136
- }
1137
- setName(_.put.sync, 'put')
1138
-
1139
- // https://jsperf.com/multi-array-concat/7
1140
- _.concat = (...fns) => {
1141
- const e = new TypeError()
1142
- Error.captureStackTrace(e)
1143
- fns = _.map.sync(_.toFn)(fns)
1144
- const ret = async x => {
1145
- if (!_.isString(x) && !_.isArray(x)) {
1146
- e.message = `cannot concat to ${x}`
1147
- throw e
1148
- }
1149
- const items = await _.map(fn => fn(x))(fns)
1150
- return x.constructor.prototype.concat.apply(x, items)
1151
- }
1152
- setName(ret, `concat(${_.map.sync(_.shorthand)(fns).join(', ')})`)
1153
- return ret
1154
- }
1155
- setName(_.concat, 'concat')
1156
-
1157
- _.concat.sync = (...fns) => {
1158
- const e = new TypeError()
1159
- Error.captureStackTrace(e)
1160
- fns = _.map.sync(_.toFn)(fns)
1161
- const ret = x => {
1162
- if (!_.isString(x) && !_.isArray(x)) {
1163
- e.message = `cannot concat to ${x}`
1164
- throw e
1165
- }
1166
- const items = _.map.sync(fn => _.toFn(fn)(x))(fns)
1167
- return x.constructor.prototype.concat.apply(x, items)
1168
- }
1169
- setName(ret, `concat(${_.map.sync(_.shorthand)(fns).join(', ')})`)
1170
- return ret
1171
- }
1172
- setName(_.concat.sync, 'concat')
1173
-
1174
- _.has = m => {
1175
- const e = new TypeError()
1176
- Error.captureStackTrace(e)
1177
- const ret = col => {
1178
- if (_.isString(col)) return col.includes(m)
1179
- if (_.isArray(col)) return col.includes(m)
1180
- if (_.isSet(col)) return col.has(m)
1181
- if (_.isMap(col)) return col.has(m)
1182
- if (_.isObject(col)) return !!_.get(m)(col)
1183
- if (_.isBuffer(col)) return _.toString(col).includes(m)
1184
- e.message = `cannot has ${col}`
1185
- throw e
1186
- }
1187
- setName(ret, `has(${_.shorthand(m)})`)
1188
- return ret
1189
- }
1190
- setName(_.has, 'has')
1191
-
1192
- _.member = col => {
1193
- let ret
1194
- if (_.isString(col)) ret = m => col.includes(m)
1195
- else if (_.isArray(col)) ret = m => col.includes(m)
1196
- else if (_.isSet(col)) ret = m => col.has(m)
1197
- else if (_.isMap(col)) ret = m => col.has(m)
1198
- else if (_.isObject(col)) ret = m => !!_.get(m)(col)
1199
- else if (_.isBuffer(x)) ret = m => _.toString(col).includes(m)
1200
- else throw new TypeError(`cannot member ${col}`)
1201
- setName(ret, `member(${_.shorthand(col)})`)
1202
- return ret
1203
- }
1204
- setName(_.member, 'member')
1205
-
1206
- _.log = tag => {
1207
- const ret = _.effect.sync(() => console.log(tag))
1208
- setName(ret, `log(${_.inspect(tag)})`)
1209
- return ret
1210
- }
1211
- setName(_.log, 'log')
1212
-
1213
- _.trace = tag => {
1214
- const ret = _.effect.sync(x => {
1215
- const args = []
1216
- if (_.exists(tag)) args.push(tag)
1217
- args.push(_.inspect(x))
1218
- console.log(...args)
1219
- })
1220
- setName(ret, `trace(${_.inspect(tag)})`)
1221
- return ret
1222
- }
1223
- setName(_.trace, 'trace')
1224
-
1225
- _.tracep = (p, tag) => {
1226
- const ret = _.effect.sync(x => {
1227
- const args = []
1228
- if (_.exists(tag)) args.push(tag)
1229
- const fmtp = _.isArray(p) ? p.join('.') : p
1230
- args.push(`.${fmtp} -`, _.inspect(_.get(p)(x)))
1231
- console.log(...args)
1232
- })
1233
- const nameArgs = [_.inspect(p)]
1234
- if (_.exists(tag)) nameArgs.push(_.inspect(tag))
1235
- setName(ret, `tracep(${nameArgs.join(', ')})`)
1236
- return ret
1237
- }
1238
- setName(_.tracep, 'tracep')
1239
-
1240
- _.tracef = (fn, tag) => {
1241
- const ret = _.effect(async x => {
1242
- const args = []
1243
- if (_.exists(tag)) args.push(tag)
1244
- args.push(_.inspect(await _.toFn(fn)(x)))
1245
- console.log(...args)
1246
- })
1247
- const nameArgs = [_.shorthand(fn)]
1248
- if (_.exists(tag)) nameArgs.push(_.shorthand(tag))
1249
- setName(ret, `tracef(${nameArgs.join(', ')})`)
1250
- return ret
1251
- }
1252
- setName(_.tracef, 'tracef')
1253
-
1254
- _.tracef.sync = (fn, tag) => {
1255
- const ret = _.effect.sync(x => {
1256
- const args = []
1257
- if (_.exists(tag)) args.push(tag)
1258
- args.push(_.inspect(_.toFn(fn)(x)))
1259
- console.log(...args)
1260
- })
1261
- const nameArgs = [_.shorthand(fn)]
1262
- if (_.exists(tag)) nameArgs.push(_.shorthand(tag))
1263
- setName(ret, `tracef(${nameArgs.join(', ')})`)
1264
- return ret
1265
- }
1266
- setName(_.tracef.sync, 'tracef')
1267
-
1268
- _.promisify = util.promisify
1269
- setName(_.promisify, 'promisify')
1270
-
1271
- _.callbackify = util.callbackify
1272
- setName(_.callbackify, 'callbackify')
1273
-
1274
- _.promisifyAll = x => {
1275
- const y = {}
1276
- if (!x) return y
1277
- for (k in x) {
1278
- const v = x[k]
1279
- if (!_.isFn(v)) { y[k] = v; continue }
1280
- y[k] = _.promisify(v.bind(x))
1281
- }
1282
- for (k in x.__proto__ || {}) {
1283
- const v = x.__proto__[k]
1284
- if (!_.isFn(v)) { y[k] = v; continue }
1285
- y[k] = _.promisify(v.bind(x))
1286
- }
1287
- return y
1288
- }
1289
- setName(_.promisifyAll, 'promisifyAll')
1290
-
1291
- _.callbackifyAll = x => {
1292
- const y = {}
1293
- if (!x) return y
1294
- for (k in x) {
1295
- const v = x[k]
1296
- if (!_.isFn(v)) { y[k] = v; continue }
1297
- y[k] = _.callbackify(v.bind(x))
1298
- }
1299
- for (k in x.__proto__ || {}) {
1300
- const v = x.__proto__[k]
1301
- if (!_.isFn(v)) { y[k] = v; continue }
1302
- y[k] = _.callbackify(v.bind(x))
1303
- }
1304
- return y
1305
- }
1306
- setName(_.callbackifyAll, 'callbackifyAll')
1307
-
1308
- _.pick = (...keys) => {
1309
- const e = new TypeError()
1310
- Error.captureStackTrace(e)
1311
- const ret = x => {
1312
- if (!_.isObject(x)) {
1313
- e.message = `cannot pick ${x}`
1314
- throw e
1315
- }
1316
- const y = {}
1317
- for (const k of keys) {
1318
- const v = x[k]
1319
- if (_.dne(v)) continue
1320
- y[k] = v
1321
- }
1322
- return y
1323
- }
1324
- setName(ret, `pick(${keys.map(_.shorthand).join(', ')})`)
1325
- return ret
1326
- }
1327
- setName(_.pick, 'pick')
1328
-
1329
- _.exclude = (...keys) => {
1330
- const e = new TypeError()
1331
- Error.captureStackTrace(e)
1332
- const ret = x => {
1333
- if (!_.isObject(x)) {
1334
- e.message = `cannot exclude ${x}`
1335
- throw e
1336
- }
1337
- const y = { ...x }
1338
- for (const k of keys) {
1339
- delete y[k]
1340
- }
1341
- return y
1342
- }
1343
- setName(ret, `exclude(${keys.map(_.shorthand).join(', ')})`)
1344
- return ret
1345
- }
1346
- setName(_.exclude, 'exclude')
1347
-
1348
- _.slice = (from, to) => {
1349
- const ret = x => {
1350
- let f = from, t = to
1351
- if (_.dne(f)) f = 0
1352
- else if (f < 0) f += x.length
1353
- if (_.dne(t)) t = x.length
1354
- else if (t < 0) t += x.length
1355
- f = Math.max(0, Math.min(f, x.length))
1356
- t = Math.max(0, Math.min(t, x.length))
1357
- let y = []
1358
- for (let i = f; i < t; i++) y.push(x[i])
1359
- if (_.isString(x)) y = y.join('')
1360
- return y
1361
- }
1362
- const nameArgs = [_.shorthand(from)]
1363
- if (_.exists(to)) nameArgs.push(_.shorthand(to))
1364
- setName(ret, `slice(${nameArgs.join(', ')})`)
1365
- return ret
1366
- }
1367
- setName(_.slice, 'slice')
1368
-
1369
- _.replaceOne = (s, r) => {
1370
- if (_.dne(r)) throw new TypeError('no replacement provided')
1371
- if (!_.isString(r) && !_.isNumber(r)) {
1372
- throw new TypeError(`bad replacement ${r}`)
1373
- }
1374
- if (!_.isString(s)) {
1375
- throw new TypeError(`cannot replace ${s}`)
1376
- }
1377
- const rx = _.toRegExp(s)
1378
- const e = new TypeError()
1379
- Error.captureStackTrace(e)
1380
- const ret = x => {
1381
- if (!_.isString(x)) {
1382
- e.message = `cannot replace for ${x}`
1383
- throw e
1384
- }
1385
- return x.replace(rx, _.toString(r))
1386
- }
1387
- setName(ret, `replaceOne(${_.shorthand(s)}, ${_.shorthand(r)})`)
1388
- return ret
1389
- }
1390
- setName(_.replaceOne, 'replaceOne')
1391
-
1392
- _.replaceAll = (s, r) => {
1393
- if (_.dne(r)) throw new TypeError('no replacement provided')
1394
- if (!_.isString(r) && !_.isNumber(r)) {
1395
- throw new TypeError(`bad replacement ${r}`)
1396
- }
1397
- if (!_.isString(s)) {
1398
- throw new TypeError(`cannot replace ${s}`)
1399
- }
1400
- const rx = _.toRegExp(s, 'g')
1401
- const e = new TypeError()
1402
- Error.captureStackTrace(e)
1403
- const ret = x => {
1404
- if (!_.isString(x)) {
1405
- e.message = `cannot replace for ${x}`
1406
- throw e
1407
- }
1408
- return x.replace(rx, _.toString(r))
1409
- }
1410
- setName(ret, `replaceAll(${_.shorthand(s)}, ${_.shorthand(r)})`)
1411
- return ret
1412
- }
1413
- setName(_.replaceAll, 'replaceAll')
1414
-
1415
- _.join = d => {
1416
- if (_.dne(d)) throw new TypeError('no delimiter provided')
1417
- if (!_.isString(d) && !_.isNumber(d)) {
1418
- throw new TypeError(`bad delimiter ${d}`)
1419
- }
1420
- const e = new TypeError()
1421
- Error.captureStackTrace(e)
1422
- const ret = x => {
1423
- if (!_.isArray(x)) {
1424
- e.message = `cannot join ${x}`
1425
- throw e
1426
- }
1427
- return x.join(d)
1428
- }
1429
- setName(ret, `join(${_.shorthand(d)})`)
1430
- return ret
1431
- }
1432
- setName(_.join, 'join')
1433
-
1434
- _.split = d => {
1435
- if (_.dne(d)) throw new TypeError('no delimiter provided')
1436
- if (!_.isString(d) && !_.isNumber(d)) {
1437
- throw new TypeError(`bad delimiter ${d}`)
1438
- }
1439
- const e = new TypeError()
1440
- Error.captureStackTrace(e)
1441
- const ret = x => {
1442
- if (!_.isString(x)) {
1443
- e.message = `cannot split ${x}`
1444
- throw e
1445
- }
1446
- return x.split(d)
1447
- }
1448
- setName(ret, `split(${_.shorthand(d)})`)
1449
- return ret
1450
- }
1451
- setName(_.split, 'split')
1452
-
1453
- _.lowercase = x => {
1454
- if (!_.isString(x)) throw new TypeError(`cannot lowercase ${x}`)
1455
- return x.toLowerCase()
1456
- }
1457
- setName(_.lowercase, 'lowercase')
1458
-
1459
- _.uppercase = x => {
1460
- if (!_.isString(x)) throw new TypeError(`cannot uppercase ${x}`)
1461
- return x.toUpperCase()
1462
- }
1463
- setName(_.uppercase, 'uppercase')
1464
-
1465
- _.capitalize = x => {
1466
- if (!_.isString(x)) throw new TypeError(`cannot capitalize ${x}`)
1467
- const s = _.toString(x)
1468
- if (s.length === 0) return ''
1469
- return `${s[0].toUpperCase()}${s.slice(1)}`
1470
- }
1471
- setName(_.capitalize, 'capitalize')
1472
-
1473
- _.braid = (...rates) => {
1474
- const e = new Error()
1475
- Error.captureStackTrace(e)
1476
- const ret = x => {
1477
- if (!_.isArray(x) || !x.every(_.isArray)) {
1478
- e.name = 'TypeError'
1479
- e.message = 'point must be an array of arrays'
1480
- throw e
1481
- }
1482
- if (x.length !== rates.length) {
1483
- e.message = 'point length must === number of rates'
1484
- throw e
1485
- }
1486
- const y = []
1487
- const iterators = x.map(y => y.values())
1488
- let i = 0
1489
- while (iterators.length > 0) {
1490
- const modi = i % iterators.length
1491
- for (let j = 0; j < rates[modi]; j++) {
1492
- const v = iterators[modi].next()
1493
- if (v.done) {
1494
- iterators.splice(modi, 1)
1495
- break
1496
- }
1497
- y.push(v.value)
1498
- }
1499
- i += 1
1500
- }
1501
- return y
1502
- }
1503
- setName(ret, `braid(${rates.map(_.shorthand).join(', ')})`)
1504
- return ret
1505
- }
1506
- setName(_.braid, 'braid')
1507
-
1508
- _.unbraid = (...rates) => {
1509
- const e = new Error()
1510
- Error.captureStackTrace(e)
1511
- const ret = x => {
1512
- if (!_.isArray(x)) {
1513
- e.name = 'TypeError'
1514
- e.message = 'point must be an array'
1515
- throw e
1516
- }
1517
- const y = []
1518
- for (let k = 0; k < rates.length; k++) y.push([])
1519
- let i = 0, ri = 0
1520
- while (i < x.length) {
1521
- const modi = ri % rates.length
1522
- for (let j = 0; j < rates[modi]; j++) {
1523
- y[modi].push(x[i])
1524
- i += 1
1525
- }
1526
- ri += 1
1527
- }
1528
- return y
1529
- }
1530
- setName(ret, `unbraid(${rates.map(_.shorthand).join(', ')})`)
1531
- return ret
1532
- }
1533
- setName(_.unbraid, 'unbraid')
1534
-
1535
- _.transpose = x => {
1536
- if (!_.isArray(x)) throw new TypeError('point must be an array')
1537
- const y = []
1538
- for (let i = 0; i < x.length; i++) {
1539
- for (let j = 0; j < x[i].length; j++) {
1540
- if (!y[j]) y[j] = []
1541
- y[j][i] = x[i][j]
1542
- }
1543
- }
1544
- return y
1545
- }
1546
- setName(_.transpose, 'transpose')
1547
-
1548
- _.flatten = x => {
1549
- if (!_.isArray(x)) throw new TypeError('point must be an array')
1550
- return x.flat(1)
1551
- }
1552
- setName(_.flatten, 'flatten')
1553
-
1554
- _.flattenAll = x => {
1555
- if (!_.isArray(x)) throw new TypeError('point must be an array')
1556
- return x.flat(Infinity)
1557
- }
1558
- setName(_.flattenAll, 'flattenAll')
1559
-
1560
- _.uniq = x => {
1561
- if (!_.isArray(x)) throw new TypeError('point must be an array')
1562
- const mem = new Set()
1563
- const y = []
1564
- for (const a of x) {
1565
- if (mem.has(a)) continue
1566
- mem.add(a)
1567
- y.push(a)
1568
- }
1569
- return y
1570
- }
1571
- setName(_.uniq, 'uniq')
1572
-
1573
- _.first = x => {
1574
- if (!_.isArray(x)) throw new TypeError('point must be an array')
1575
- return _.get(0)(x)
1576
- }
1577
- setName(_.first, 'first')
1578
-
1579
- _.last = x => {
1580
- if (!_.isArray(x)) throw new TypeError('point must be an array')
1581
- return x[x.length - 1]
1582
- }
1583
- setName(_.last, 'last')
1584
-
1585
- _.reverse = x => {
1586
- if (!_.isArray(x)) throw new TypeError('point must be an array')
1587
- return x.slice(0).reverse()
1588
- }
1589
- setName(_.reverse, 'reverse')
1590
-
1591
- _.compare = (a, b) => {
1592
- if (a < b) return -1
1593
- if (a > b) return 1
1594
- return 0
1595
- }
1596
- setName(_.compare, 'compare')
1597
-
1598
- _.sort = (order = 1) => {
1599
- const e = new TypeError()
1600
- Error.captureStackTrace(e)
1601
- const ret = x => {
1602
- if (!_.isArray(x)) {
1603
- e.message = 'point must be an array'
1604
- throw e
1605
- }
1606
- return x.sort(
1607
- (a, b) => order * _.compare(a, b)
1608
- )
1609
- }
1610
- setName(ret, `sort(${_.shorthand(order)})`)
1611
- return ret
1612
- }
1613
- setName(_.sort, 'sort')
1614
-
1615
- // TODO: take function instead of prop
1616
- _.sortBy = (k, order = 1) => {
1617
- const e = new TypeError()
1618
- Error.captureStackTrace(e)
1619
- const ret = x => {
1620
- if (!_.isArray(x)) {
1621
- e.message = 'point must be an array'
1622
- throw e
1623
- }
1624
- return x.sort(
1625
- (a, b) => order * _.compare(_.get(k)(a), _.get(k)(b))
1626
- )
1627
- }
1628
- setName(ret, `sortBy(${_.shorthand(k)}, ${_.shorthand(order)})`)
1629
- return ret
1630
- }
1631
- setName(_.sortBy, 'sortBy')
1632
-
1633
- _.size = x => {
1634
- if (_.isString(x)) return x.length
1635
- if (_.isArray(x)) return x.length
1636
- if (_.isSet(x)) return x.size
1637
- if (_.isMap(x)) return x.size
1638
- if (_.isObject(x)) {
1639
- let y = 0
1640
- for (const k in x) if (x.hasOwnProperty(k)) y += 1
1641
- return y
1642
- }
1643
- throw new TypeError(`cannot size ${x}`)
1644
- }
1645
- setName(_.size, 'size')
1646
-
1647
- _.isEmpty = x => _.size(x) === 0
1648
- setName(_.isEmpty, 'isEmpty')
1649
-
1650
- _.once = fn => {
1651
- const ret = (...args) => {
1652
- let ret = null
1653
- if (ret) return ret
1654
- ret = fn(...args)
1655
- return ret
1656
- }
1657
- setName(ret, `once(${_.shorthand(fn)})`)
1658
- return ret
1659
- }
1660
- setName(_.once, 'once')
1661
-
1662
- _.spaces = l => {
1663
- let s = ''
1664
- for (let i = 0; i < l; i++) s += ' '
1665
- return s
1666
- }
1667
- setName(_.spaces, 'spaces')
1668
-
1669
- _.prettifyJSON = x => JSON.stringify(x, null, 2)
1670
- setName(_.prettifyJSON, 'prettifyJSON')
1671
-
1672
- _.hash = alg => {
1673
- const ret = x => crypto.createHash(alg).update(x).digest('hex')
1674
- setName(ret, `hash(${_.shorthand(alg)})`)
1675
- return ret
1676
- }
1677
- setName(_.hash, 'hash')
1678
-
1679
- _.sha256 = _.hash('sha256')
1680
- setName(_.sha256, 'sha256')
1681
-
1682
- _.sha512 = _.hash('sha512')
1683
- setName(_.sha512, 'sha512')
1684
-
1685
- module.exports = _