rubico 1.9.7 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +3 -2
  3. package/.github/workflows/nodejs.yml +1 -1
  4. package/AggregateReducer.js +19 -0
  5. package/AggregateReducer.test.js +82 -0
  6. package/CHANGELOG.md +22 -1
  7. package/README.md +158 -81
  8. package/Transducer.js +75 -26
  9. package/Transducer.test.js +117 -0
  10. package/_internal/ComparisonOperator.js +68 -0
  11. package/_internal/File.js +41 -0
  12. package/_internal/FlatMappingAsyncIterator.js +4 -4
  13. package/_internal/FlatMappingIterator.js +1 -1
  14. package/_internal/TimeInLoopSuite.js +138 -0
  15. package/_internal/areAnyValuesPromises.js +23 -0
  16. package/_internal/{arrayAll.js → arrayEvery.js} +4 -4
  17. package/_internal/arrayExtend.js +3 -2
  18. package/_internal/arrayFilter.js +3 -4
  19. package/_internal/{arrayAny.js → arraySome.js} +8 -8
  20. package/_internal/{asyncIteratorAll.js → asyncIteratorEvery.js} +4 -4
  21. package/_internal/{asyncIteratorAny.js → asyncIteratorSome.js} +4 -4
  22. package/_internal/curry4.test.js +25 -0
  23. package/_internal/curry5.test.js +29 -0
  24. package/_internal/curryArgs2.js +43 -0
  25. package/_internal/curryArgs3.test.js +21 -0
  26. package/_internal/curryArgs4.js +65 -0
  27. package/_internal/curryArgs4.test.js +25 -0
  28. package/_internal/equals.js +13 -0
  29. package/_internal/findAllFilePaths.js +22 -0
  30. package/_internal/funcApply.js +2 -0
  31. package/_internal/funcCall.js +14 -0
  32. package/_internal/functionArrayAll.js +26 -0
  33. package/_internal/functionArrayAllSeries.js +55 -0
  34. package/_internal/functionObjectAll.js +32 -0
  35. package/_internal/genericReduce.js +4 -22
  36. package/_internal/genericTransform.js +15 -15
  37. package/_internal/improvedGenericTransform.js +93 -0
  38. package/_internal/{iteratorAll.js → iteratorEvery.js} +4 -4
  39. package/_internal/{iteratorAny.js → iteratorSome.js} +6 -6
  40. package/_internal/leftResolverRightResolverCompare.js +19 -0
  41. package/_internal/leftResolverRightValueCompare.js +16 -0
  42. package/_internal/leftValueRightResolverCompare.js +16 -0
  43. package/_internal/objectReduce.js +0 -1
  44. package/_internal/pathResolve.js +6 -0
  45. package/_internal/{reducerAll.js → reducerEvery.js} +4 -4
  46. package/_internal/reducerFlatMap.js +4 -4
  47. package/_internal/reducerFlatten.js +1 -1
  48. package/_internal/{reducerAny.js → reducerSome.js} +4 -4
  49. package/_internal/timeInLoop.js +37 -0
  50. package/_internal/timeInLoop.test.js +18 -0
  51. package/_internal/timeInLoopAsync.js +35 -0
  52. package/_internal/timeInLoopAsync.test.js +22 -0
  53. package/all.js +106 -40
  54. package/and.js +54 -36
  55. package/archive/{FlatMappingIteratorCool.js → FlatMappingIterator-2020-09-28.js} +1 -1
  56. package/archive/_Promise-2023-05-29.js +93 -0
  57. package/archive/arrayMap2-2023-05-29.js +73 -0
  58. package/archive/benchmarks-v1.9.7/all.js +34 -0
  59. package/archive/benchmarks-v1.9.7/and.js +24 -0
  60. package/archive/benchmarks-v1.9.7/assign.js +174 -0
  61. package/archive/benchmarks-v1.9.7/curry.js +55 -0
  62. package/archive/benchmarks-v1.9.7/eq.js +25 -0
  63. package/archive/benchmarks-v1.9.7/filter.js +1322 -0
  64. package/archive/benchmarks-v1.9.7/flatMap.js +48 -0
  65. package/archive/benchmarks-v1.9.7/get.js +44 -0
  66. package/archive/benchmarks-v1.9.7/gt.js +25 -0
  67. package/archive/benchmarks-v1.9.7/gte.js +25 -0
  68. package/archive/benchmarks-v1.9.7/lt.js +25 -0
  69. package/archive/benchmarks-v1.9.7/lte.js +25 -0
  70. package/archive/benchmarks-v1.9.7/map.js +892 -0
  71. package/archive/benchmarks-v1.9.7/omit.js +28 -0
  72. package/archive/benchmarks-v1.9.7/or.js +51 -0
  73. package/archive/benchmarks-v1.9.7/pick.js +24 -0
  74. package/archive/benchmarks-v1.9.7/pipe.js +152 -0
  75. package/archive/benchmarks-v1.9.7/reduce.js +739 -0
  76. package/archive/benchmarks-v1.9.7/switchCase.js +256 -0
  77. package/archive/benchmarks-v1.9.7/tap.js +90 -0
  78. package/archive/benchmarks-v1.9.7/transform.js +218 -0
  79. package/archive/benchmarks-v1.9.7/tryCatch.js +108 -0
  80. package/assign.js +18 -8
  81. package/bench +65 -0
  82. package/benchmark-output/v1.9.7 +268 -0
  83. package/benchmarks/all.async.js +43 -0
  84. package/benchmarks/all.js +42 -33
  85. package/benchmarks/always.js +15 -0
  86. package/benchmarks/and.async.js +25 -0
  87. package/benchmarks/and.js +20 -19
  88. package/benchmarks/assign.async.js +27 -0
  89. package/benchmarks/assign.js +20 -167
  90. package/benchmarks/curry.js +34 -54
  91. package/benchmarks/eq.async.js +23 -0
  92. package/benchmarks/eq.js +17 -19
  93. package/benchmarks/every.async.js +19 -0
  94. package/benchmarks/every.js +19 -0
  95. package/benchmarks/filter.async.js +32 -0
  96. package/benchmarks/filter.js +27 -1311
  97. package/benchmarks/flatMap.async.js +26 -0
  98. package/benchmarks/flatMap.js +26 -36
  99. package/benchmarks/get.async.js +19 -0
  100. package/benchmarks/get.js +27 -32
  101. package/benchmarks/gt.async.js +23 -0
  102. package/benchmarks/gt.js +17 -19
  103. package/benchmarks/gte.async.js +23 -0
  104. package/benchmarks/gte.js +17 -19
  105. package/benchmarks/lt.async.js +23 -0
  106. package/benchmarks/lt.js +17 -19
  107. package/benchmarks/lte.async.js +23 -0
  108. package/benchmarks/lte.js +17 -19
  109. package/benchmarks/map.async.js +43 -0
  110. package/benchmarks/map.js +24 -876
  111. package/benchmarks/misc/Promise.js +26 -0
  112. package/benchmarks/misc/isPromise.js +30 -0
  113. package/benchmarks/misc/promiseAll.js +36 -0
  114. package/benchmarks/not.js +23 -0
  115. package/benchmarks/omit.js +30 -20
  116. package/benchmarks/or.async.js +25 -0
  117. package/benchmarks/or.js +23 -49
  118. package/benchmarks/pick.js +30 -16
  119. package/benchmarks/pipe.async.js +47 -0
  120. package/benchmarks/pipe.js +46 -151
  121. package/benchmarks/reduce.async.js +32 -0
  122. package/benchmarks/reduce.js +27 -728
  123. package/benchmarks/set.async.js +19 -0
  124. package/benchmarks/set.js +41 -0
  125. package/benchmarks/some.async.js +19 -0
  126. package/benchmarks/some.js +19 -0
  127. package/benchmarks/switchCase.async.js +27 -0
  128. package/benchmarks/switchCase.js +55 -256
  129. package/benchmarks/tap.js +10 -85
  130. package/benchmarks/thunkify.js +15 -0
  131. package/benchmarks/transform.async.js +27 -0
  132. package/benchmarks/transform.js +28 -206
  133. package/benchmarks/tryCatch.async.js +25 -0
  134. package/benchmarks/tryCatch.js +24 -100
  135. package/build +472 -0
  136. package/compose.js +46 -0
  137. package/dist/Transducer.es.js +481 -0
  138. package/dist/Transducer.es.min.js +7 -0
  139. package/dist/Transducer.js +488 -0
  140. package/dist/Transducer.min.js +8 -0
  141. package/dist/Transducer.mjs +481 -0
  142. package/dist/__.es.js +2 -2
  143. package/dist/__.es.min.js +2 -2
  144. package/dist/__.js +2 -2
  145. package/dist/__.min.js +2 -2
  146. package/dist/__.mjs +2 -2
  147. package/dist/all.es.js +173 -92
  148. package/dist/all.es.min.js +3 -3
  149. package/dist/all.js +173 -92
  150. package/dist/all.min.js +3 -3
  151. package/dist/all.mjs +173 -92
  152. package/dist/always.es.js +2 -2
  153. package/dist/always.es.min.js +2 -2
  154. package/dist/always.js +2 -2
  155. package/dist/always.min.js +2 -2
  156. package/dist/always.mjs +2 -2
  157. package/dist/and.es.js +101 -32
  158. package/dist/and.es.min.js +3 -3
  159. package/dist/and.js +101 -32
  160. package/dist/and.min.js +3 -3
  161. package/dist/and.mjs +101 -32
  162. package/dist/assign.es.js +37 -10
  163. package/dist/assign.es.min.js +3 -3
  164. package/dist/assign.js +37 -10
  165. package/dist/assign.min.js +3 -3
  166. package/dist/assign.mjs +37 -10
  167. package/dist/compose.es.js +71 -0
  168. package/dist/compose.es.min.js +7 -0
  169. package/dist/compose.js +78 -0
  170. package/dist/compose.min.js +8 -0
  171. package/dist/compose.mjs +71 -0
  172. package/dist/curry.es.js +2 -2
  173. package/dist/curry.es.min.js +2 -2
  174. package/dist/curry.js +2 -2
  175. package/dist/curry.min.js +2 -2
  176. package/dist/curry.mjs +2 -2
  177. package/dist/eq.es.js +172 -49
  178. package/dist/eq.es.min.js +3 -3
  179. package/dist/eq.js +172 -49
  180. package/dist/eq.min.js +3 -3
  181. package/dist/eq.mjs +172 -49
  182. package/dist/every.es.js +194 -0
  183. package/dist/every.es.min.js +7 -0
  184. package/dist/every.js +201 -0
  185. package/dist/every.min.js +8 -0
  186. package/dist/every.mjs +194 -0
  187. package/dist/filter.es.js +14 -108
  188. package/dist/filter.es.min.js +3 -3
  189. package/dist/filter.js +14 -108
  190. package/dist/filter.min.js +3 -3
  191. package/dist/filter.mjs +14 -108
  192. package/dist/flatMap.es.js +27 -214
  193. package/dist/flatMap.es.min.js +3 -3
  194. package/dist/flatMap.js +27 -214
  195. package/dist/flatMap.min.js +3 -3
  196. package/dist/flatMap.mjs +27 -214
  197. package/dist/{x/forEach.es.js → forEach.es.js} +52 -70
  198. package/dist/forEach.es.min.js +7 -0
  199. package/dist/{x/forEach.js → forEach.js} +52 -70
  200. package/dist/forEach.min.js +8 -0
  201. package/dist/{x/forEach.mjs → forEach.mjs} +52 -70
  202. package/dist/get.es.js +60 -5
  203. package/dist/get.es.min.js +3 -3
  204. package/dist/get.js +60 -5
  205. package/dist/get.min.js +3 -3
  206. package/dist/get.mjs +60 -5
  207. package/dist/gt.es.js +171 -48
  208. package/dist/gt.es.min.js +3 -3
  209. package/dist/gt.js +171 -48
  210. package/dist/gt.min.js +3 -3
  211. package/dist/gt.mjs +171 -48
  212. package/dist/gte.es.js +171 -48
  213. package/dist/gte.es.min.js +3 -3
  214. package/dist/gte.js +171 -48
  215. package/dist/gte.min.js +3 -3
  216. package/dist/gte.mjs +171 -48
  217. package/dist/lt.es.js +171 -48
  218. package/dist/lt.es.min.js +3 -3
  219. package/dist/lt.js +171 -48
  220. package/dist/lt.min.js +3 -3
  221. package/dist/lt.mjs +171 -48
  222. package/dist/lte.es.js +171 -48
  223. package/dist/lte.es.min.js +3 -3
  224. package/dist/lte.js +171 -48
  225. package/dist/lte.min.js +3 -3
  226. package/dist/lte.mjs +171 -48
  227. package/dist/map.es.js +12 -101
  228. package/dist/map.es.min.js +3 -3
  229. package/dist/map.js +12 -101
  230. package/dist/map.min.js +3 -3
  231. package/dist/map.mjs +12 -101
  232. package/dist/not.es.js +75 -14
  233. package/dist/not.es.min.js +3 -3
  234. package/dist/not.js +75 -14
  235. package/dist/not.min.js +3 -3
  236. package/dist/not.mjs +75 -14
  237. package/dist/omit.es.js +7 -2
  238. package/dist/omit.es.min.js +3 -3
  239. package/dist/omit.js +7 -2
  240. package/dist/omit.min.js +3 -3
  241. package/dist/omit.mjs +7 -2
  242. package/dist/or.es.js +99 -31
  243. package/dist/or.es.min.js +3 -3
  244. package/dist/or.js +99 -31
  245. package/dist/or.min.js +3 -3
  246. package/dist/or.mjs +99 -31
  247. package/dist/pick.es.js +8 -3
  248. package/dist/pick.es.min.js +3 -3
  249. package/dist/pick.js +8 -3
  250. package/dist/pick.min.js +3 -3
  251. package/dist/pick.mjs +8 -3
  252. package/dist/pipe.es.js +42 -46
  253. package/dist/pipe.es.min.js +3 -3
  254. package/dist/pipe.js +42 -46
  255. package/dist/pipe.min.js +3 -3
  256. package/dist/pipe.mjs +42 -46
  257. package/dist/reduce.es.js +52 -94
  258. package/dist/reduce.es.min.js +3 -3
  259. package/dist/reduce.js +52 -94
  260. package/dist/reduce.min.js +3 -3
  261. package/dist/reduce.mjs +52 -94
  262. package/dist/rubico.es.js +762 -883
  263. package/dist/rubico.es.min.js +3 -3
  264. package/dist/rubico.global.js +2794 -0
  265. package/dist/rubico.global.min.js +8 -0
  266. package/dist/rubico.js +739 -869
  267. package/dist/rubico.min.js +3 -3
  268. package/dist/rubico.mjs +762 -883
  269. package/dist/set.es.js +18 -3
  270. package/dist/set.es.min.js +3 -3
  271. package/dist/set.js +18 -3
  272. package/dist/set.min.js +3 -3
  273. package/dist/set.mjs +18 -3
  274. package/dist/{any.js → some.es.js} +64 -54
  275. package/dist/some.es.min.js +7 -0
  276. package/dist/{any.mjs → some.js} +72 -48
  277. package/dist/some.min.js +8 -0
  278. package/dist/{any.es.js → some.mjs} +65 -48
  279. package/dist/switchCase.es.js +55 -5
  280. package/dist/switchCase.es.min.js +3 -3
  281. package/dist/switchCase.js +55 -5
  282. package/dist/switchCase.min.js +3 -3
  283. package/dist/switchCase.mjs +55 -5
  284. package/dist/tap.es.js +2 -9
  285. package/dist/tap.es.min.js +3 -3
  286. package/dist/tap.js +2 -9
  287. package/dist/tap.min.js +3 -3
  288. package/dist/tap.mjs +2 -9
  289. package/dist/thunkify.es.js +45 -2
  290. package/dist/thunkify.es.min.js +3 -3
  291. package/dist/thunkify.js +45 -2
  292. package/dist/thunkify.min.js +3 -3
  293. package/dist/thunkify.mjs +45 -2
  294. package/dist/transform.es.js +35 -71
  295. package/dist/transform.es.min.js +3 -3
  296. package/dist/transform.js +35 -71
  297. package/dist/transform.min.js +3 -3
  298. package/dist/transform.mjs +35 -71
  299. package/dist/tryCatch.es.js +33 -17
  300. package/dist/tryCatch.es.min.js +3 -3
  301. package/dist/tryCatch.js +33 -17
  302. package/dist/tryCatch.min.js +3 -3
  303. package/dist/tryCatch.mjs +33 -17
  304. package/dist/x/append.es.js +2 -2
  305. package/dist/x/append.es.min.js +2 -2
  306. package/dist/x/append.js +2 -2
  307. package/dist/x/append.min.js +2 -2
  308. package/dist/x/append.mjs +2 -2
  309. package/dist/x/callProp.es.js +2 -2
  310. package/dist/x/callProp.es.min.js +2 -2
  311. package/dist/x/callProp.js +2 -2
  312. package/dist/x/callProp.min.js +2 -2
  313. package/dist/x/callProp.mjs +2 -2
  314. package/dist/x/defaultsDeep.es.js +2 -2
  315. package/dist/x/defaultsDeep.es.min.js +2 -2
  316. package/dist/x/defaultsDeep.js +2 -2
  317. package/dist/x/defaultsDeep.min.js +2 -2
  318. package/dist/x/defaultsDeep.mjs +2 -2
  319. package/dist/x/differenceWith.es.js +7 -7
  320. package/dist/x/differenceWith.es.min.js +3 -3
  321. package/dist/x/differenceWith.js +7 -7
  322. package/dist/x/differenceWith.min.js +2 -2
  323. package/dist/x/differenceWith.mjs +7 -7
  324. package/dist/x/filterOut.es.js +60 -117
  325. package/dist/x/filterOut.es.min.js +3 -3
  326. package/dist/x/filterOut.js +60 -117
  327. package/dist/x/filterOut.min.js +3 -3
  328. package/dist/x/filterOut.mjs +60 -117
  329. package/dist/x/find.es.js +2 -2
  330. package/dist/x/find.es.min.js +2 -2
  331. package/dist/x/find.js +2 -2
  332. package/dist/x/find.min.js +2 -2
  333. package/dist/x/find.mjs +2 -2
  334. package/dist/x/findIndex.es.js +2 -2
  335. package/dist/x/findIndex.es.min.js +2 -2
  336. package/dist/x/findIndex.js +2 -2
  337. package/dist/x/findIndex.min.js +2 -2
  338. package/dist/x/findIndex.mjs +2 -2
  339. package/dist/x/first.es.js +2 -2
  340. package/dist/x/first.es.min.js +2 -2
  341. package/dist/x/first.js +2 -2
  342. package/dist/x/first.min.js +2 -2
  343. package/dist/x/first.mjs +2 -2
  344. package/dist/x/flatten.es.js +20 -207
  345. package/dist/x/flatten.es.min.js +3 -3
  346. package/dist/x/flatten.js +20 -207
  347. package/dist/x/flatten.min.js +3 -3
  348. package/dist/x/flatten.mjs +20 -207
  349. package/dist/x/groupBy.es.js +52 -94
  350. package/dist/x/groupBy.es.min.js +3 -3
  351. package/dist/x/groupBy.js +52 -94
  352. package/dist/x/groupBy.min.js +3 -3
  353. package/dist/x/groupBy.mjs +52 -94
  354. package/dist/x/has.es.js +2 -2
  355. package/dist/x/has.es.min.js +2 -2
  356. package/dist/x/has.js +2 -2
  357. package/dist/x/has.min.js +2 -2
  358. package/dist/x/has.mjs +2 -2
  359. package/dist/x/identity.es.js +2 -2
  360. package/dist/x/identity.es.min.js +2 -2
  361. package/dist/x/identity.js +2 -2
  362. package/dist/x/identity.min.js +2 -2
  363. package/dist/x/identity.mjs +2 -2
  364. package/dist/x/includes.es.js +2 -2
  365. package/dist/x/includes.es.min.js +2 -2
  366. package/dist/x/includes.js +2 -2
  367. package/dist/x/includes.min.js +2 -2
  368. package/dist/x/includes.mjs +2 -2
  369. package/dist/x/isDeepEqual.es.js +2 -2
  370. package/dist/x/isDeepEqual.es.min.js +2 -2
  371. package/dist/x/isDeepEqual.js +2 -2
  372. package/dist/x/isDeepEqual.min.js +2 -2
  373. package/dist/x/isDeepEqual.mjs +2 -2
  374. package/dist/x/isEmpty.es.js +2 -2
  375. package/dist/x/isEmpty.es.min.js +2 -2
  376. package/dist/x/isEmpty.js +2 -2
  377. package/dist/x/isEmpty.min.js +2 -2
  378. package/dist/x/isEmpty.mjs +2 -2
  379. package/dist/x/isEqual.es.js +2 -2
  380. package/dist/x/isEqual.es.min.js +2 -2
  381. package/dist/x/isEqual.js +2 -2
  382. package/dist/x/isEqual.min.js +2 -2
  383. package/dist/x/isEqual.mjs +2 -2
  384. package/dist/x/isFunction.es.js +2 -2
  385. package/dist/x/isFunction.es.min.js +2 -2
  386. package/dist/x/isFunction.js +2 -2
  387. package/dist/x/isFunction.min.js +2 -2
  388. package/dist/x/isFunction.mjs +2 -2
  389. package/dist/x/isIn.es.js +2 -2
  390. package/dist/x/isIn.es.min.js +2 -2
  391. package/dist/x/isIn.js +2 -2
  392. package/dist/x/isIn.min.js +2 -2
  393. package/dist/x/isIn.mjs +2 -2
  394. package/dist/x/isObject.es.js +2 -2
  395. package/dist/x/isObject.es.min.js +2 -2
  396. package/dist/x/isObject.js +2 -2
  397. package/dist/x/isObject.min.js +2 -2
  398. package/dist/x/isObject.mjs +2 -2
  399. package/dist/x/isString.es.js +2 -2
  400. package/dist/x/isString.es.min.js +2 -2
  401. package/dist/x/isString.js +2 -2
  402. package/dist/x/isString.min.js +2 -2
  403. package/dist/x/isString.mjs +2 -2
  404. package/dist/x/keys.es.js +2 -2
  405. package/dist/x/keys.es.min.js +2 -2
  406. package/dist/x/keys.js +2 -2
  407. package/dist/x/keys.min.js +2 -2
  408. package/dist/x/keys.mjs +2 -2
  409. package/dist/x/last.es.js +2 -2
  410. package/dist/x/last.es.min.js +2 -2
  411. package/dist/x/last.js +2 -2
  412. package/dist/x/last.min.js +2 -2
  413. package/dist/x/last.mjs +2 -2
  414. package/dist/x/maxBy.es.js +59 -6
  415. package/dist/x/maxBy.es.min.js +3 -3
  416. package/dist/x/maxBy.js +59 -6
  417. package/dist/x/maxBy.min.js +3 -3
  418. package/dist/x/maxBy.mjs +59 -6
  419. package/dist/x/noop.es.js +2 -2
  420. package/dist/x/noop.es.min.js +2 -2
  421. package/dist/x/noop.js +2 -2
  422. package/dist/x/noop.min.js +2 -2
  423. package/dist/x/noop.mjs +2 -2
  424. package/dist/x/pluck.es.js +32 -103
  425. package/dist/x/pluck.es.min.js +3 -3
  426. package/dist/x/pluck.js +32 -103
  427. package/dist/x/pluck.min.js +3 -3
  428. package/dist/x/pluck.mjs +32 -103
  429. package/dist/x/prepend.es.js +2 -2
  430. package/dist/x/prepend.es.min.js +2 -2
  431. package/dist/x/prepend.js +2 -2
  432. package/dist/x/prepend.min.js +2 -2
  433. package/dist/x/prepend.mjs +2 -2
  434. package/dist/x/size.es.js +2 -2
  435. package/dist/x/size.es.min.js +2 -2
  436. package/dist/x/size.js +2 -2
  437. package/dist/x/size.min.js +2 -2
  438. package/dist/x/size.mjs +2 -2
  439. package/dist/x/trace.es.js +2 -9
  440. package/dist/x/trace.es.min.js +3 -3
  441. package/dist/x/trace.js +2 -9
  442. package/dist/x/trace.min.js +3 -3
  443. package/dist/x/trace.mjs +2 -9
  444. package/dist/x/unionWith.es.js +2 -2
  445. package/dist/x/unionWith.es.min.js +2 -2
  446. package/dist/x/unionWith.js +2 -2
  447. package/dist/x/unionWith.min.js +2 -2
  448. package/dist/x/unionWith.mjs +2 -2
  449. package/dist/x/uniq.es.js +2 -2
  450. package/dist/x/uniq.es.min.js +2 -2
  451. package/dist/x/uniq.js +2 -2
  452. package/dist/x/uniq.min.js +2 -2
  453. package/dist/x/uniq.mjs +2 -2
  454. package/dist/x/unless.es.js +2 -2
  455. package/dist/x/unless.es.min.js +2 -2
  456. package/dist/x/unless.js +2 -2
  457. package/dist/x/unless.min.js +2 -2
  458. package/dist/x/unless.mjs +2 -2
  459. package/dist/x/values.es.js +2 -2
  460. package/dist/x/values.es.min.js +2 -2
  461. package/dist/x/values.js +2 -2
  462. package/dist/x/values.min.js +2 -2
  463. package/dist/x/values.mjs +2 -2
  464. package/dist/x/when.es.js +2 -2
  465. package/dist/x/when.es.min.js +2 -2
  466. package/dist/x/when.js +2 -2
  467. package/dist/x/when.min.js +2 -2
  468. package/dist/x/when.mjs +2 -2
  469. package/dist-test.js +31 -2042
  470. package/eq.js +21 -63
  471. package/es.js +739 -869
  472. package/every.js +94 -0
  473. package/filter.js +23 -91
  474. package/flatMap.js +75 -70
  475. package/forEach.js +82 -0
  476. package/get.js +23 -6
  477. package/global.js +6 -4
  478. package/gt.js +15 -58
  479. package/gte.js +14 -57
  480. package/index.js +739 -869
  481. package/lt.js +17 -60
  482. package/lte.js +14 -57
  483. package/map.js +9 -94
  484. package/memory-usage/reduce.js +2 -2
  485. package/not.js +27 -45
  486. package/omit.js +4 -0
  487. package/or.js +50 -33
  488. package/package.json +7 -7
  489. package/pick.js +5 -1
  490. package/pipe.js +13 -50
  491. package/reduce.js +42 -51
  492. package/rubico.js +22 -11
  493. package/set.js +43 -10
  494. package/some.js +105 -0
  495. package/switchCase.js +13 -3
  496. package/tap.js +0 -24
  497. package/test.js +847 -1096
  498. package/thunkify.js +9 -0
  499. package/tmp.js +1 -0
  500. package/transform.js +31 -16
  501. package/tryCatch.js +19 -15
  502. package/x/differenceWith.js +3 -3
  503. package/x/filterOut.test.js +6 -6
  504. package/x/flatten.js +1 -1
  505. package/x/flatten.test.js +0 -8
  506. package/x/index.js +0 -2
  507. package/x/pluck.js +18 -27
  508. package/x/pluck.test.js +3 -7
  509. package/x/timeInLoop.js +16 -25
  510. package/x/timeInLoop.test.js +8 -4
  511. package/any.js +0 -82
  512. package/dist/__.min.mjs +0 -7
  513. package/dist/all.min.mjs +0 -7
  514. package/dist/always.min.mjs +0 -7
  515. package/dist/and.min.mjs +0 -7
  516. package/dist/any.es.min.js +0 -7
  517. package/dist/any.min.js +0 -8
  518. package/dist/any.min.mjs +0 -7
  519. package/dist/assign.min.mjs +0 -7
  520. package/dist/curry.min.mjs +0 -7
  521. package/dist/eq.min.mjs +0 -7
  522. package/dist/filter.min.mjs +0 -7
  523. package/dist/flatMap.min.mjs +0 -7
  524. package/dist/fork.es.js +0 -159
  525. package/dist/fork.es.min.js +0 -7
  526. package/dist/fork.js +0 -166
  527. package/dist/fork.min.js +0 -8
  528. package/dist/fork.min.mjs +0 -7
  529. package/dist/fork.mjs +0 -159
  530. package/dist/get.min.mjs +0 -7
  531. package/dist/gt.min.mjs +0 -7
  532. package/dist/gte.min.mjs +0 -7
  533. package/dist/lt.min.mjs +0 -7
  534. package/dist/lte.min.mjs +0 -7
  535. package/dist/map.min.mjs +0 -7
  536. package/dist/not.min.mjs +0 -7
  537. package/dist/omit.min.mjs +0 -7
  538. package/dist/or.min.mjs +0 -7
  539. package/dist/pick.min.mjs +0 -7
  540. package/dist/pipe.min.mjs +0 -7
  541. package/dist/reduce.min.mjs +0 -7
  542. package/dist/rubico.min.mjs +0 -7
  543. package/dist/set.min.mjs +0 -7
  544. package/dist/switchCase.min.mjs +0 -7
  545. package/dist/tap.min.mjs +0 -7
  546. package/dist/thunkify.min.mjs +0 -7
  547. package/dist/transform.min.mjs +0 -7
  548. package/dist/tryCatch.min.mjs +0 -7
  549. package/dist/x/append.min.mjs +0 -7
  550. package/dist/x/callProp.min.mjs +0 -7
  551. package/dist/x/defaultsDeep.min.mjs +0 -7
  552. package/dist/x/differenceWith.min.mjs +0 -7
  553. package/dist/x/filterOut.min.mjs +0 -7
  554. package/dist/x/find.min.mjs +0 -7
  555. package/dist/x/findIndex.min.mjs +0 -7
  556. package/dist/x/first.min.mjs +0 -7
  557. package/dist/x/flatten.min.mjs +0 -7
  558. package/dist/x/forEach.es.min.js +0 -7
  559. package/dist/x/forEach.min.js +0 -8
  560. package/dist/x/forEach.min.mjs +0 -7
  561. package/dist/x/groupBy.min.mjs +0 -7
  562. package/dist/x/has.min.mjs +0 -7
  563. package/dist/x/identity.min.mjs +0 -7
  564. package/dist/x/includes.min.mjs +0 -7
  565. package/dist/x/isDeepEqual.min.mjs +0 -7
  566. package/dist/x/isEmpty.min.mjs +0 -7
  567. package/dist/x/isEqual.min.mjs +0 -7
  568. package/dist/x/isFunction.min.mjs +0 -7
  569. package/dist/x/isIn.min.mjs +0 -7
  570. package/dist/x/isObject.min.mjs +0 -7
  571. package/dist/x/isString.min.mjs +0 -7
  572. package/dist/x/keys.min.mjs +0 -7
  573. package/dist/x/last.min.mjs +0 -7
  574. package/dist/x/maxBy.min.mjs +0 -7
  575. package/dist/x/noop.min.mjs +0 -7
  576. package/dist/x/pluck.min.mjs +0 -7
  577. package/dist/x/prepend.min.mjs +0 -7
  578. package/dist/x/size.min.mjs +0 -7
  579. package/dist/x/trace.min.mjs +0 -7
  580. package/dist/x/unionWith.min.mjs +0 -7
  581. package/dist/x/uniq.min.mjs +0 -7
  582. package/dist/x/unless.min.mjs +0 -7
  583. package/dist/x/values.min.mjs +0 -7
  584. package/dist/x/when.min.mjs +0 -7
  585. package/distributor.js +0 -495
  586. package/fork.js +0 -101
  587. package/x/forEach.js +0 -93
  588. package/x/forEach.test.js +0 -218
  589. /package/{benchmarks → archive/benchmarks-v1.9.7}/any.js +0 -0
  590. /package/{x/forEach.benchmark.js → archive/benchmarks-v1.9.7/forEach.js} +0 -0
  591. /package/{benchmarks → archive/benchmarks-v1.9.7}/fork.js +0 -0
  592. /package/{benchmarks → archive/benchmarks-v1.9.7}/integration.js +0 -0
  593. /package/{benchmarks → archive/benchmarks-v1.9.7}/misc.js +0 -0
@@ -0,0 +1,2794 @@
1
+ /**
2
+ * rubico v2.0.1
3
+ * https://github.com/a-synchronous/rubico
4
+ * (c) 2019-2023 Richard Tong
5
+ * rubico may be freely distributed under the MIT license.
6
+ */
7
+
8
+ (function (root, rubico) {
9
+ for (const functionName in rubico) {
10
+ root[functionName] = rubico[functionName]
11
+ }
12
+ }(typeof globalThis == 'object' ? globalThis : this, (function () { 'use strict'
13
+
14
+ const isPromise = value => value != null && typeof value.then == 'function'
15
+
16
+ const areAnyValuesPromises = function (values) {
17
+ const length = values.length
18
+ let index = -1
19
+ while (++index < length) {
20
+ const value = values[index]
21
+ if (isPromise(value)) {
22
+ return true
23
+ }
24
+ }
25
+ return false
26
+ }
27
+
28
+ const promiseAll = Promise.all.bind(Promise)
29
+
30
+ const funcConcat = (
31
+ funcA, funcB,
32
+ ) => function pipedFunction(...args) {
33
+ const intermediate = funcA(...args)
34
+ return isPromise(intermediate)
35
+ ? intermediate.then(funcB)
36
+ : funcB(intermediate)
37
+ }
38
+
39
+ const funcApply = (func, args) => func(...args)
40
+
41
+ const __ = Symbol.for('placeholder')
42
+
43
+ // argument resolver for curry2
44
+ const curry2ResolveArg0 = (
45
+ baseFunc, arg1,
46
+ ) => function arg0Resolver(arg0) {
47
+ return baseFunc(arg0, arg1)
48
+ }
49
+
50
+ // argument resolver for curry2
51
+ const curry2ResolveArg1 = (
52
+ baseFunc, arg0,
53
+ ) => function arg1Resolver(arg1) {
54
+ return baseFunc(arg0, arg1)
55
+ }
56
+
57
+ const curry2 = function (baseFunc, arg0, arg1) {
58
+ return arg0 == __
59
+ ? curry2ResolveArg0(baseFunc, arg1)
60
+ : curry2ResolveArg1(baseFunc, arg0)
61
+ }
62
+
63
+ const pipe = function (...args) {
64
+ const funcs = args.pop()
65
+ const pipeline = funcs.reduce(funcConcat)
66
+
67
+ if (args.length == 0) {
68
+ return pipeline
69
+ }
70
+
71
+ if (areAnyValuesPromises(args)) {
72
+ return promiseAll(args).then(curry2(funcApply, pipeline, __))
73
+ }
74
+
75
+ return pipeline(...args)
76
+ }
77
+
78
+ const compose = function (...args) {
79
+ const funcs = args.pop()
80
+ const composition = funcs.reduceRight(funcConcat)
81
+
82
+ if (args.length == 0) {
83
+ return composition
84
+ }
85
+
86
+ if (areAnyValuesPromises(args)) {
87
+ return promiseAll(args).then(curry2(funcApply, composition, __))
88
+ }
89
+
90
+ return composition(...args)
91
+ }
92
+
93
+ const always = value => function getter() { return value }
94
+
95
+ const thunkifyArgs = (func, args) => function thunk() {
96
+ return func(...args)
97
+ }
98
+
99
+ const thunkConditional = (
100
+ conditionalExpression, thunkOnTruthy, thunkOnFalsy,
101
+ ) => conditionalExpression ? thunkOnTruthy() : thunkOnFalsy()
102
+
103
+ // argument resolver for curry3
104
+ const curry3ResolveArg0 = (
105
+ baseFunc, arg1, arg2,
106
+ ) => function arg0Resolver(arg0) {
107
+ return baseFunc(arg0, arg1, arg2)
108
+ }
109
+
110
+ // argument resolver for curry3
111
+ const curry3ResolveArg1 = (
112
+ baseFunc, arg0, arg2,
113
+ ) => function arg1Resolver(arg1) {
114
+ return baseFunc(arg0, arg1, arg2)
115
+ }
116
+
117
+ // argument resolver for curry3
118
+ const curry3ResolveArg2 = (
119
+ baseFunc, arg0, arg1,
120
+ ) => function arg2Resolver(arg2) {
121
+ return baseFunc(arg0, arg1, arg2)
122
+ }
123
+
124
+ const curry3 = function (baseFunc, arg0, arg1, arg2) {
125
+ if (arg0 == __) {
126
+ return curry3ResolveArg0(baseFunc, arg1, arg2)
127
+ }
128
+ if (arg1 == __) {
129
+ return curry3ResolveArg1(baseFunc, arg0, arg2)
130
+ }
131
+ return curry3ResolveArg2(baseFunc, arg0, arg1)
132
+ }
133
+
134
+ const tap = func => function tapping(...args) {
135
+ const result = args[0],
136
+ call = func(...args)
137
+ return isPromise(call) ? call.then(always(result)) : result
138
+ }
139
+
140
+ tap.if = (predicate, func) => function tappingIf(...args) {
141
+ const predication = predicate(...args)
142
+ if (isPromise(predication)) {
143
+ return predication.then(curry3(
144
+ thunkConditional, __, thunkifyArgs(tap(func), args), always(args[0])))
145
+ }
146
+ if (predication) {
147
+ const execution = func(...args)
148
+ if (isPromise(execution)) {
149
+ return execution.then(always(args[0]))
150
+ }
151
+ }
152
+ return args[0]
153
+ }
154
+
155
+ const isArray = Array.isArray
156
+
157
+ // argument resolver for curryArgs2
158
+ const curryArgs2ResolveArgs0 = (
159
+ baseFunc, arg1, arg2,
160
+ ) => function args0Resolver(...args) {
161
+ return baseFunc(args, arg1)
162
+ }
163
+
164
+ // argument resolver for curryArgs2
165
+ const curryArgs2ResolveArgs1 = (
166
+ baseFunc, arg0, arg2,
167
+ ) => function arg1Resolver(...args) {
168
+ return baseFunc(arg0, args)
169
+ }
170
+
171
+ const curryArgs2 = function (baseFunc, arg0, arg1) {
172
+ if (arg0 == __) {
173
+ return curryArgs2ResolveArgs0(baseFunc, arg1)
174
+ }
175
+ return curryArgs2ResolveArgs1(baseFunc, arg0)
176
+ }
177
+
178
+ const functionArrayAll = function (funcs, args) {
179
+ const funcsLength = funcs.length,
180
+ result = Array(funcsLength)
181
+ let funcsIndex = -1, isAsync = false
182
+ while (++funcsIndex < funcsLength) {
183
+ const resultItem = funcs[funcsIndex](...args)
184
+ if (isPromise(resultItem)) {
185
+ isAsync = true
186
+ }
187
+ result[funcsIndex] = resultItem
188
+ }
189
+ return isAsync ? promiseAll(result) : result
190
+ }
191
+
192
+ // argument resolver for curry4
193
+ const curry4ResolveArg0 = (
194
+ baseFunc, arg1, arg2, arg3,
195
+ ) => function arg0Resolver(arg0) {
196
+ return baseFunc(arg0, arg1, arg2, arg3)
197
+ }
198
+
199
+ // argument resolver for curry4
200
+ const curry4ResolveArg1 = (
201
+ baseFunc, arg0, arg2, arg3,
202
+ ) => function arg1Resolver(arg1) {
203
+ return baseFunc(arg0, arg1, arg2, arg3)
204
+ }
205
+
206
+ // argument resolver for curry4
207
+ const curry4ResolveArg2 = (
208
+ baseFunc, arg0, arg1, arg3,
209
+ ) => function arg2Resolver(arg2) {
210
+ return baseFunc(arg0, arg1, arg2, arg3)
211
+ }
212
+
213
+ // argument resolver for curry4
214
+ const curry4ResolveArg3 = (
215
+ baseFunc, arg0, arg1, arg2,
216
+ ) => function arg3Resolver(arg3) {
217
+ return baseFunc(arg0, arg1, arg2, arg3)
218
+ }
219
+
220
+ const curry4 = function (baseFunc, arg0, arg1, arg2, arg3) {
221
+ if (arg0 == __) {
222
+ return curry4ResolveArg0(baseFunc, arg1, arg2, arg3)
223
+ }
224
+ if (arg1 == __) {
225
+ return curry4ResolveArg1(baseFunc, arg0, arg2, arg3)
226
+ }
227
+ if (arg2 == __) {
228
+ return curry4ResolveArg2(baseFunc, arg0, arg1, arg3)
229
+ }
230
+ return curry4ResolveArg3(baseFunc, arg0, arg1, arg2)
231
+ }
232
+
233
+ const objectSet = function (object, property, value) {
234
+ object[property] = value
235
+ return object
236
+ }
237
+
238
+ const asyncFunctionArrayAllSeries = async function (funcs, args, result, funcsIndex) {
239
+ const funcsLength = funcs.length
240
+ while (++funcsIndex < funcsLength) {
241
+ const resultItem = funcs[funcsIndex](...args)
242
+ result[funcsIndex] = isPromise(resultItem) ? await resultItem : resultItem
243
+ }
244
+ return result
245
+ }
246
+
247
+ const functionArrayAllSeries = function (funcs, args) {
248
+ const funcsLength = funcs.length, result = []
249
+ let funcsIndex = -1
250
+ while (++funcsIndex < funcsLength) {
251
+ const resultItem = funcs[funcsIndex](...args)
252
+ if (isPromise(resultItem)) {
253
+ return resultItem.then(funcConcat(
254
+ curry3(objectSet, result, funcsIndex, __),
255
+ curry4(asyncFunctionArrayAllSeries, funcs, args, __, funcsIndex)))
256
+ }
257
+ result[funcsIndex] = resultItem
258
+ }
259
+ return result
260
+ }
261
+
262
+ const functionObjectAll = function (funcs, args) {
263
+ const result = {}, promises = []
264
+ for (const key in funcs) {
265
+ const resultItem = funcs[key](...args)
266
+ if (isPromise(resultItem)) {
267
+ promises.push(resultItem.then(curry3(objectSet, result, key, __)))
268
+ } else {
269
+ result[key] = resultItem
270
+ }
271
+ }
272
+ return promises.length == 0 ? result : promiseAll(promises).then(always(result))
273
+ }
274
+
275
+ const all = function (...args) {
276
+ const funcs = args.pop()
277
+ if (args.length == 0) {
278
+ return isArray(funcs)
279
+ ? curryArgs2(functionArrayAll, funcs, __)
280
+ : curryArgs2(functionObjectAll, funcs, __)
281
+ }
282
+
283
+ if (areAnyValuesPromises(args)) {
284
+ return isArray(funcs)
285
+ ? promiseAll(args).then(curry2(functionArrayAll, funcs, __))
286
+ : promiseAll(args).then(curry2(functionObjectAll, funcs, __))
287
+ }
288
+
289
+ return isArray(funcs)
290
+ ? functionArrayAll(funcs, args)
291
+ : functionObjectAll(funcs, args)
292
+ }
293
+
294
+ all.series = function allSeries(...args) {
295
+ const funcs = args.pop()
296
+ if (args.length == 0) {
297
+ return curryArgs2(functionArrayAllSeries, funcs, __)
298
+ }
299
+ if (areAnyValuesPromises(args)) {
300
+ return promiseAll(args).then(curry2(functionArrayAllSeries, funcs, __))
301
+ }
302
+ return functionArrayAllSeries(funcs, args)
303
+ }
304
+
305
+ const objectAssign = Object.assign
306
+
307
+ // _assign(object Object, funcs Object<function>) -> Promise|Object
308
+ const _assign = function (object, funcs) {
309
+ const result = functionObjectAll(funcs, [object])
310
+ return isPromise(result)
311
+ ? result.then(curry3(objectAssign, {}, object, __))
312
+ : ({ ...object, ...result })
313
+ }
314
+
315
+ const assign = function (arg0, arg1) {
316
+ if (arg1 == null) {
317
+ return curry2(_assign, __, arg0)
318
+ }
319
+ return isPromise(arg0)
320
+ ? arg0.then(curry2(_assign, __, arg1))
321
+ : _assign(arg0, arg1)
322
+ }
323
+
324
+ const catcherApply = function (catcher, err, args) {
325
+ return catcher(err, ...args)
326
+ }
327
+
328
+ // _tryCatch(tryer function, catcher function, args Array) -> Promise
329
+ const _tryCatch = function (tryer, catcher, args) {
330
+ try {
331
+ const result = tryer(...args)
332
+ return isPromise(result)
333
+ ? result.catch(curry3(catcherApply, catcher, __, args))
334
+ : result
335
+ } catch (error) {
336
+ return catcher(error, ...args)
337
+ }
338
+ }
339
+
340
+ const tryCatch = function (...args) {
341
+ if (args.length > 2) {
342
+ const catcher = args.pop(),
343
+ tryer = args.pop()
344
+ if (areAnyValuesPromises(args)) {
345
+ return promiseAll(args)
346
+ .then(curry3(_tryCatch, tryer, catcher, __))
347
+ }
348
+ return _tryCatch(tryer, catcher, args)
349
+ }
350
+
351
+ const tryer = args[0],
352
+ catcher = args[1]
353
+ return function tryCatcher(...args) {
354
+ return _tryCatch(tryer, catcher, args)
355
+ }
356
+ }
357
+
358
+ const thunkify3 = (func, arg0, arg1, arg2) => function thunk() {
359
+ return func(arg0, arg1, arg2)
360
+ }
361
+
362
+ const arrayConditional = function (array, args, funcsIndex) {
363
+ const lastIndex = array.length - 1
364
+
365
+ while ((funcsIndex += 2) < lastIndex) {
366
+ const predicate = array[funcsIndex],
367
+ resolverOrValue = array[funcsIndex + 1]
368
+
369
+ const predication = typeof predicate == 'function'
370
+ ? predicate(...args)
371
+ : predicate
372
+
373
+ if (isPromise(predication)) {
374
+ return predication.then(curry3(
375
+ thunkConditional,
376
+ __,
377
+ typeof resolverOrValue == 'function'
378
+ ? thunkifyArgs(resolverOrValue, args)
379
+ : always(resolverOrValue),
380
+ thunkify3(arrayConditional, array, args, funcsIndex),
381
+ ))
382
+ }
383
+
384
+ if (predication) {
385
+ return typeof resolverOrValue == 'function'
386
+ ? resolverOrValue(...args)
387
+ : resolverOrValue
388
+ }
389
+ }
390
+
391
+ // even number of array
392
+ if (funcsIndex == array.length) {
393
+ return undefined
394
+ }
395
+
396
+ const defaultResolverOrValue = array[lastIndex]
397
+ return typeof defaultResolverOrValue == 'function'
398
+ ? defaultResolverOrValue(...args)
399
+ : defaultResolverOrValue
400
+ }
401
+
402
+ const areAllValuesNonfunctions = function (values) {
403
+ const length = values.length
404
+ let index = -1
405
+ while (++index < length) {
406
+ if (typeof values[index] == 'function') {
407
+ return false
408
+ }
409
+ }
410
+ return true
411
+ }
412
+
413
+ const thunkify2 = (func, arg0, arg1) => function thunk() {
414
+ return func(arg0, arg1)
415
+ }
416
+
417
+ const nonfunctionsConditional = function (array, index) {
418
+ const length = array.length,
419
+ lastIndex = length - 1
420
+ while ((index += 2) < lastIndex) {
421
+ const predication = array[index],
422
+ value = array[index + 1]
423
+ if (isPromise(predication)) {
424
+ return predication.then(curry3(
425
+ thunkConditional,
426
+ __,
427
+ always(value),
428
+ thunkify2(nonfunctionsConditional, array, index),
429
+ ))
430
+ }
431
+ if (predication) {
432
+ return value
433
+ }
434
+ }
435
+ // even number of array values
436
+ if (index == length) {
437
+ return undefined
438
+ }
439
+ return array[index]
440
+ }
441
+
442
+ // argument resolver for curryArgs3
443
+ const curryArgs3ResolveArgs0 = (
444
+ baseFunc, arg1, arg2,
445
+ ) => function args0Resolver(...args) {
446
+ return baseFunc(args, arg1, arg2)
447
+ }
448
+
449
+ // argument resolver for curryArgs3
450
+ const curryArgs3ResolveArgs1 = (
451
+ baseFunc, arg0, arg2,
452
+ ) => function arg1Resolver(...args) {
453
+ return baseFunc(arg0, args, arg2)
454
+ }
455
+
456
+ // argument resolver for curryArgs3
457
+ const curryArgs3ResolveArgs2 = (
458
+ baseFunc, arg0, arg1,
459
+ ) => function arg2Resolver(...args) {
460
+ return baseFunc(arg0, arg1, args)
461
+ }
462
+
463
+ const curryArgs3 = function (baseFunc, arg0, arg1, arg2) {
464
+ if (arg0 == __) {
465
+ return curryArgs3ResolveArgs0(baseFunc, arg1, arg2)
466
+ }
467
+ if (arg1 == __) {
468
+ return curryArgs3ResolveArgs1(baseFunc, arg0, arg2)
469
+ }
470
+ return curryArgs3ResolveArgs2(baseFunc, arg0, arg1)
471
+ }
472
+
473
+ const switchCase = (...args) => {
474
+ const values = args.pop()
475
+ if (areAllValuesNonfunctions(values)) {
476
+ return nonfunctionsConditional(values, -2)
477
+ }
478
+ if (args.length == 0) {
479
+ return curryArgs3(arrayConditional, values, __, -2)
480
+ }
481
+ if (areAnyValuesPromises(args)) {
482
+ return promiseAll(args).then(curry3(arrayConditional, values, __, -2))
483
+ }
484
+ return arrayConditional(values, args, -2)
485
+ }
486
+
487
+ const symbolIterator = Symbol.iterator
488
+
489
+ const MappingIterator = (iterator, mapper) => ({
490
+ toString() {
491
+ return '[object MappingIterator]'
492
+ },
493
+ [symbolIterator]() {
494
+ return this
495
+ },
496
+ next() {
497
+ const iteration = iterator.next()
498
+ return iteration.done ? iteration
499
+ : { value: mapper(iteration.value), done: false }
500
+ },
501
+ })
502
+
503
+ const NextIteration = value => ({ value, done: false })
504
+
505
+ const symbolAsyncIterator = Symbol.asyncIterator
506
+
507
+ const MappingAsyncIterator = (asyncIterator, mapper) => ({
508
+ [symbolAsyncIterator]() {
509
+ return this
510
+ },
511
+ async next() {
512
+ const iteration = await asyncIterator.next()
513
+ if (iteration.done) {
514
+ return iteration
515
+ }
516
+ const mapped = mapper(iteration.value)
517
+ return isPromise(mapped)
518
+ ? mapped.then(NextIteration)
519
+ : { value: mapped, done: false }
520
+ }
521
+ })
522
+
523
+ const isObject = value => {
524
+ if (value == null) {
525
+ return false
526
+ }
527
+
528
+ const typeofValue = typeof value
529
+ return (typeofValue == 'object') || (typeofValue == 'function')
530
+ }
531
+
532
+ const arrayMap = function (array, mapper) {
533
+ const arrayLength = array.length,
534
+ result = Array(arrayLength)
535
+ let index = -1,
536
+ isAsync = false
537
+
538
+ while (++index < arrayLength) {
539
+ const resultItem = mapper(array[index], index, array)
540
+ if (isPromise(resultItem)) {
541
+ isAsync = true
542
+ }
543
+ result[index] = resultItem
544
+ }
545
+ return isAsync ? promiseAll(result) : result
546
+ }
547
+
548
+ const callPropUnary = (value, property, arg0) => value[property](arg0)
549
+
550
+ const stringMap = function (string, mapper) {
551
+ const result = arrayMap(string, mapper)
552
+ return isPromise(result)
553
+ ? result.then(curry3(callPropUnary, __, 'join', ''))
554
+ : result.join('')
555
+ }
556
+
557
+ const setMap = function (set, mapper) {
558
+ const result = new Set(),
559
+ promises = []
560
+ for (const item of set) {
561
+ const resultItem = mapper(item, item, set)
562
+ if (isPromise(resultItem)) {
563
+ promises.push(resultItem.then(curry3(callPropUnary, result, 'add', __)))
564
+ } else {
565
+ result.add(resultItem)
566
+ }
567
+ }
568
+ return promises.length == 0
569
+ ? result
570
+ : promiseAll(promises).then(always(result))
571
+ }
572
+
573
+ const callPropBinary = (value, property, arg0, arg1) => value[property](arg0, arg1)
574
+
575
+ const mapMap = function (value, mapper) {
576
+ const result = new Map(),
577
+ promises = []
578
+ for (const [key, item] of value) {
579
+ const resultItem = mapper(item, key, value)
580
+ if (isPromise(resultItem)) {
581
+ promises.push(resultItem.then(
582
+ curry4(callPropBinary, result, 'set', key, __)))
583
+ } else {
584
+ result.set(key, resultItem)
585
+ }
586
+ }
587
+ return promises.length == 0
588
+ ? result
589
+ : promiseAll(promises).then(always(result))
590
+ }
591
+
592
+ const promiseObjectAllExecutor = object => function executor(resolve) {
593
+ const result = {}
594
+ let numPromises = 0
595
+ for (const key in object) {
596
+ const value = object[key]
597
+ if (isPromise(value)) {
598
+ numPromises += 1
599
+ value.then((key => function (res) {
600
+ result[key] = res
601
+ numPromises -= 1
602
+ if (numPromises == 0) {
603
+ resolve(result)
604
+ }
605
+ })(key))
606
+ } else {
607
+ result[key] = value
608
+ }
609
+ }
610
+ if (numPromises == 0) {
611
+ resolve(result)
612
+ }
613
+ }
614
+
615
+ const promiseObjectAll = object => new Promise(promiseObjectAllExecutor(object))
616
+
617
+ const objectMap = function (object, mapper) {
618
+ const result = {}
619
+ let isAsync = false
620
+ for (const key in object) {
621
+ const resultItem = mapper(object[key], key, object)
622
+ if (isPromise(resultItem)) {
623
+ isAsync = true
624
+ }
625
+ result[key] = resultItem
626
+ }
627
+ return isAsync ? promiseObjectAll(result) : result
628
+ }
629
+
630
+ const arrayMapSeriesAsync = async function (
631
+ array, mapper, result, index,
632
+ ) {
633
+ const arrayLength = array.length
634
+ while (++index < arrayLength) {
635
+ const resultItem = mapper(array[index])
636
+ result[index] = isPromise(resultItem) ? await resultItem : resultItem
637
+ }
638
+ return result
639
+ }
640
+
641
+ const arrayMapSeries = function (array, mapper) {
642
+ const arrayLength = array.length,
643
+ result = Array(arrayLength)
644
+ let index = -1
645
+
646
+ while (++index < arrayLength) {
647
+ const resultItem = mapper(array[index])
648
+ if (isPromise(resultItem)) {
649
+ return resultItem.then(funcConcat(
650
+ curry3(objectSet, result, index, __),
651
+ curry4(arrayMapSeriesAsync, array, mapper, __, index)))
652
+ }
653
+ result[index] = resultItem
654
+ }
655
+ return result
656
+ }
657
+
658
+ const tapSync = func => function tapping(...args) {
659
+ func(...args)
660
+ return args[0]
661
+ }
662
+
663
+ const promiseRace = Promise.race.bind(Promise)
664
+
665
+ const arrayMapPoolAsync = async function (
666
+ array, mapper, concurrencyLimit, result, index, promises,
667
+ ) {
668
+ const arrayLength = array.length
669
+ while (++index < arrayLength) {
670
+ if (promises.size >= concurrencyLimit) {
671
+ await promiseRace(promises)
672
+ }
673
+
674
+ const resultItem = mapper(array[index])
675
+ if (isPromise(resultItem)) {
676
+ const selfDeletingPromise = resultItem.then(
677
+ tapSync(() => promises.delete(selfDeletingPromise)))
678
+ promises.add(selfDeletingPromise)
679
+ result[index] = selfDeletingPromise
680
+ } else {
681
+ result[index] = resultItem
682
+ }
683
+ }
684
+ return promiseAll(result)
685
+ }
686
+
687
+ const arrayMapPool = function (array, mapper, concurrentLimit) {
688
+ const arrayLength = array.length,
689
+ result = Array(arrayLength)
690
+ let index = -1
691
+ while (++index < arrayLength) {
692
+
693
+ const resultItem = mapper(array[index])
694
+ if (isPromise(resultItem)) {
695
+ const promises = new Set(),
696
+ selfDeletingPromise = resultItem.then(
697
+ tapSync(() => promises.delete(selfDeletingPromise)))
698
+ promises.add(selfDeletingPromise)
699
+ result[index] = selfDeletingPromise
700
+ return arrayMapPoolAsync(
701
+ array, mapper, concurrentLimit, result, index, promises)
702
+ }
703
+ result[index] = resultItem
704
+ }
705
+ return result
706
+ }
707
+
708
+ const _curryArity = (arity, func, args) => function curried(...curriedArgs) {
709
+ const argsLength = args.length,
710
+ curriedArgsLength = curriedArgs.length,
711
+ nextArgs = []
712
+ let argsIndex = -1,
713
+ curriedArgsIndex = -1,
714
+ numCurriedPlaceholders = 0
715
+
716
+ while (++argsIndex < argsLength) {
717
+ const arg = args[argsIndex]
718
+ if (arg == __ && (curriedArgsIndex += 1) < curriedArgsLength) {
719
+ const curriedArg = curriedArgs[curriedArgsIndex]
720
+ if (curriedArg == __) {
721
+ numCurriedPlaceholders += 1
722
+ }
723
+ nextArgs.push(curriedArg)
724
+ } else {
725
+ nextArgs.push(arg)
726
+ }
727
+ if (nextArgs.length == arity) {
728
+ return numCurriedPlaceholders == 0
729
+ ? func(...nextArgs)
730
+ : curryArity(arity, func, nextArgs)
731
+ }
732
+ }
733
+
734
+ while (++curriedArgsIndex < curriedArgsLength) {
735
+ const curriedArg = curriedArgs[curriedArgsIndex]
736
+ if (curriedArg == __) {
737
+ numCurriedPlaceholders += 1
738
+ }
739
+ nextArgs.push(curriedArg)
740
+ if (nextArgs.length == arity) {
741
+ return numCurriedPlaceholders == 0
742
+ ? func(...nextArgs)
743
+ : curryArity(arity, func, nextArgs)
744
+ }
745
+ }
746
+ return curryArity(arity, func, nextArgs)
747
+ }
748
+
749
+ const curryArity = function (arity, func, args) {
750
+ const argsLength = args.length
751
+ if (argsLength < arity) {
752
+ return _curryArity(arity, func, args)
753
+ }
754
+ let argsIndex = -1
755
+ while (++argsIndex < argsLength) {
756
+ const arg = args[argsIndex]
757
+ if (arg == __) {
758
+ return _curryArity(arity, func, args)
759
+ }
760
+ }
761
+ return func(...args)
762
+ }
763
+
764
+ const spread2 = func => function spreading2([arg0, arg1]) {
765
+ return func(arg0, arg1)
766
+ }
767
+
768
+ const objectMapEntries = function (object, mapper) {
769
+ const result = {},
770
+ promises = []
771
+ for (const key in object) {
772
+ const value = object[key],
773
+ mapping = mapper([key, value])
774
+ if (isPromise(mapping)) {
775
+ promises.push(mapping.then(
776
+ spread2(curryArity(3, objectSet, [result]))))
777
+ } else {
778
+ result[mapping[0]] = mapping[1]
779
+ }
780
+ }
781
+ return promises.length == 0
782
+ ? result
783
+ : promiseAll(promises).then(always(result))
784
+ }
785
+
786
+ const mapSet = function setting(source, key, value) {
787
+ return source.set(key, value)
788
+ }
789
+
790
+ // (mapper function, result Map, promises Array<Promise>) => (key any, value any) => ()
791
+ const mapMapEntriesForEachCallback = (
792
+ mapper, result, promises,
793
+ ) => function callback(value, key) {
794
+ const mapping = mapper([key, value])
795
+ if (isPromise(mapping)) {
796
+ promises.push(mapping.then(spread2(curryArity(3, mapSet, [result]))))
797
+ } else {
798
+ result.set(mapping[0], mapping[1])
799
+ }
800
+ }
801
+
802
+ const mapMapEntries = function (source, mapper) {
803
+ const result = new Map(),
804
+ promises = []
805
+ source.forEach(mapMapEntriesForEachCallback(mapper, result, promises))
806
+ return promises.length == 0
807
+ ? result
808
+ : promiseAll(promises).then(always(result))
809
+ }
810
+
811
+ const _map = function (value, mapper) {
812
+ if (isArray(value)) {
813
+ return arrayMap(value, mapper)
814
+ }
815
+ if (value == null) {
816
+ return value
817
+ }
818
+
819
+ if (typeof value.then == 'function') {
820
+ return value.then(mapper)
821
+ }
822
+ if (typeof value.map == 'function') {
823
+ return value.map(mapper)
824
+ }
825
+ if (typeof value == 'string' || value.constructor == String) {
826
+ return stringMap(value, mapper)
827
+ }
828
+ if (value.constructor == Set) {
829
+ return setMap(value, mapper)
830
+ }
831
+ if (value.constructor == Map) {
832
+ return mapMap(value, mapper)
833
+ }
834
+ if (typeof value[symbolIterator] == 'function') {
835
+ return MappingIterator(value[symbolIterator](), mapper)
836
+ }
837
+ if (typeof value[symbolAsyncIterator] == 'function') {
838
+ return MappingAsyncIterator(value[symbolAsyncIterator](), mapper)
839
+ }
840
+ if (value.constructor == Object) {
841
+ return objectMap(value, mapper)
842
+ }
843
+ return mapper(value)
844
+ }
845
+
846
+ const map = (...args) => {
847
+ const mapper = args.pop()
848
+ if (args.length == 0) {
849
+ return curry2(_map, __, mapper)
850
+ }
851
+
852
+ const collection = args[0]
853
+ if (isPromise(collection)) {
854
+ return collection.then(curry2(_map, __, mapper))
855
+ }
856
+ return _map(collection, mapper)
857
+ }
858
+
859
+ map.entries = function mapEntries(mapper) {
860
+ return function mappingEntries(value) {
861
+ if (value == null) {
862
+ throw new TypeError('value is not an Object or Map')
863
+ }
864
+ if (value.constructor == Object) {
865
+ return objectMapEntries(value, mapper)
866
+ }
867
+ if (value.constructor == Map) {
868
+ return mapMapEntries(value, mapper)
869
+ }
870
+ throw new TypeError('value is not an Object or Map')
871
+ }
872
+ }
873
+
874
+ map.series = mapper => function mappingInSeries(value) {
875
+ if (isArray(value)) {
876
+ return arrayMapSeries(value, mapper)
877
+ }
878
+ throw new TypeError(`${value} is not an Array`)
879
+ }
880
+
881
+ map.pool = (concurrencyLimit, mapper) => function concurrentPoolMapping(value) {
882
+ if (isArray(value)) {
883
+ return arrayMapPool(value, mapper, concurrencyLimit)
884
+ }
885
+ throw new TypeError(`${value} is not an Array`)
886
+ }
887
+
888
+ const FilteringIterator = (iterator, predicate) => ({
889
+ [symbolIterator]() {
890
+ return this
891
+ },
892
+ next() {
893
+ let iteration = iterator.next()
894
+ while (!iteration.done) {
895
+ const { value } = iteration
896
+ if (predicate(value)) {
897
+ return { value, done: false }
898
+ }
899
+ iteration = iterator.next()
900
+ }
901
+ return iteration
902
+ },
903
+ })
904
+
905
+ const FilteringAsyncIterator = (asyncIterator, predicate) => ({
906
+ isAsyncIteratorDone: false,
907
+ [symbolAsyncIterator]() {
908
+ return this
909
+ },
910
+ async next() {
911
+ while (!this.isAsyncIteratorDone) {
912
+ const { value, done } = await asyncIterator.next()
913
+ if (done) {
914
+ this.isAsyncIteratorDone = true
915
+ } else {
916
+ const predication = predicate(value)
917
+ if (isPromise(predication) ? await predication : predication) {
918
+ return { value, done: false }
919
+ }
920
+ }
921
+ }
922
+ return { value: undefined, done: true }
923
+ },
924
+ })
925
+
926
+ const arrayExtendMap = function (
927
+ array, values, valuesMapper, valuesIndex,
928
+ ) {
929
+ const valuesLength = values.length
930
+ let arrayIndex = array.length - 1
931
+ while (++valuesIndex < valuesLength) {
932
+ array[++arrayIndex] = valuesMapper(values[valuesIndex], valuesIndex, array)
933
+ }
934
+ return array
935
+ }
936
+
937
+ const arrayFilterByConditions = function (
938
+ array, result, index, conditions,
939
+ ) {
940
+ const arrayLength = array.length
941
+ let conditionsIndex = -1
942
+ while (++index < arrayLength) {
943
+ if (conditions[++conditionsIndex]) {
944
+ result.push(array[index])
945
+ }
946
+ }
947
+ return result
948
+ }
949
+
950
+ const arrayFilter = function (array, predicate) {
951
+ const arrayLength = array.length,
952
+ result = []
953
+ let index = -1,
954
+ resultIndex = -1
955
+ while (++index < arrayLength) {
956
+ const item = array[index],
957
+ shouldIncludeItem = predicate(item, index, array)
958
+ if (isPromise(shouldIncludeItem)) {
959
+ return promiseAll(
960
+ arrayExtendMap([shouldIncludeItem], array, predicate, index)
961
+ ).then(curry4(arrayFilterByConditions, array, result, index - 1, __))
962
+ }
963
+ if (shouldIncludeItem) {
964
+ result[++resultIndex] = item
965
+ }
966
+ }
967
+ return result
968
+ }
969
+
970
+ const stringFilter = function (string, predicate) {
971
+ const filteredCharactersArray = arrayFilter(string, predicate)
972
+ return isPromise(filteredCharactersArray)
973
+ ? filteredCharactersArray.then(curry3(callPropUnary, __, 'join', ''))
974
+ : filteredCharactersArray.join('')
975
+ }
976
+
977
+ const thunkify1 = (func, arg0) => function thunk() {
978
+ return func(arg0)
979
+ }
980
+
981
+ const noop = function () {}
982
+
983
+ const setFilter = function (value, predicate) {
984
+ const result = new Set(),
985
+ resultAdd = result.add.bind(result),
986
+ promises = []
987
+ for (const item of value) {
988
+ const predication = predicate(item, item, value)
989
+ if (isPromise(predication)) {
990
+ promises.push(predication.then(curry3(
991
+ thunkConditional, __, thunkify1(resultAdd, item), noop)))
992
+ } else if (predication) {
993
+ result.add(item)
994
+ }
995
+ }
996
+ return promises.length == 0
997
+ ? result
998
+ : promiseAll(promises).then(always(result))
999
+ }
1000
+
1001
+ const thunkify4 = (func, arg0, arg1, arg2, arg3) => function thunk() {
1002
+ return func(arg0, arg1, arg2, arg3)
1003
+ }
1004
+
1005
+ const mapFilter = function (map, predicate) {
1006
+ const result = new Map(),
1007
+ promises = []
1008
+ for (const [key, item] of map) {
1009
+ const predication = predicate(item, key, map)
1010
+ if (isPromise(predication)) {
1011
+ promises.push(predication.then(curry3(thunkConditional,
1012
+ __,
1013
+ thunkify4(callPropBinary, result, 'set', key, item),
1014
+ noop)))
1015
+ } else if (predication) {
1016
+ result.set(key, item)
1017
+ }
1018
+ }
1019
+ return promises.length == 0 ? result
1020
+ : promiseAll(promises).then(always(result))
1021
+ }
1022
+
1023
+ const objectSetIf = function (
1024
+ object, key, value, condition,
1025
+ ) {
1026
+ if (condition) {
1027
+ object[key] = value
1028
+ }
1029
+ }
1030
+
1031
+ const objectFilter = function (object, predicate) {
1032
+ const result = {},
1033
+ promises = []
1034
+ for (const key in object) {
1035
+ const item = object[key],
1036
+ shouldIncludeItem = predicate(item, key, object)
1037
+ if (isPromise(shouldIncludeItem)) {
1038
+ promises.push(shouldIncludeItem.then(
1039
+ curry4(objectSetIf, result, key, object[key], __)))
1040
+ } else if (shouldIncludeItem) {
1041
+ result[key] = item
1042
+ }
1043
+ }
1044
+ return promises.length == 0
1045
+ ? result
1046
+ : promiseAll(promises).then(always(result))
1047
+ }
1048
+
1049
+ const _filter = function (value, predicate) {
1050
+ if (isArray(value)) {
1051
+ return arrayFilter(value, predicate)
1052
+ }
1053
+ if (value == null) {
1054
+ return value
1055
+ }
1056
+
1057
+ if (typeof value == 'string' || value.constructor == String) {
1058
+ return stringFilter(value, predicate)
1059
+ }
1060
+ if (value.constructor == Set) {
1061
+ return setFilter(value, predicate)
1062
+ }
1063
+ if (value.constructor == Map) {
1064
+ return mapFilter(value, predicate)
1065
+ }
1066
+ if (typeof value.filter == 'function') {
1067
+ return value.filter(predicate)
1068
+ }
1069
+ if (typeof value[symbolIterator] == 'function') {
1070
+ return FilteringIterator(value[symbolIterator](), predicate)
1071
+ }
1072
+ if (typeof value[symbolAsyncIterator] == 'function') {
1073
+ return FilteringAsyncIterator(value[symbolAsyncIterator](), predicate)
1074
+ }
1075
+ if (value.constructor == Object) {
1076
+ return objectFilter(value, predicate)
1077
+ }
1078
+ return value
1079
+ }
1080
+
1081
+ const filter = function (...args) {
1082
+ const predicate = args.pop()
1083
+ if (args.length == 0) {
1084
+ return curry2(_filter, __, predicate)
1085
+ }
1086
+ return _filter(args[0], predicate)
1087
+ }
1088
+
1089
+ const objectValues = Object.values
1090
+
1091
+ const objectProto = Object.prototype
1092
+
1093
+ const nativeObjectToString = objectProto.toString
1094
+
1095
+ const objectToString = value => nativeObjectToString.call(value)
1096
+
1097
+ const generatorFunctionTag = '[object GeneratorFunction]'
1098
+
1099
+ const isGeneratorFunction = value => objectToString(value) == generatorFunctionTag
1100
+
1101
+ const asyncGeneratorFunctionTag = '[object AsyncGeneratorFunction]'
1102
+
1103
+ const isAsyncGeneratorFunction = value => objectToString(value) == asyncGeneratorFunctionTag
1104
+
1105
+ const iteratorReduceAsync = async function (
1106
+ iterator, reducer, result,
1107
+ ) {
1108
+ let iteration = iterator.next()
1109
+ if (iteration.done) {
1110
+ return result
1111
+ }
1112
+
1113
+ while (!iteration.done) {
1114
+ result = reducer(result, iteration.value)
1115
+ if (isPromise(result)) {
1116
+ result = await result
1117
+ }
1118
+ iteration = iterator.next()
1119
+ }
1120
+ return result
1121
+ }
1122
+
1123
+ const iteratorReduce = function (iterator, reducer, result) {
1124
+ let iteration = iterator.next()
1125
+ if (iteration.done) {
1126
+ return result
1127
+ }
1128
+ if (result === undefined) {
1129
+ result = iteration.value
1130
+ iteration = iterator.next()
1131
+ }
1132
+ while (!iteration.done) {
1133
+ result = reducer(result, iteration.value)
1134
+ if (isPromise(result)) {
1135
+ return result.then(curry3(iteratorReduceAsync, iterator, reducer, __))
1136
+ }
1137
+ iteration = iterator.next()
1138
+ }
1139
+ return result
1140
+ }
1141
+
1142
+ const asyncIteratorReduce = async function (asyncIterator, reducer, result) {
1143
+ let iteration = await asyncIterator.next()
1144
+ if (iteration.done) {
1145
+ return result
1146
+ }
1147
+ if (result === undefined) {
1148
+ result = iteration.value
1149
+ iteration = await asyncIterator.next()
1150
+ }
1151
+
1152
+ while (!iteration.done) {
1153
+ result = await reducer(result, iteration.value)
1154
+ iteration = await asyncIterator.next()
1155
+ }
1156
+ return result
1157
+ }
1158
+
1159
+ const arrayReduceAsync = async function (
1160
+ array, reducer, result, index,
1161
+ ) {
1162
+ const length = array.length
1163
+ while (++index < length) {
1164
+ result = reducer(result, array[index], index, array)
1165
+ if (isPromise(result)) {
1166
+ result = await result
1167
+ }
1168
+ }
1169
+ return result
1170
+ }
1171
+
1172
+ const arrayReduce = function (array, reducer, result) {
1173
+ const arrayLength = array.length
1174
+ let index = -1
1175
+ if (result === undefined) {
1176
+ result = array[++index]
1177
+ }
1178
+ while (++index < arrayLength) {
1179
+ result = reducer(result, array[index], index, array)
1180
+ if (isPromise(result)) {
1181
+ return result.then(curry4(arrayReduceAsync, array, reducer, __, index))
1182
+ }
1183
+ }
1184
+ return result
1185
+ }
1186
+
1187
+ // argument resolver for curry5
1188
+ const curry5ResolveArg0 = (
1189
+ baseFunc, arg1, arg2, arg3, arg4,
1190
+ ) => function arg0Resolver(arg0) {
1191
+ return baseFunc(arg0, arg1, arg2, arg3, arg4)
1192
+ }
1193
+
1194
+ // argument resolver for curry5
1195
+ const curry5ResolveArg1 = (
1196
+ baseFunc, arg0, arg2, arg3, arg4,
1197
+ ) => function arg1Resolver(arg1) {
1198
+ return baseFunc(arg0, arg1, arg2, arg3, arg4)
1199
+ }
1200
+
1201
+ // argument resolver for curry5
1202
+ const curry5ResolveArg2 = (
1203
+ baseFunc, arg0, arg1, arg3, arg4,
1204
+ ) => function arg2Resolver(arg2) {
1205
+ return baseFunc(arg0, arg1, arg2, arg3, arg4)
1206
+ }
1207
+
1208
+ // argument resolver for curry5
1209
+ const curry5ResolveArg3 = (
1210
+ baseFunc, arg0, arg1, arg2, arg4,
1211
+ ) => function arg3Resolver(arg3) {
1212
+ return baseFunc(arg0, arg1, arg2, arg3, arg4)
1213
+ }
1214
+
1215
+ // argument resolver for curry5
1216
+ const curry5ResolveArg4 = (
1217
+ baseFunc, arg0, arg1, arg2, arg3,
1218
+ ) => function arg3Resolver(arg4) {
1219
+ return baseFunc(arg0, arg1, arg2, arg3, arg4)
1220
+ }
1221
+
1222
+ const curry5 = function (baseFunc, arg0, arg1, arg2, arg3, arg4) {
1223
+ if (arg0 == __) {
1224
+ return curry5ResolveArg0(baseFunc, arg1, arg2, arg3, arg4)
1225
+ }
1226
+ if (arg1 == __) {
1227
+ return curry5ResolveArg1(baseFunc, arg0, arg2, arg3, arg4)
1228
+ }
1229
+ if (arg2 == __) {
1230
+ return curry5ResolveArg2(baseFunc, arg0, arg1, arg3, arg4)
1231
+ }
1232
+ if (arg3 == __) {
1233
+ return curry5ResolveArg3(baseFunc, arg0, arg1, arg2, arg4)
1234
+ }
1235
+ return curry5ResolveArg4(baseFunc, arg0, arg1, arg2, arg3)
1236
+ }
1237
+
1238
+ const objectKeys = Object.keys
1239
+
1240
+ const objectReduceAsync = async function (object, reducer, result, keys, index) {
1241
+ const keysLength = keys.length
1242
+ while (++index < keysLength) {
1243
+ const key = keys[index]
1244
+ result = reducer(result, object[key], key, object)
1245
+ if (isPromise(result)) {
1246
+ result = await result
1247
+ }
1248
+ }
1249
+ return result
1250
+ }
1251
+
1252
+ const objectReduce = function (object, reducer, result) {
1253
+ const keys = objectKeys(object),
1254
+ keysLength = keys.length
1255
+ let index = -1
1256
+ if (result === undefined) {
1257
+ result = object[keys[++index]]
1258
+ }
1259
+ while (++index < keysLength) {
1260
+ const key = keys[index]
1261
+ result = reducer(result, object[key], key, object)
1262
+ if (isPromise(result)) {
1263
+ return result.then(curry5(objectReduceAsync, object, reducer, __, keys, index))
1264
+ }
1265
+ }
1266
+ return result
1267
+ }
1268
+
1269
+ const mapReduceAsync = async function (
1270
+ map, reducer, result, mapEntriesIter,
1271
+ ) {
1272
+ for (const [key, value] of mapEntriesIter) {
1273
+ result = reducer(result, value, key, map)
1274
+ if (isPromise(result)) {
1275
+ result = await result
1276
+ }
1277
+ }
1278
+ return result
1279
+ }
1280
+
1281
+ const mapReduce = function (map, reducer, result) {
1282
+ const mapEntriesIter = map.entries()
1283
+ if (result === undefined) {
1284
+ const firstIteration = mapEntriesIter.next()
1285
+ if (firstIteration.done) {
1286
+ return result
1287
+ }
1288
+ result = firstIteration.value[1]
1289
+ }
1290
+ for (const [key, value] of mapEntriesIter) {
1291
+ result = reducer(result, value, key, map)
1292
+ if (isPromise(result)) {
1293
+ return result.then(curry4(
1294
+ mapReduceAsync, map, reducer, __, mapEntriesIter))
1295
+ }
1296
+ }
1297
+ return result
1298
+ }
1299
+
1300
+ const reducerConcat = (
1301
+ reducerA, reducerB,
1302
+ ) => function pipedReducer(result, item) {
1303
+ const intermediate = reducerA(result, item)
1304
+ return isPromise(intermediate)
1305
+ ? intermediate.then(curry2(reducerB, __, item))
1306
+ : reducerB(intermediate, item)
1307
+ }
1308
+
1309
+ const genericReduce = function (collection, reducer, result) {
1310
+ if (isArray(collection)) {
1311
+ return arrayReduce(collection, reducer, result)
1312
+ }
1313
+ if (collection == null) {
1314
+ return result === undefined
1315
+ ? curry2(reducer, collection, __)
1316
+ : reducer(result, collection)
1317
+ }
1318
+
1319
+ if (collection.constructor == Map) {
1320
+ return mapReduce(collection, reducer, result)
1321
+ }
1322
+ if (typeof collection[symbolIterator] == 'function') {
1323
+ return iteratorReduce(
1324
+ collection[symbolIterator](), reducer, result)
1325
+ }
1326
+ if (typeof collection[symbolAsyncIterator] == 'function') {
1327
+ return asyncIteratorReduce(
1328
+ collection[symbolAsyncIterator](), reducer, result)
1329
+ }
1330
+ if (typeof collection.reduce == 'function') {
1331
+ return collection.reduce(reducer, result)
1332
+ }
1333
+ if (typeof collection.chain == 'function') {
1334
+ return collection.chain(curry2(reducer, result, __))
1335
+ }
1336
+ if (typeof collection.flatMap == 'function') {
1337
+ return collection.flatMap(curry2(reducer, result, __))
1338
+ }
1339
+ if (collection.constructor == Object) {
1340
+ return objectReduce(collection, reducer, result)
1341
+ }
1342
+ return result === undefined
1343
+ ? curry2(reducer, collection, __)
1344
+ : reducer(result, collection)
1345
+ }
1346
+
1347
+ // _reduce(collection any, reducer function, initialValue function|any) -> Promise
1348
+ const _reduce = function (collection, reducer, initialValue) {
1349
+ if (typeof initialValue == 'function') {
1350
+ const actualInitialValue = initialValue(collection)
1351
+ return isPromise(actualInitialValue)
1352
+ ? actualInitialValue.then(curry3(genericReduce, collection, reducer, __))
1353
+ : genericReduce(collection, reducer, actualInitialValue)
1354
+ }
1355
+ return isPromise(initialValue)
1356
+ ? initialValue.then(curry3(genericReduce, collection, reducer, __))
1357
+ : genericReduce(collection, reducer, initialValue)
1358
+ }
1359
+
1360
+ const reduce = function (...args) {
1361
+ if (typeof args[0] == 'function') {
1362
+ return curry3(_reduce, __, args[0], args[1])
1363
+ }
1364
+ if (isPromise(args[0])) {
1365
+ return args[0].then(curry3(_reduce, __, args[1], args[2]))
1366
+ }
1367
+ return _reduce(args[0], args[1], args[2])
1368
+ }
1369
+
1370
+ const isBinary = ArrayBuffer.isView
1371
+
1372
+ const add = (a, b) => a + b
1373
+
1374
+ const _arrayExtend = function (array, values) {
1375
+ const arrayLength = array.length,
1376
+ valuesLength = values.length
1377
+ let valuesIndex = -1
1378
+ while (++valuesIndex < valuesLength) {
1379
+ array[arrayLength + valuesIndex] = values[valuesIndex]
1380
+ }
1381
+ return array
1382
+ }
1383
+
1384
+ const arrayExtend = function (array, values) {
1385
+ if (isArray(values) || isBinary(values)) {
1386
+ return _arrayExtend(array, values)
1387
+ }
1388
+ array.push(values)
1389
+ return array
1390
+ }
1391
+
1392
+ const globalThisHasBuffer = typeof Buffer == 'function'
1393
+
1394
+ const bufferAlloc = globalThisHasBuffer ? Buffer.alloc : noop
1395
+
1396
+ const _binaryExtend = function (typedArray, array) {
1397
+ const offset = typedArray.length
1398
+ const result = globalThisHasBuffer && typedArray.constructor == Buffer
1399
+ ? bufferAlloc(offset + array.length)
1400
+ : new typedArray.constructor(offset + array.length)
1401
+ result.set(typedArray)
1402
+ result.set(array, offset)
1403
+ return result
1404
+ }
1405
+
1406
+ const binaryExtend = function (typedArray, array) {
1407
+ if (isArray(array) || isBinary(array)) {
1408
+ return _binaryExtend(typedArray, array)
1409
+ }
1410
+ return _binaryExtend(typedArray, [array])
1411
+ }
1412
+
1413
+ const isNodeReadStream = value => value != null && typeof value.pipe == 'function'
1414
+
1415
+ const __streamWrite = stream => function appender(
1416
+ chunk, encoding, callback,
1417
+ ) {
1418
+ stream.write(chunk, encoding, callback)
1419
+ return stream
1420
+ }
1421
+
1422
+ const _streamExtendExecutor = (
1423
+ resultStream, stream,
1424
+ ) => function executor(resolve, reject) {
1425
+ stream.on('data', __streamWrite(resultStream))
1426
+ stream.on('end', thunkify1(resolve, resultStream))
1427
+ stream.on('error', reject)
1428
+ }
1429
+
1430
+ const _streamExtend = (
1431
+ resultStream, stream,
1432
+ ) => new Promise(_streamExtendExecutor(resultStream, stream))
1433
+
1434
+ const streamExtend = function (stream, values) {
1435
+ if (isNodeReadStream(values)) {
1436
+ return _streamExtend(stream, values)
1437
+ }
1438
+ stream.write(values)
1439
+ return stream
1440
+ }
1441
+
1442
+ const setExtend = function (set, values) {
1443
+ if (values != null && values.constructor == Set) {
1444
+ for (const value of values) {
1445
+ set.add(value)
1446
+ }
1447
+ return set
1448
+ }
1449
+ return set.add(values)
1450
+ }
1451
+
1452
+ const callConcat = function (object, values) {
1453
+ return object.concat(values)
1454
+ }
1455
+
1456
+ const identityTransform = function (collection, transducer, result) {
1457
+ const nil = genericReduce(collection, transducer(noop), null)
1458
+ return isPromise(nil) ? nil.then(always(result)) : result
1459
+ }
1460
+
1461
+ const genericTransform = function (collection, transducer, result) {
1462
+ if (isArray(result)) {
1463
+ return genericReduce(collection, transducer(arrayExtend), result)
1464
+ }
1465
+ if (isBinary(result)) {
1466
+ const intermediateArray = genericReduce(collection, transducer(arrayExtend), [])
1467
+ return isPromise(intermediateArray)
1468
+ ? intermediateArray.then(curry2(binaryExtend, result, __))
1469
+ : binaryExtend(result, intermediateArray)
1470
+ }
1471
+ if (result == null) {
1472
+ return identityTransform(collection, transducer, result)
1473
+ }
1474
+
1475
+ const resultConstructor = result.constructor
1476
+ if (typeof result == 'string' || resultConstructor == String) {
1477
+ // TODO: use array + join over adding
1478
+ return genericReduce(collection, transducer(add), result)
1479
+ }
1480
+ if (typeof result.concat == 'function') {
1481
+ return genericReduce(collection, transducer(callConcat), result)
1482
+ }
1483
+ if (typeof result.write == 'function') {
1484
+ return genericReduce(collection, transducer(streamExtend), result)
1485
+ }
1486
+ if (resultConstructor == Set) {
1487
+ return genericReduce(collection, transducer(setExtend), result)
1488
+ }
1489
+ if (resultConstructor == Object) {
1490
+ return genericReduce(collection, transducer(objectAssign), result)
1491
+ }
1492
+ return identityTransform(collection, transducer, result)
1493
+ }
1494
+
1495
+ // _transform(collection any, transducer function, initialValue function|any) -> Promise
1496
+ const _transform = function (collection, transducer, initialValue) {
1497
+ if (typeof initialValue == 'function') {
1498
+ const actualInitialValue = initialValue(collection)
1499
+ return isPromise(actualInitialValue)
1500
+ ? actualInitialValue.then(curry3(genericTransform, collection, transducer, __))
1501
+ : genericTransform(collection, transducer, actualInitialValue)
1502
+ }
1503
+ return isPromise(initialValue)
1504
+ ? initialValue.then(curry3(genericTransform, collection, transducer, __))
1505
+ : genericTransform(collection, transducer, initialValue)
1506
+ }
1507
+
1508
+ const transform = function (...args) {
1509
+ if (typeof args[0] == 'function') {
1510
+ return curry3(_transform, __, args[0], args[1])
1511
+ }
1512
+ if (isPromise(args[0])) {
1513
+ return args[0].then(curry3(_transform, __, args[1], args[2]))
1514
+ }
1515
+ return _transform(args[0], args[1], args[2])
1516
+ }
1517
+
1518
+ const arrayPush = function (array, value) {
1519
+ array.push(value)
1520
+ return array
1521
+ }
1522
+
1523
+ const FlatMappingIterator = function (iterator, flatMapper) {
1524
+ let buffer = [],
1525
+ bufferIndex = 0
1526
+ return {
1527
+ [symbolIterator]() {
1528
+ return this
1529
+ },
1530
+ next() {
1531
+ if (bufferIndex < buffer.length) {
1532
+ const value = buffer[bufferIndex]
1533
+ bufferIndex += 1
1534
+ return { value, done: false }
1535
+ }
1536
+
1537
+ const iteration = iterator.next()
1538
+ if (iteration.done) {
1539
+ return iteration
1540
+ }
1541
+ const monadAsArray = genericReduce(
1542
+ flatMapper(iteration.value),
1543
+ arrayPush,
1544
+ []) // this will always have at least one item
1545
+ if (monadAsArray.length > 1) {
1546
+ buffer = monadAsArray
1547
+ bufferIndex = 1
1548
+ }
1549
+ return {
1550
+ value: monadAsArray[0],
1551
+ done: false,
1552
+ }
1553
+ },
1554
+ }
1555
+ }
1556
+
1557
+ const sleep = time => new Promise(resolve => {
1558
+ setTimeout(resolve, time)
1559
+ })
1560
+
1561
+ const FlatMappingAsyncIterator = function (asyncIterator, flatMapper) {
1562
+ const buffer = [],
1563
+ promises = new Set()
1564
+
1565
+ return {
1566
+ isAsyncIteratorDone: false,
1567
+ [symbolAsyncIterator]() {
1568
+ return this
1569
+ },
1570
+ toString() {
1571
+ return '[object FlatMappingAsyncIterator]'
1572
+ },
1573
+
1574
+
1575
+ async next() {
1576
+ while (
1577
+ !this.isAsyncIteratorDone || buffer.length > 0 || promises.size > 0
1578
+ ) {
1579
+ if (!this.isAsyncIteratorDone) {
1580
+ const { value, done } = await asyncIterator.next()
1581
+ if (done) {
1582
+ this.isAsyncIteratorDone = done
1583
+ } else {
1584
+ const monad = flatMapper(value)
1585
+ if (isPromise(monad)) {
1586
+ const bufferLoading =
1587
+ monad.then(curry3(genericReduce, __, arrayPush, buffer))
1588
+ const promise = bufferLoading.then(() => promises.delete(promise))
1589
+ promises.add(promise)
1590
+ } else {
1591
+ const bufferLoading = genericReduce(monad, arrayPush, buffer)
1592
+ if (isPromise(bufferLoading)) {
1593
+ const promise = bufferLoading.then(() => promises.delete(promise))
1594
+ promises.add(promise)
1595
+ }
1596
+ }
1597
+ }
1598
+ }
1599
+ if (buffer.length > 0) {
1600
+ return { value: buffer.shift(), done: false }
1601
+ }
1602
+ if (promises.size > 0) {
1603
+ await promiseRace([sleep(1000), ...promises])
1604
+ }
1605
+ }
1606
+ return { value: undefined, done: true }
1607
+ },
1608
+ }
1609
+ }
1610
+
1611
+ const getArg1 = (arg0, arg1) => arg1
1612
+
1613
+ const identity = value => value
1614
+
1615
+ const funcConcatSync = (
1616
+ funcA, funcB,
1617
+ ) => function pipedFunction(...args) {
1618
+ return funcB(funcA(...args))
1619
+ }
1620
+
1621
+ const asyncIteratorForEach = async function (asyncIterator, callback) {
1622
+ const promises = []
1623
+ for await (const item of asyncIterator) {
1624
+ const operation = callback(item)
1625
+ if (isPromise(operation)) {
1626
+ promises.push(operation)
1627
+ }
1628
+ }
1629
+ return promises.length == 0 ? asyncIterator
1630
+ : promiseAll(promises).then(always(asyncIterator))
1631
+ }
1632
+
1633
+ const arrayFlatten = function (array) {
1634
+ const length = array.length,
1635
+ promises = [],
1636
+ result = []
1637
+ let index = -1
1638
+
1639
+ while (++index < length) {
1640
+ const item = array[index]
1641
+ if (isArray(item)) {
1642
+ const itemLength = item.length
1643
+ let itemIndex = -1
1644
+ while (++itemIndex < itemLength) {
1645
+ result.push(item[itemIndex])
1646
+ }
1647
+ } else if (item == null) {
1648
+ result.push(item)
1649
+ } else if (typeof item.then == 'function') {
1650
+ promises.push(item.then(curry2(arrayPush, result, __)))
1651
+ } else if (typeof item[symbolIterator] == 'function') {
1652
+ for (const subItem of item) {
1653
+ result.push(subItem)
1654
+ }
1655
+ } else if (typeof item[symbolAsyncIterator] == 'function') {
1656
+ promises.push(asyncIteratorForEach(
1657
+ item[symbolAsyncIterator](), curry2(arrayPush, result, __)))
1658
+ } else if (typeof item.chain == 'function') {
1659
+ const monadValue = item.chain(identity)
1660
+ isPromise(monadValue)
1661
+ ? promises.push(monadValue.then(curry2(arrayPush, result, __)))
1662
+ : result.push(monadValue)
1663
+ } else if (typeof item.flatMap == 'function') {
1664
+ const monadValue = item.flatMap(identity)
1665
+ isPromise(monadValue)
1666
+ ? promises.push(monadValue.then(curry2(arrayPush, result, __)))
1667
+ : result.push(monadValue)
1668
+ } else if (typeof item.reduce == 'function') {
1669
+ const folded = item.reduce(funcConcatSync(
1670
+ getArg1, curry2(arrayPush, result, __)), null)
1671
+ isPromise(folded) && promises.push(folded)
1672
+ } else if (item.constructor == Object) {
1673
+ for (const key in item) {
1674
+ result.push(item[key])
1675
+ }
1676
+ } else {
1677
+ result.push(item)
1678
+ }
1679
+ }
1680
+ return promises.length == 0
1681
+ ? result
1682
+ : promiseAll(promises).then(always(result))
1683
+ }
1684
+
1685
+ const arrayFlatMap = function (array, flatMapper) {
1686
+ const monadArray = arrayMap(array, flatMapper)
1687
+ return isPromise(monadArray)
1688
+ ? monadArray.then(arrayFlatten)
1689
+ : arrayFlatten(monadArray)
1690
+ }
1691
+
1692
+ const objectFlatten = function (object) {
1693
+ const promises = [],
1694
+ result = {},
1695
+ resultAssign = curry2(objectAssign, result, __),
1696
+ resultAssignReducer = funcConcatSync(getArg1, resultAssign),
1697
+ getResult = () => result
1698
+
1699
+ for (const key in object) {
1700
+ const item = object[key]
1701
+ if (item == null) {
1702
+ continue
1703
+ } else if (typeof item[symbolIterator] == 'function') {
1704
+ for (const monadItem of item) {
1705
+ objectAssign(result, monadItem)
1706
+ }
1707
+ } else if (typeof item[symbolAsyncIterator] == 'function') {
1708
+ promises.push(
1709
+ asyncIteratorForEach(item[symbolAsyncIterator](), resultAssign))
1710
+ } else if (typeof item.chain == 'function') {
1711
+ const monadValue = item.chain(identity)
1712
+ isPromise(monadValue)
1713
+ ? promises.push(monadValue.then(resultAssign))
1714
+ : objectAssign(result, monadValue)
1715
+ } else if (typeof item.flatMap == 'function') {
1716
+ const monadValue = item.flatMap(identity)
1717
+ isPromise(monadValue)
1718
+ ? promises.push(monadValue.then(resultAssign))
1719
+ : resultAssign(monadValue)
1720
+ } else if (typeof item.reduce == 'function') {
1721
+ const folded = item.reduce(resultAssignReducer, null)
1722
+ isPromise(folded) && promises.push(folded)
1723
+ } else {
1724
+ objectAssign(result, item)
1725
+ }
1726
+ }
1727
+ return promises.length == 0
1728
+ ? result
1729
+ : promiseAll(promises).then(getResult)
1730
+ }
1731
+
1732
+ const objectFlatMap = function (object, flatMapper) {
1733
+ const monadObject = objectMap(object, flatMapper)
1734
+ return isPromise(monadObject)
1735
+ ? monadObject.then(objectFlatten)
1736
+ : objectFlatten(monadObject)
1737
+ }
1738
+
1739
+ const setFlatten = function (set) {
1740
+ const size = set.size,
1741
+ promises = [],
1742
+ result = new Set(),
1743
+ resultAddReducer = (_, subItem) => result.add(subItem),
1744
+ resultAdd = curry3(callPropUnary, result, 'add', __),
1745
+ getResult = () => result
1746
+
1747
+ for (const item of set) {
1748
+ if (isArray(item)) {
1749
+ const itemLength = item.length
1750
+ let itemIndex = -1
1751
+ while (++itemIndex < itemLength) {
1752
+ result.add(item[itemIndex])
1753
+ }
1754
+ } else if (item == null) {
1755
+ result.add(item)
1756
+ } else if (typeof item[symbolIterator] == 'function') {
1757
+ for (const subItem of item) {
1758
+ result.add(subItem)
1759
+ }
1760
+ } else if (typeof item[symbolAsyncIterator] == 'function') {
1761
+ promises.push(
1762
+ asyncIteratorForEach(item[symbolAsyncIterator](), resultAdd))
1763
+ } else if (typeof item.chain == 'function') {
1764
+ const monadValue = item.chain(identity)
1765
+ isPromise(monadValue)
1766
+ ? promises.push(monadValue.then(resultAdd))
1767
+ : result.add(monadValue)
1768
+ } else if (typeof item.flatMap == 'function') {
1769
+ const monadValue = item.flatMap(identity)
1770
+ isPromise(monadValue)
1771
+ ? promises.push(monadValue.then(resultAdd))
1772
+ : result.add(monadValue)
1773
+ } else if (typeof item.reduce == 'function') {
1774
+ const folded = item.reduce(resultAddReducer, null)
1775
+ isPromise(folded) && promises.push(folded)
1776
+ } else if (item.constructor == Object) {
1777
+ for (const key in item) {
1778
+ result.add(item[key])
1779
+ }
1780
+ } else {
1781
+ result.add(item)
1782
+ }
1783
+ }
1784
+ return promises.length == 0 ? result : promiseAll(promises).then(getResult)
1785
+ }
1786
+
1787
+ const setFlatMap = function (set, flatMapper) {
1788
+ const monadSet = setMap(set, flatMapper)
1789
+ return isPromise(monadSet)
1790
+ ? monadSet.then(setFlatten)
1791
+ : setFlatten(monadSet)
1792
+ }
1793
+
1794
+ const arrayJoin = (array, delimiter) => array.join(delimiter)
1795
+
1796
+ const arrayFlattenToString = funcConcat(
1797
+ arrayFlatten,
1798
+ curry2(arrayJoin, __, ''))
1799
+
1800
+ const stringFlatMap = function (string, flatMapper) {
1801
+ const monadArray = arrayMap(string, flatMapper)
1802
+ return isPromise(monadArray)
1803
+ ? monadArray.then(arrayFlattenToString)
1804
+ : arrayFlattenToString(monadArray)
1805
+ }
1806
+
1807
+ const _flatMap = function (value, flatMapper) {
1808
+ if (isArray(value)) {
1809
+ return arrayFlatMap(value, flatMapper)
1810
+ }
1811
+ if (value == null) {
1812
+ return flatMapper(value)
1813
+ }
1814
+
1815
+ if (typeof value.then == 'function') {
1816
+ return value.then(flatMapper)
1817
+ }
1818
+ if (typeof value.next == 'function') {
1819
+ return symbolIterator in value
1820
+ ? FlatMappingIterator(value, flatMapper)
1821
+ : FlatMappingAsyncIterator(value, flatMapper)
1822
+ }
1823
+ if (typeof value.chain == 'function') {
1824
+ return value.chain(flatMapper)
1825
+ }
1826
+ if (typeof value.flatMap == 'function') {
1827
+ return value.flatMap(flatMapper)
1828
+ }
1829
+ const valueConstructor = value.constructor
1830
+ if (valueConstructor == Object) {
1831
+ return objectFlatMap(value, flatMapper)
1832
+ }
1833
+ if (valueConstructor == Set) {
1834
+ return setFlatMap(value, flatMapper)
1835
+ }
1836
+ if (typeof value == 'string' || valueConstructor == String) {
1837
+ return stringFlatMap(value, flatMapper)
1838
+ }
1839
+ return flatMapper(value)
1840
+ }
1841
+
1842
+ const flatMap = (...args) => {
1843
+ const flatMapper = args.pop()
1844
+ if (args.length == 0) {
1845
+ return curry2(_flatMap, __, flatMapper)
1846
+ }
1847
+ const collection = args[0]
1848
+ return isPromise(collection)
1849
+ ? collection.then(curry2(_flatMap, __, flatMapper))
1850
+ : _flatMap(args[0], flatMapper)
1851
+ }
1852
+
1853
+ const arrayForEach = function (array, callback) {
1854
+ const length = array.length,
1855
+ promises = []
1856
+ let index = -1
1857
+ while (++index < length) {
1858
+ const operation = callback(array[index])
1859
+ if (isPromise(operation)) {
1860
+ promises.push(operation)
1861
+ }
1862
+ }
1863
+ return promises.length == 0 ? array : promiseAll(promises).then(always(array))
1864
+ }
1865
+
1866
+ const objectForEach = function (object, callback) {
1867
+ const promises = []
1868
+ for (const key in object) {
1869
+ const operation = callback(object[key])
1870
+ if (isPromise(operation)) {
1871
+ promises.push(operation)
1872
+ }
1873
+ }
1874
+ return promises.length == 0 ? object : promiseAll(promises).then(always(object))
1875
+ }
1876
+
1877
+ const iteratorForEach = function (iterator, callback) {
1878
+ const promises = []
1879
+ for (const item of iterator) {
1880
+ const operation = callback(item)
1881
+ if (isPromise(operation)) {
1882
+ promises.push(operation)
1883
+ }
1884
+ }
1885
+ return promises.length == 0 ? iterator : promiseAll(promises).then(always(iterator))
1886
+ }
1887
+
1888
+ // type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
1889
+ // _forEach(collection Collection, callback function) -> collection Collection
1890
+ const _forEach = function (collection, callback) {
1891
+ if (isArray(collection)) {
1892
+ return arrayForEach(collection, callback)
1893
+ }
1894
+ if (collection == null) {
1895
+ return collection
1896
+ }
1897
+ if (typeof collection.forEach == 'function') {
1898
+ return collection.forEach(callback)
1899
+ }
1900
+ if (typeof collection[symbolIterator] == 'function') {
1901
+ return iteratorForEach(collection[symbolIterator](), callback)
1902
+ }
1903
+ if (typeof collection[symbolAsyncIterator] == 'function') {
1904
+ return asyncIteratorForEach(collection[symbolAsyncIterator](), callback)
1905
+ }
1906
+ if (collection.constructor == Object) {
1907
+ return objectForEach(collection, callback)
1908
+ }
1909
+ return collection
1910
+ }
1911
+
1912
+ const forEach = function (...args) {
1913
+ const callback = args.pop()
1914
+ if (args.length == 0) {
1915
+ return curry2(_forEach, __, callback)
1916
+ }
1917
+ const collection = args[0]
1918
+ return isPromise(collection)
1919
+ ? collection.then(curry2(_forEach, __, callback))
1920
+ : _forEach(collection, callback)
1921
+ }
1922
+
1923
+ const SelfReferencingPromise = function (basePromise) {
1924
+ const promise = basePromise.then(res => [res, promise])
1925
+ return promise
1926
+ }
1927
+
1928
+ const asyncArraySome = async function (
1929
+ array, predicate, index, promisesInFlight,
1930
+ ) {
1931
+ const length = array.length
1932
+
1933
+ while (++index < length) {
1934
+ const predication = predicate(array[index])
1935
+ if (isPromise(predication)) {
1936
+ promisesInFlight.add(SelfReferencingPromise(predication))
1937
+ } else if (predication) {
1938
+ return true
1939
+ }
1940
+ }
1941
+ while (promisesInFlight.size > 0) {
1942
+ const [predication, promise] = await promiseRace(promisesInFlight)
1943
+ promisesInFlight.delete(promise)
1944
+ if (predication) {
1945
+ return true
1946
+ }
1947
+ }
1948
+ return false
1949
+ }
1950
+
1951
+ const arraySome = function (array, predicate) {
1952
+ const length = array.length
1953
+ let index = -1
1954
+ while (++index < length) {
1955
+ const predication = predicate(array[index])
1956
+ if (isPromise(predication)) {
1957
+ return asyncArraySome(
1958
+ array, predicate, index, new Set([SelfReferencingPromise(predication)]))
1959
+ }
1960
+ if (predication) {
1961
+ return true
1962
+ }
1963
+ }
1964
+ return false
1965
+ }
1966
+
1967
+ const asyncIteratorSome = async function (
1968
+ iterator, predicate, promisesInFlight, maxConcurrency = 20,
1969
+ ) {
1970
+ let iteration = iterator.next()
1971
+ if (isPromise(iteration)) {
1972
+ iteration = await iteration
1973
+ }
1974
+
1975
+ while (!iteration.done) {
1976
+ if (promisesInFlight.size >= maxConcurrency) {
1977
+ const [predication, promise] = await promiseRace(promisesInFlight)
1978
+ promisesInFlight.delete(promise)
1979
+ if (predication) {
1980
+ return true
1981
+ }
1982
+ }
1983
+ const predication = predicate(iteration.value)
1984
+ if (isPromise(predication)) {
1985
+ promisesInFlight.add(SelfReferencingPromise(predication))
1986
+ } else if (predication) {
1987
+ return true
1988
+ }
1989
+ iteration = iterator.next()
1990
+ if (isPromise(iteration)) {
1991
+ iteration = await iteration
1992
+ }
1993
+ }
1994
+ while (promisesInFlight.size > 0) {
1995
+ const [predication, promise] = await promiseRace(promisesInFlight)
1996
+ promisesInFlight.delete(promise)
1997
+ if (predication) {
1998
+ return true
1999
+ }
2000
+ }
2001
+ return false
2002
+ }
2003
+
2004
+ const iteratorSome = function (iterator, predicate) {
2005
+ for (const item of iterator) {
2006
+ const predication = predicate(item)
2007
+ if (isPromise(predication)) {
2008
+ return asyncIteratorSome(
2009
+ iterator, predicate, new Set([SelfReferencingPromise(predication)]))
2010
+ }
2011
+ if (predication) {
2012
+ return true
2013
+ }
2014
+ }
2015
+ return false
2016
+ }
2017
+
2018
+ const reducerAnySync = predicate => function anyReducer(result, item) {
2019
+ return result ? true : predicate(item)
2020
+ }
2021
+
2022
+ const reducerSome = predicate => function anyReducer(result, item) {
2023
+ return result === true ? result
2024
+ : isPromise(result) ? result.then(curry2(reducerAnySync(predicate), __, item))
2025
+ : result ? true : predicate(item)
2026
+ }
2027
+
2028
+ // _some(collection Array|Iterable|AsyncIterable|{ reduce: function }|Object, predicate function) -> Promise|boolean
2029
+ const _some = function (collection, predicate) {
2030
+ if (isArray(collection)) {
2031
+ return arraySome(collection, predicate)
2032
+ }
2033
+ if (collection == null) {
2034
+ return predicate(collection)
2035
+ }
2036
+ if (typeof collection[symbolIterator] == 'function') {
2037
+ return iteratorSome(collection[symbolIterator](), predicate)
2038
+ }
2039
+ if (typeof collection[symbolAsyncIterator] == 'function') {
2040
+ return asyncIteratorSome(
2041
+ collection[symbolAsyncIterator](), predicate, new Set()
2042
+ )
2043
+ }
2044
+ if (typeof collection.reduce == 'function') {
2045
+ return collection.reduce(reducerSome(predicate), false)
2046
+ }
2047
+ if (collection.constructor == Object) {
2048
+ return arraySome(objectValues(collection), predicate)
2049
+ }
2050
+ return predicate(collection)
2051
+ }
2052
+
2053
+ const some = function (...args) {
2054
+ const predicate = args.pop()
2055
+ if (args.length == 0) {
2056
+ return curry2(_some, __, predicate)
2057
+ }
2058
+
2059
+ const collection = args[0]
2060
+ if (isPromise(collection)) {
2061
+ return collection.then(curry2(_some, __, predicate))
2062
+ }
2063
+
2064
+ return _some(collection, predicate)
2065
+ }
2066
+
2067
+ const arrayEvery = function (array, predicate) {
2068
+ const arrayLength = array.length,
2069
+ promises = []
2070
+ let index = -1
2071
+ while (++index < arrayLength) {
2072
+ const predication = predicate(array[index])
2073
+ if (isPromise(predication)) {
2074
+ promises.push(predication)
2075
+ } else if (!predication) {
2076
+ return false
2077
+ }
2078
+ }
2079
+ return promises.length == 0
2080
+ ? true
2081
+ : promiseAll(promises).then(curry3(callPropUnary, __, 'every', Boolean))
2082
+ }
2083
+
2084
+ const iteratorEvery = function (iterator, predicate) {
2085
+ const promises = []
2086
+ for (const item of iterator) {
2087
+ const predication = predicate(item)
2088
+ if (isPromise(predication)) {
2089
+ promises.push(predication)
2090
+ } else if (!predication) {
2091
+ return false
2092
+ }
2093
+ }
2094
+ return promises.length == 0
2095
+ ? true
2096
+ : promiseAll(promises).then(curry3(callPropUnary, __, 'every', Boolean))
2097
+ }
2098
+
2099
+ const asyncIteratorEvery = async function (
2100
+ asyncIterator, predicate, promisesInFlight, maxConcurrency = 20,
2101
+ ) {
2102
+ let iteration = await asyncIterator.next()
2103
+ while (!iteration.done) {
2104
+ if (promisesInFlight.size >= maxConcurrency) {
2105
+ const [predication, promise] = await promiseRace(promisesInFlight)
2106
+ promisesInFlight.delete(promise)
2107
+ if (!predication) {
2108
+ return false
2109
+ }
2110
+ }
2111
+
2112
+ const predication = predicate(iteration.value)
2113
+ if (isPromise(predication)) {
2114
+ promisesInFlight.add(SelfReferencingPromise(predication))
2115
+ } else if (!predication) {
2116
+ return false
2117
+ }
2118
+ iteration = await asyncIterator.next()
2119
+ }
2120
+ while (promisesInFlight.size > 0) {
2121
+ const [predication, promise] = await promiseRace(promisesInFlight)
2122
+ promisesInFlight.delete(promise)
2123
+ if (!predication) {
2124
+ return false
2125
+ }
2126
+ }
2127
+ return true
2128
+ }
2129
+
2130
+ const reducerAllSync = (predicate, result, item) => result ? predicate(item) : false
2131
+
2132
+ const reducerEvery = predicate => function allReducer(result, item) {
2133
+ return result === false ? false
2134
+ : isPromise(result) ? result.then(
2135
+ curry3(reducerAllSync, predicate, __, item))
2136
+ : result ? predicate(item) : false
2137
+ }
2138
+
2139
+ // _every(collection Array|Iterable|AsyncIterable|{ reduce: function }|Object, predicate function) -> Promise|boolean
2140
+ const _every = function (collection, predicate) {
2141
+ if (isArray(collection)) {
2142
+ return arrayEvery(collection, predicate)
2143
+ }
2144
+ if (collection == null) {
2145
+ return predicate(collection)
2146
+ }
2147
+
2148
+ if (typeof collection[symbolIterator] == 'function') {
2149
+ return iteratorEvery(collection[symbolIterator](), predicate)
2150
+ }
2151
+ if (typeof collection[symbolAsyncIterator] == 'function') {
2152
+ return asyncIteratorEvery(
2153
+ collection[symbolAsyncIterator](), predicate, new Set()
2154
+ )
2155
+ }
2156
+ if (typeof collection.reduce == 'function') {
2157
+ return collection.reduce(reducerEvery(predicate), true)
2158
+ }
2159
+ if (collection.constructor == Object) {
2160
+ return arrayEvery(objectValues(collection), predicate)
2161
+ }
2162
+ return predicate(collection)
2163
+ }
2164
+
2165
+ const every = function (...args) {
2166
+ const predicate = args.pop()
2167
+ if (args.length == 0) {
2168
+ return curry2(_every, __, predicate)
2169
+ }
2170
+
2171
+ const collection = args[0]
2172
+ if (isPromise(collection)) {
2173
+ return collection.then(curry2(_every, __, predicate))
2174
+ }
2175
+
2176
+ return _every(collection, predicate)
2177
+ }
2178
+
2179
+ const areAllValuesTruthy = function (predicates, index) {
2180
+ const length = predicates.length
2181
+ while (++index < length) {
2182
+ const predicate = predicates[index]
2183
+ if (isPromise(predicate)) {
2184
+ return predicate.then(curry3(
2185
+ thunkConditional,
2186
+ __,
2187
+ thunkify2(areAllValuesTruthy, predicates, index),
2188
+ always(false),
2189
+ ))
2190
+ }
2191
+ if (!predicate) {
2192
+ return false
2193
+ }
2194
+ }
2195
+ return true
2196
+ }
2197
+
2198
+ const asyncArePredicatesAllTruthy = async function (args, predicates, index) {
2199
+ const length = predicates.length
2200
+ while (++index < length) {
2201
+ let predicate = predicates[index]
2202
+ if (typeof predicate == 'function') {
2203
+ predicate = predicate(...args)
2204
+ }
2205
+ if (isPromise(predicate)) {
2206
+ predicate = await predicate
2207
+ }
2208
+ if (!predicate) {
2209
+ return false
2210
+ }
2211
+ }
2212
+ return true
2213
+ }
2214
+
2215
+ // areAllPredicatesTruthy(args Array, predicates Array<function>) -> Promise|boolean
2216
+ const areAllPredicatesTruthy = function (args, predicates) {
2217
+ const length = predicates.length
2218
+ let index = -1
2219
+
2220
+ while (++index < length) {
2221
+ let predicate = predicates[index]
2222
+ if (typeof predicate == 'function') {
2223
+ predicate = predicate(...args)
2224
+ }
2225
+ if (isPromise(predicate)) {
2226
+ return predicate.then(curry3(
2227
+ thunkConditional,
2228
+ __,
2229
+ thunkify3(asyncArePredicatesAllTruthy, args, predicates, index),
2230
+ always(false),
2231
+ ))
2232
+ }
2233
+ if (!predicate) {
2234
+ return false
2235
+ }
2236
+ }
2237
+ return true
2238
+ }
2239
+
2240
+ const and = function (...args) {
2241
+ const predicatesOrValues = args.pop()
2242
+ if (areAllValuesNonfunctions(predicatesOrValues)) {
2243
+ return areAllValuesTruthy(predicatesOrValues, -1)
2244
+ }
2245
+
2246
+ if (args.length == 0) {
2247
+ return curryArgs2(areAllPredicatesTruthy, __, predicatesOrValues)
2248
+ }
2249
+
2250
+ if (areAnyValuesPromises(args)) {
2251
+ return promiseAll(args)
2252
+ .then(curry2(areAllPredicatesTruthy, __, predicatesOrValues))
2253
+ }
2254
+
2255
+ return areAllPredicatesTruthy(args, predicatesOrValues)
2256
+ }
2257
+
2258
+ const areAnyNonfunctionsTruthy = function (predicates, index) {
2259
+ const length = predicates.length
2260
+ while (++index < length) {
2261
+ const predicate = predicates[index]
2262
+ if (isPromise(predicate)) {
2263
+ return predicate.then(curry3(
2264
+ thunkConditional,
2265
+ __,
2266
+ always(true),
2267
+ thunkify2(areAnyNonfunctionsTruthy, predicates, index),
2268
+ ))
2269
+ }
2270
+ if (predicate) {
2271
+ return true
2272
+ }
2273
+ }
2274
+ return false
2275
+ }
2276
+
2277
+ const asyncAreAnyPredicatesTruthy = async function (args, predicates, index) {
2278
+ const length = predicates.length
2279
+ while (++index < length) {
2280
+ let predicate = predicates[index]
2281
+ if (typeof predicate == 'function') {
2282
+ predicate = predicate(...args)
2283
+ }
2284
+ if (isPromise(predicate)) {
2285
+ predicate = await predicate
2286
+ }
2287
+ if (predicate) {
2288
+ return true
2289
+ }
2290
+ }
2291
+ return false
2292
+ }
2293
+
2294
+ // areAnyPredicatesTruthy(args Array, predicates Array<function>) -> Promise|boolean
2295
+ const areAnyPredicatesTruthy = function (args, predicates) {
2296
+ const length = predicates.length
2297
+ let index = -1
2298
+
2299
+ while (++index < length) {
2300
+ let predicate = predicates[index]
2301
+ if (typeof predicate == 'function') {
2302
+ predicate = predicate(...args)
2303
+ }
2304
+ if (isPromise(predicate)) {
2305
+ return predicate.then(curry3(
2306
+ thunkConditional,
2307
+ __,
2308
+ always(true),
2309
+ thunkify3(asyncAreAnyPredicatesTruthy, args, predicates, index),
2310
+ ))
2311
+ }
2312
+ if (predicate) {
2313
+ return true
2314
+ }
2315
+ }
2316
+ return false
2317
+ }
2318
+
2319
+ const or = function (...args) {
2320
+ const predicatesOrValues = args.pop()
2321
+ if (areAllValuesNonfunctions(predicatesOrValues)) {
2322
+ return areAnyNonfunctionsTruthy(predicatesOrValues, -1)
2323
+ }
2324
+
2325
+ if (args.length == 0) {
2326
+ return curryArgs2(areAnyPredicatesTruthy, __, predicatesOrValues)
2327
+ }
2328
+
2329
+ if (areAnyValuesPromises(args)) {
2330
+ return promiseAll(args)
2331
+ .then(curry2(areAnyPredicatesTruthy, __, predicatesOrValues))
2332
+ }
2333
+
2334
+ return areAnyPredicatesTruthy(args, predicatesOrValues)
2335
+ }
2336
+
2337
+ // negate(value boolean) -> inverse boolean
2338
+ const negate = value => !value
2339
+
2340
+ // _not(args Array, predicate function)
2341
+ const _not = function (args, predicate) {
2342
+ const boolean = predicate(...args)
2343
+ return isPromise(boolean) ? boolean.then(negate) : !boolean
2344
+ }
2345
+
2346
+ const not = function (...args) {
2347
+ const predicateOrValue = args.pop()
2348
+ if (typeof predicateOrValue == 'function') {
2349
+ if (args.length == 0) {
2350
+ return curryArgs2(_not, __, predicateOrValue)
2351
+ }
2352
+ if (areAnyValuesPromises(args)) {
2353
+ return promiseAll(args).then(curry2(_not, __, predicateOrValue))
2354
+ }
2355
+ return _not(args, predicateOrValue)
2356
+ }
2357
+ return !predicateOrValue
2358
+ }
2359
+
2360
+ // argument resolver for curryArgs4
2361
+ const curryArgs4ResolveArgs0 = (
2362
+ baseFunc, arg1, arg2, arg3,
2363
+ ) => function args0Resolver(...args) {
2364
+ return baseFunc(args, arg1, arg2, arg3)
2365
+ }
2366
+
2367
+ // argument resolver for curryArgs4
2368
+ const curryArgs4ResolveArgs1 = (
2369
+ baseFunc, arg0, arg2, arg3,
2370
+ ) => function args1Resolver(...args) {
2371
+ return baseFunc(arg0, args, arg2, arg3)
2372
+ }
2373
+
2374
+ // argument resolver for curryArgs4
2375
+ const curryArgs4ResolveArgs2 = (
2376
+ baseFunc, arg0, arg1, arg3,
2377
+ ) => function args2Resolver(...args) {
2378
+ return baseFunc(arg0, arg1, args, arg3)
2379
+ }
2380
+
2381
+ // argument resolver for curryArgs4
2382
+ const curryArgs4ResolveArgs3 = (
2383
+ baseFunc, arg0, arg1, arg2,
2384
+ ) => function args3Resolver(...args) {
2385
+ return baseFunc(arg0, arg1, arg2, args)
2386
+ }
2387
+
2388
+ const curryArgs4 = function (baseFunc, arg0, arg1, arg2, arg3) {
2389
+ if (arg0 == __) {
2390
+ return curryArgs4ResolveArgs0(baseFunc, arg1, arg2, arg3)
2391
+ }
2392
+ if (arg1 == __) {
2393
+ return curryArgs4ResolveArgs1(baseFunc, arg0, arg2, arg3)
2394
+ }
2395
+ if (arg2 == __) {
2396
+ return curryArgs4ResolveArgs2(baseFunc, arg0, arg1, arg3)
2397
+ }
2398
+ return curryArgs4ResolveArgs3(baseFunc, arg0, arg1, arg2)
2399
+ }
2400
+
2401
+ // leftResolverRightResolverCompare(
2402
+ // args Array, comparator function, left function, right function,
2403
+ // ) -> Promise|boolean
2404
+ const leftResolverRightResolverCompare = function (
2405
+ args, comparator, left, right,
2406
+ ) {
2407
+ const leftResult = left(...args),
2408
+ rightResult = right(...args)
2409
+ if (isPromise(leftResult) || isPromise(rightResult)) {
2410
+ return promiseAll([leftResult, rightResult]).then(spread2(comparator))
2411
+ }
2412
+ return comparator(leftResult, rightResult)
2413
+ }
2414
+
2415
+ // leftResolverRightValueCompare(
2416
+ // args Array, comparator function, left function, right any
2417
+ // ) -> Promise|boolean
2418
+ const leftResolverRightValueCompare = function (args, comparator, left, right) {
2419
+ const leftResult = left(...args)
2420
+ if (isPromise(leftResult) || isPromise(right)) {
2421
+ return promiseAll([leftResult, right]).then(spread2(comparator))
2422
+ }
2423
+ return comparator(leftResult, right)
2424
+ }
2425
+
2426
+ // leftValueRightResolverCompare(
2427
+ // args Array, comparator function, left any, right any,
2428
+ // ) -> Promise|boolean
2429
+ const leftValueRightResolverCompare = function (args, comparator, left, right) {
2430
+ const rightResult = right(...args)
2431
+ if (isPromise(left) || isPromise(rightResult)) {
2432
+ return promiseAll([left, rightResult]).then(spread2(comparator))
2433
+ }
2434
+ return comparator(left, rightResult)
2435
+ }
2436
+
2437
+ // ComparisonOperator(comparator function) -> operator function
2438
+ const ComparisonOperator = comparator => function operator(...args) {
2439
+ const right = args.pop()
2440
+ const left = args.pop()
2441
+ const isLeftResolver = typeof left == 'function',
2442
+ isRightResolver = typeof right == 'function'
2443
+
2444
+ if (isLeftResolver && isRightResolver) {
2445
+ if (args.length == 0) {
2446
+ return curryArgs4(
2447
+ leftResolverRightResolverCompare, __, comparator, left, right,
2448
+ )
2449
+ }
2450
+ if (areAnyValuesPromises(args)) {
2451
+ return promiseAll(args).then(curry4(
2452
+ leftResolverRightResolverCompare, __, comparator, left, right,
2453
+ ))
2454
+ }
2455
+ return leftResolverRightResolverCompare(args, comparator, left, right)
2456
+ }
2457
+
2458
+ if (isLeftResolver) {
2459
+ if (args.length == 0) {
2460
+ return curryArgs4(
2461
+ leftResolverRightValueCompare, __, comparator, left, right,
2462
+ )
2463
+ }
2464
+ if (areAnyValuesPromises(args)) {
2465
+ return promiseAll(args).then(curry4(
2466
+ leftResolverRightValueCompare, __, comparator, left, right,
2467
+ ))
2468
+ }
2469
+ return leftResolverRightValueCompare(args, comparator, left, right)
2470
+ }
2471
+
2472
+ if (isRightResolver) {
2473
+ if (args.length == 0) {
2474
+ return curryArgs4(
2475
+ leftValueRightResolverCompare, __, comparator, left, right,
2476
+ )
2477
+ }
2478
+ if (areAnyValuesPromises(args)) {
2479
+ return promiseAll(args).then(curry4(
2480
+ leftValueRightResolverCompare, __, comparator, left, right,
2481
+ ))
2482
+ }
2483
+ return leftValueRightResolverCompare(args, comparator, left, right)
2484
+ }
2485
+
2486
+ if (isPromise(left) || isPromise(right)) {
2487
+ return promiseAll([left, right]).then(spread2(comparator))
2488
+ }
2489
+ return comparator(left, right)
2490
+ }
2491
+
2492
+ const equals = function (left, right) {
2493
+ return left == right
2494
+ }
2495
+
2496
+ const eq = ComparisonOperator(equals)
2497
+
2498
+ const greaterThan = (left, right) => left > right
2499
+
2500
+ const gt = ComparisonOperator(greaterThan)
2501
+
2502
+ const lessThan = (left, right) => left < right
2503
+
2504
+ const lt = ComparisonOperator(lessThan)
2505
+
2506
+ const greaterThanOrEqual = (left, right) => left >= right
2507
+
2508
+ const gte = ComparisonOperator(greaterThanOrEqual)
2509
+
2510
+ const lessThanOrEqual = (left, right) => left <= right
2511
+
2512
+ const lte = ComparisonOperator(lessThanOrEqual)
2513
+
2514
+ const memoizeCappedUnary = function (func, cap) {
2515
+ const cache = new Map(),
2516
+ memoized = function memoized(arg0) {
2517
+ if (cache.has(arg0)) {
2518
+ return cache.get(arg0)
2519
+ }
2520
+ const result = func(arg0)
2521
+ cache.set(arg0, result)
2522
+ if (cache.size > cap) {
2523
+ cache.clear()
2524
+ }
2525
+ return result
2526
+ }
2527
+ memoized.cache = cache
2528
+ return memoized
2529
+ }
2530
+
2531
+ // a[0].b.c
2532
+ const pathDelimiters = /[.|[|\]]+/
2533
+
2534
+ const parsePropertyPath = function (pathString) {
2535
+ const pathStringLastIndex = pathString.length - 1,
2536
+ firstChar = pathString[0],
2537
+ lastChar = pathString[pathStringLastIndex],
2538
+ isFirstCharLeftBracket = firstChar == '[',
2539
+ isLastCharRightBracket = lastChar == ']'
2540
+
2541
+ if (isFirstCharLeftBracket && isLastCharRightBracket) {
2542
+ return pathString.slice(1, pathStringLastIndex).split(pathDelimiters)
2543
+ } else if (isFirstCharLeftBracket) {
2544
+ return pathString.slice(1).split(pathDelimiters)
2545
+ } else if (isLastCharRightBracket) {
2546
+ return pathString.slice(0, pathStringLastIndex).split(pathDelimiters)
2547
+ }
2548
+ return pathString.split(pathDelimiters)
2549
+ }
2550
+
2551
+ // memoized version of parsePropertyPath, max cache size 500
2552
+ const memoizedCappedParsePropertyPath = memoizeCappedUnary(parsePropertyPath, 500)
2553
+
2554
+ const propertyPathToArray = path => isArray(path) ? path
2555
+ : typeof path == 'string' ? memoizedCappedParsePropertyPath(path)
2556
+ : [path]
2557
+
2558
+ const getByPath = function (value, path) {
2559
+ const propertyPathArray = propertyPathToArray(path),
2560
+ length = propertyPathArray.length
2561
+ let index = -1,
2562
+ result = value
2563
+ while (++index < length) {
2564
+ result = result[propertyPathArray[index]]
2565
+ if (result == null) {
2566
+ return undefined
2567
+ }
2568
+ }
2569
+ return result
2570
+ }
2571
+
2572
+ // _get(object Object, path string, defaultValue function|any)
2573
+ const _get = function (object, path, defaultValue) {
2574
+ const result = object == null ? undefined : getByPath(object, path)
2575
+ return result === undefined
2576
+ ? typeof defaultValue == 'function' ? defaultValue(object) : defaultValue
2577
+ : result
2578
+ }
2579
+
2580
+ const get = function (arg0, arg1, arg2) {
2581
+ if (isPromise(arg0)) {
2582
+ return arg0.then(curry3(_get, __, arg1, arg2))
2583
+ }
2584
+ if (isObject(arg0) && !isArray(arg0)) {
2585
+ return _get(arg0, arg1, arg2)
2586
+ }
2587
+ return curry3(_get, __, arg0, arg1)
2588
+ }
2589
+
2590
+ const setByPath = function (obj, value, path) {
2591
+ if (!isObject(obj)){
2592
+ return obj
2593
+ }
2594
+ const pathArray = propertyPathToArray(path)
2595
+ const pathLength = pathArray.length
2596
+ const lastIndex = pathLength - 1
2597
+ const result = { ...obj }
2598
+ let nested = result
2599
+ let index = -1
2600
+ while (++index < pathLength){
2601
+ const pathKey = pathArray[index]
2602
+ if (index == lastIndex){
2603
+ nested[pathKey] = value
2604
+ } else {
2605
+ const existingNextNested = nested[pathKey]
2606
+ const nextNested = isArray(existingNextNested)
2607
+ ? existingNextNested.slice() : { ...existingNextNested }
2608
+ nested[pathKey] = nextNested
2609
+ nested = nextNested
2610
+ }
2611
+ }
2612
+ return result
2613
+ }
2614
+
2615
+ const _set = function (obj, path, value) {
2616
+ if (typeof value == 'function') {
2617
+ const actualValue = value(obj)
2618
+ if (isPromise(actualValue)) {
2619
+ return actualValue.then(
2620
+ curry3(setByPath, obj, __, path)
2621
+ )
2622
+ }
2623
+ return setByPath(obj, actualValue, path)
2624
+ }
2625
+ if (isPromise(value)) {
2626
+ return value.then(
2627
+ curry3(setByPath, obj, __, path)
2628
+ )
2629
+ }
2630
+ return setByPath(obj, value, path)
2631
+ }
2632
+
2633
+ const set = function (arg0, arg1, arg2) {
2634
+ if (arg2 == null) {
2635
+ return curry3(_set, __, arg0, arg1)
2636
+ }
2637
+ if (isPromise(arg0)) {
2638
+ return arg0.then(curry3(_set, __, arg1, arg2))
2639
+ }
2640
+ return _set(arg0, arg1, arg2)
2641
+ }
2642
+
2643
+ // _pick(source Object, keys Array<string>) -> result Object
2644
+ const _pick = function (source, keys) {
2645
+ if (source == null) {
2646
+ return source
2647
+ }
2648
+ const keysLength = keys.length
2649
+ let result = {}
2650
+ let keysIndex = -1
2651
+ while (++keysIndex < keysLength) {
2652
+ const key = keys[keysIndex],
2653
+ value = getByPath(source, key)
2654
+ if (value != null) {
2655
+ result = setByPath(result, value, key)
2656
+ }
2657
+ }
2658
+ return result
2659
+ }
2660
+
2661
+ const pick = function (arg0, arg1) {
2662
+ if (arg1 == null) {
2663
+ return curry2(_pick, __, arg0)
2664
+ }
2665
+ if (isPromise(arg0)) {
2666
+ return arg0.then(curry2(_pick, __, arg1))
2667
+ }
2668
+ return _pick(arg0, arg1)
2669
+ }
2670
+
2671
+ const deleteByPath = function (object, path) {
2672
+ if (object == null) {
2673
+ return undefined
2674
+ }
2675
+ const pathArray = propertyPathToArray(path),
2676
+ lengthMinusOne = pathArray.length - 1
2677
+ let index = -1,
2678
+ result = object
2679
+ while (++index < lengthMinusOne) {
2680
+ result = result[pathArray[index]]
2681
+ if (result == null) {
2682
+ return undefined
2683
+ }
2684
+ }
2685
+ const property = pathArray[index]
2686
+ if (result != null && property in result) {
2687
+ delete result[property]
2688
+ }
2689
+ return undefined
2690
+ }
2691
+
2692
+ // objectCopyDeep(array Array) -> copied Array
2693
+ const objectCopyDeep = function (object) {
2694
+ const result = {}
2695
+ for (const key in object) {
2696
+ const item = object[key]
2697
+ if (isArray(item)) {
2698
+ result[key] = arrayCopyDeep(item)
2699
+ } else if (item != null && item.constructor == Object) {
2700
+ result[key] = objectCopyDeep(item)
2701
+ } else {
2702
+ result[key] = item
2703
+ }
2704
+ }
2705
+ return result
2706
+ }
2707
+
2708
+ // arrayCopyDeep(array Array) -> copied Array
2709
+ const arrayCopyDeep = function (array) {
2710
+ const length = array.length,
2711
+ result = []
2712
+ let index = -1
2713
+ while (++index < length) {
2714
+ const item = array[index]
2715
+ if (isArray(item)) {
2716
+ result[index] = arrayCopyDeep(item)
2717
+ } else if (item != null && item.constructor == Object) {
2718
+ result[index] = objectCopyDeep(item)
2719
+ } else {
2720
+ result[index] = item
2721
+ }
2722
+ }
2723
+ return result
2724
+ }
2725
+
2726
+ const copyDeep = function (value) {
2727
+ if (isArray(value)) {
2728
+ return arrayCopyDeep(value)
2729
+ }
2730
+ if (value == null) {
2731
+ return value
2732
+ }
2733
+ if (value.constructor == Object) {
2734
+ return objectCopyDeep(value)
2735
+ }
2736
+ return value
2737
+ }
2738
+
2739
+ // _omit(source Object, paths Array<string>) -> result Object
2740
+ const _omit = function (source, paths) {
2741
+ const pathsLength = paths.length,
2742
+ result = copyDeep(source)
2743
+ let pathsIndex = -1
2744
+ while (++pathsIndex < pathsLength) {
2745
+ deleteByPath(result, paths[pathsIndex])
2746
+ }
2747
+ return result
2748
+ }
2749
+
2750
+ const omit = function (arg0, arg1) {
2751
+ if (arg1 == null) {
2752
+ return curry2(_omit, __, arg0)
2753
+ }
2754
+ if (isPromise(arg0)) {
2755
+ return arg0.then(curry2(_omit, __, arg1))
2756
+ }
2757
+ return _omit(arg0, arg1)
2758
+ }
2759
+
2760
+ const thunkify = (func, ...args) => function thunk() {
2761
+ if (areAnyValuesPromises(args)) {
2762
+ return promiseAll(args).then(curry2(funcApply, func, __))
2763
+ }
2764
+ return func(...args)
2765
+ }
2766
+
2767
+ const curry = (func, ...args) => curryArity(func.length, func, args)
2768
+
2769
+ curry.arity = function curryArity_(arity, func, ...args) {
2770
+ return curryArity(arity, func, args)
2771
+ }
2772
+
2773
+ const rubico = {
2774
+ pipe, compose,
2775
+
2776
+ tap, forEach,
2777
+
2778
+ switchCase,
2779
+
2780
+ tryCatch,
2781
+
2782
+ all, assign, get, set, pick, omit,
2783
+
2784
+ map, filter, flatMap, reduce, transform,
2785
+
2786
+ and, or, not, some, every,
2787
+
2788
+ eq, gt, lt, gte, lte,
2789
+
2790
+ thunkify, always, curry, __,
2791
+ }
2792
+
2793
+ return rubico
2794
+ }())))