rubico 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. package/_internal/arrayMapPool.js +11 -19
  2. package/_internal/mapMapPool.js +80 -0
  3. package/_internal/objectMapPool.js +77 -0
  4. package/_internal/objectMapSeries.js +1 -0
  5. package/_internal/setMapPool.js +79 -0
  6. package/_internal/stringMapPool.js +22 -0
  7. package/all.js +11 -1
  8. package/and.js +9 -0
  9. package/assign.js +14 -1
  10. package/compose.js +8 -0
  11. package/dist/Transducer.es.js +1 -1
  12. package/dist/Transducer.es.min.js +1 -1
  13. package/dist/Transducer.js +1 -1
  14. package/dist/Transducer.min.js +1 -1
  15. package/dist/Transducer.mjs +1 -1
  16. package/dist/__.es.js +1 -1
  17. package/dist/__.es.min.js +1 -1
  18. package/dist/__.js +1 -1
  19. package/dist/__.min.js +1 -1
  20. package/dist/__.mjs +1 -1
  21. package/dist/all.es.js +1 -1
  22. package/dist/all.es.min.js +1 -1
  23. package/dist/all.js +1 -1
  24. package/dist/all.min.js +1 -1
  25. package/dist/all.mjs +1 -1
  26. package/dist/always.es.js +1 -1
  27. package/dist/always.es.min.js +1 -1
  28. package/dist/always.js +1 -1
  29. package/dist/always.min.js +1 -1
  30. package/dist/always.mjs +1 -1
  31. package/dist/and.es.js +1 -1
  32. package/dist/and.es.min.js +1 -1
  33. package/dist/and.js +1 -1
  34. package/dist/and.min.js +1 -1
  35. package/dist/and.mjs +1 -1
  36. package/dist/assign.es.js +1 -1
  37. package/dist/assign.es.min.js +1 -1
  38. package/dist/assign.js +1 -1
  39. package/dist/assign.min.js +1 -1
  40. package/dist/assign.mjs +1 -1
  41. package/dist/compose.es.js +1 -1
  42. package/dist/compose.es.min.js +1 -1
  43. package/dist/compose.js +1 -1
  44. package/dist/compose.min.js +1 -1
  45. package/dist/compose.mjs +1 -1
  46. package/dist/curry.es.js +1 -1
  47. package/dist/curry.es.min.js +1 -1
  48. package/dist/curry.js +1 -1
  49. package/dist/curry.min.js +1 -1
  50. package/dist/curry.mjs +1 -1
  51. package/dist/eq.es.js +1 -1
  52. package/dist/eq.es.min.js +1 -1
  53. package/dist/eq.js +1 -1
  54. package/dist/eq.min.js +1 -1
  55. package/dist/eq.mjs +1 -1
  56. package/dist/every.es.js +1 -1
  57. package/dist/every.es.min.js +1 -1
  58. package/dist/every.js +1 -1
  59. package/dist/every.min.js +1 -1
  60. package/dist/every.mjs +1 -1
  61. package/dist/filter.es.js +1 -1
  62. package/dist/filter.es.min.js +1 -1
  63. package/dist/filter.js +1 -1
  64. package/dist/filter.min.js +1 -1
  65. package/dist/filter.mjs +1 -1
  66. package/dist/flatMap.es.js +1 -1
  67. package/dist/flatMap.es.min.js +1 -1
  68. package/dist/flatMap.js +1 -1
  69. package/dist/flatMap.min.js +1 -1
  70. package/dist/flatMap.mjs +1 -1
  71. package/dist/forEach.es.js +3 -2
  72. package/dist/forEach.es.min.js +2 -2
  73. package/dist/forEach.js +3 -2
  74. package/dist/forEach.min.js +2 -2
  75. package/dist/forEach.mjs +3 -2
  76. package/dist/get.es.js +1 -1
  77. package/dist/get.es.min.js +1 -1
  78. package/dist/get.js +1 -1
  79. package/dist/get.min.js +1 -1
  80. package/dist/get.mjs +1 -1
  81. package/dist/gt.es.js +1 -1
  82. package/dist/gt.es.min.js +1 -1
  83. package/dist/gt.js +1 -1
  84. package/dist/gt.min.js +1 -1
  85. package/dist/gt.mjs +1 -1
  86. package/dist/gte.es.js +1 -1
  87. package/dist/gte.es.min.js +1 -1
  88. package/dist/gte.js +1 -1
  89. package/dist/gte.min.js +1 -1
  90. package/dist/gte.mjs +1 -1
  91. package/dist/lt.es.js +1 -1
  92. package/dist/lt.es.min.js +1 -1
  93. package/dist/lt.js +1 -1
  94. package/dist/lt.min.js +1 -1
  95. package/dist/lt.mjs +1 -1
  96. package/dist/lte.es.js +1 -1
  97. package/dist/lte.es.min.js +1 -1
  98. package/dist/lte.js +1 -1
  99. package/dist/lte.min.js +1 -1
  100. package/dist/lte.mjs +1 -1
  101. package/dist/map.es.js +221 -44
  102. package/dist/map.es.min.js +2 -2
  103. package/dist/map.js +221 -44
  104. package/dist/map.min.js +2 -2
  105. package/dist/map.mjs +221 -44
  106. package/dist/not.es.js +1 -1
  107. package/dist/not.es.min.js +1 -1
  108. package/dist/not.js +1 -1
  109. package/dist/not.min.js +1 -1
  110. package/dist/not.mjs +1 -1
  111. package/dist/omit.es.js +1 -1
  112. package/dist/omit.es.min.js +1 -1
  113. package/dist/omit.js +1 -1
  114. package/dist/omit.min.js +1 -1
  115. package/dist/omit.mjs +1 -1
  116. package/dist/or.es.js +1 -1
  117. package/dist/or.es.min.js +1 -1
  118. package/dist/or.js +1 -1
  119. package/dist/or.min.js +1 -1
  120. package/dist/or.mjs +1 -1
  121. package/dist/pick.es.js +1 -1
  122. package/dist/pick.es.min.js +1 -1
  123. package/dist/pick.js +1 -1
  124. package/dist/pick.min.js +1 -1
  125. package/dist/pick.mjs +1 -1
  126. package/dist/pipe.es.js +1 -1
  127. package/dist/pipe.es.min.js +1 -1
  128. package/dist/pipe.js +1 -1
  129. package/dist/pipe.min.js +1 -1
  130. package/dist/pipe.mjs +1 -1
  131. package/dist/reduce.es.js +1 -1
  132. package/dist/reduce.es.min.js +1 -1
  133. package/dist/reduce.js +1 -1
  134. package/dist/reduce.min.js +1 -1
  135. package/dist/reduce.mjs +1 -1
  136. package/dist/rubico.es.js +197 -16
  137. package/dist/rubico.es.min.js +2 -2
  138. package/dist/rubico.global.js +197 -16
  139. package/dist/rubico.global.min.js +2 -2
  140. package/dist/rubico.js +197 -16
  141. package/dist/rubico.min.js +2 -2
  142. package/dist/rubico.mjs +197 -16
  143. package/dist/set.es.js +1 -1
  144. package/dist/set.es.min.js +1 -1
  145. package/dist/set.js +1 -1
  146. package/dist/set.min.js +1 -1
  147. package/dist/set.mjs +1 -1
  148. package/dist/some.es.js +1 -1
  149. package/dist/some.es.min.js +1 -1
  150. package/dist/some.js +1 -1
  151. package/dist/some.min.js +1 -1
  152. package/dist/some.mjs +1 -1
  153. package/dist/switchCase.es.js +1 -1
  154. package/dist/switchCase.es.min.js +1 -1
  155. package/dist/switchCase.js +1 -1
  156. package/dist/switchCase.min.js +1 -1
  157. package/dist/switchCase.mjs +1 -1
  158. package/dist/tap.es.js +38 -1
  159. package/dist/tap.es.min.js +2 -2
  160. package/dist/tap.js +38 -1
  161. package/dist/tap.min.js +2 -2
  162. package/dist/tap.mjs +38 -1
  163. package/dist/thunkify.es.js +1 -1
  164. package/dist/thunkify.es.min.js +1 -1
  165. package/dist/thunkify.js +1 -1
  166. package/dist/thunkify.min.js +1 -1
  167. package/dist/thunkify.mjs +1 -1
  168. package/dist/transform.es.js +1 -1
  169. package/dist/transform.es.min.js +1 -1
  170. package/dist/transform.js +1 -1
  171. package/dist/transform.min.js +1 -1
  172. package/dist/transform.mjs +1 -1
  173. package/dist/tryCatch.es.js +1 -1
  174. package/dist/tryCatch.es.min.js +1 -1
  175. package/dist/tryCatch.js +1 -1
  176. package/dist/tryCatch.min.js +1 -1
  177. package/dist/tryCatch.mjs +1 -1
  178. package/dist/x/append.es.js +1 -1
  179. package/dist/x/append.es.min.js +1 -1
  180. package/dist/x/append.js +1 -1
  181. package/dist/x/append.min.js +1 -1
  182. package/dist/x/append.mjs +1 -1
  183. package/dist/x/callProp.es.js +1 -1
  184. package/dist/x/callProp.es.min.js +1 -1
  185. package/dist/x/callProp.js +1 -1
  186. package/dist/x/callProp.min.js +1 -1
  187. package/dist/x/callProp.mjs +1 -1
  188. package/dist/x/defaultsDeep.es.js +1 -1
  189. package/dist/x/defaultsDeep.es.min.js +1 -1
  190. package/dist/x/defaultsDeep.js +1 -1
  191. package/dist/x/defaultsDeep.min.js +1 -1
  192. package/dist/x/defaultsDeep.mjs +1 -1
  193. package/dist/x/differenceWith.es.js +1 -1
  194. package/dist/x/differenceWith.es.min.js +1 -1
  195. package/dist/x/differenceWith.js +1 -1
  196. package/dist/x/differenceWith.min.js +1 -1
  197. package/dist/x/differenceWith.mjs +1 -1
  198. package/dist/x/filterOut.es.js +1 -1
  199. package/dist/x/filterOut.es.min.js +1 -1
  200. package/dist/x/filterOut.js +1 -1
  201. package/dist/x/filterOut.min.js +1 -1
  202. package/dist/x/filterOut.mjs +1 -1
  203. package/dist/x/find.es.js +1 -1
  204. package/dist/x/find.es.min.js +1 -1
  205. package/dist/x/find.js +1 -1
  206. package/dist/x/find.min.js +1 -1
  207. package/dist/x/find.mjs +1 -1
  208. package/dist/x/findIndex.es.js +1 -1
  209. package/dist/x/findIndex.es.min.js +1 -1
  210. package/dist/x/findIndex.js +1 -1
  211. package/dist/x/findIndex.min.js +1 -1
  212. package/dist/x/findIndex.mjs +1 -1
  213. package/dist/x/first.es.js +1 -1
  214. package/dist/x/first.es.min.js +1 -1
  215. package/dist/x/first.js +1 -1
  216. package/dist/x/first.min.js +1 -1
  217. package/dist/x/first.mjs +1 -1
  218. package/dist/x/flatten.es.js +1 -1
  219. package/dist/x/flatten.es.min.js +1 -1
  220. package/dist/x/flatten.js +1 -1
  221. package/dist/x/flatten.min.js +1 -1
  222. package/dist/x/flatten.mjs +1 -1
  223. package/dist/x/groupBy.es.js +1 -1
  224. package/dist/x/groupBy.es.min.js +1 -1
  225. package/dist/x/groupBy.js +1 -1
  226. package/dist/x/groupBy.min.js +1 -1
  227. package/dist/x/groupBy.mjs +1 -1
  228. package/dist/x/has.es.js +1 -1
  229. package/dist/x/has.es.min.js +1 -1
  230. package/dist/x/has.js +1 -1
  231. package/dist/x/has.min.js +1 -1
  232. package/dist/x/has.mjs +1 -1
  233. package/dist/x/identity.es.js +1 -1
  234. package/dist/x/identity.es.min.js +1 -1
  235. package/dist/x/identity.js +1 -1
  236. package/dist/x/identity.min.js +1 -1
  237. package/dist/x/identity.mjs +1 -1
  238. package/dist/x/includes.es.js +1 -1
  239. package/dist/x/includes.es.min.js +1 -1
  240. package/dist/x/includes.js +1 -1
  241. package/dist/x/includes.min.js +1 -1
  242. package/dist/x/includes.mjs +1 -1
  243. package/dist/x/isDeepEqual.es.js +1 -1
  244. package/dist/x/isDeepEqual.es.min.js +1 -1
  245. package/dist/x/isDeepEqual.js +1 -1
  246. package/dist/x/isDeepEqual.min.js +1 -1
  247. package/dist/x/isDeepEqual.mjs +1 -1
  248. package/dist/x/isEmpty.es.js +1 -1
  249. package/dist/x/isEmpty.es.min.js +1 -1
  250. package/dist/x/isEmpty.js +1 -1
  251. package/dist/x/isEmpty.min.js +1 -1
  252. package/dist/x/isEmpty.mjs +1 -1
  253. package/dist/x/isEqual.es.js +1 -1
  254. package/dist/x/isEqual.es.min.js +1 -1
  255. package/dist/x/isEqual.js +1 -1
  256. package/dist/x/isEqual.min.js +1 -1
  257. package/dist/x/isEqual.mjs +1 -1
  258. package/dist/x/isFunction.es.js +1 -1
  259. package/dist/x/isFunction.es.min.js +1 -1
  260. package/dist/x/isFunction.js +1 -1
  261. package/dist/x/isFunction.min.js +1 -1
  262. package/dist/x/isFunction.mjs +1 -1
  263. package/dist/x/isIn.es.js +1 -1
  264. package/dist/x/isIn.es.min.js +1 -1
  265. package/dist/x/isIn.js +1 -1
  266. package/dist/x/isIn.min.js +1 -1
  267. package/dist/x/isIn.mjs +1 -1
  268. package/dist/x/isObject.es.js +1 -1
  269. package/dist/x/isObject.es.min.js +1 -1
  270. package/dist/x/isObject.js +1 -1
  271. package/dist/x/isObject.min.js +1 -1
  272. package/dist/x/isObject.mjs +1 -1
  273. package/dist/x/isString.es.js +1 -1
  274. package/dist/x/isString.es.min.js +1 -1
  275. package/dist/x/isString.js +1 -1
  276. package/dist/x/isString.min.js +1 -1
  277. package/dist/x/isString.mjs +1 -1
  278. package/dist/x/keys.es.js +1 -1
  279. package/dist/x/keys.es.min.js +1 -1
  280. package/dist/x/keys.js +1 -1
  281. package/dist/x/keys.min.js +1 -1
  282. package/dist/x/keys.mjs +1 -1
  283. package/dist/x/last.es.js +1 -1
  284. package/dist/x/last.es.min.js +1 -1
  285. package/dist/x/last.js +1 -1
  286. package/dist/x/last.min.js +1 -1
  287. package/dist/x/last.mjs +1 -1
  288. package/dist/x/maxBy.es.js +1 -1
  289. package/dist/x/maxBy.es.min.js +1 -1
  290. package/dist/x/maxBy.js +1 -1
  291. package/dist/x/maxBy.min.js +1 -1
  292. package/dist/x/maxBy.mjs +1 -1
  293. package/dist/x/noop.es.js +1 -1
  294. package/dist/x/noop.es.min.js +1 -1
  295. package/dist/x/noop.js +1 -1
  296. package/dist/x/noop.min.js +1 -1
  297. package/dist/x/noop.mjs +1 -1
  298. package/dist/x/pluck.es.js +221 -44
  299. package/dist/x/pluck.es.min.js +2 -2
  300. package/dist/x/pluck.js +221 -44
  301. package/dist/x/pluck.min.js +2 -2
  302. package/dist/x/pluck.mjs +221 -44
  303. package/dist/x/prepend.es.js +1 -1
  304. package/dist/x/prepend.es.min.js +1 -1
  305. package/dist/x/prepend.js +1 -1
  306. package/dist/x/prepend.min.js +1 -1
  307. package/dist/x/prepend.mjs +1 -1
  308. package/dist/x/size.es.js +1 -1
  309. package/dist/x/size.es.min.js +1 -1
  310. package/dist/x/size.js +1 -1
  311. package/dist/x/size.min.js +1 -1
  312. package/dist/x/size.mjs +1 -1
  313. package/dist/x/trace.es.js +38 -1
  314. package/dist/x/trace.es.min.js +2 -2
  315. package/dist/x/trace.js +38 -1
  316. package/dist/x/trace.min.js +2 -2
  317. package/dist/x/trace.mjs +38 -1
  318. package/dist/x/unionWith.es.js +1 -1
  319. package/dist/x/unionWith.es.min.js +1 -1
  320. package/dist/x/unionWith.js +1 -1
  321. package/dist/x/unionWith.min.js +1 -1
  322. package/dist/x/unionWith.mjs +1 -1
  323. package/dist/x/uniq.es.js +1 -1
  324. package/dist/x/uniq.es.min.js +1 -1
  325. package/dist/x/uniq.js +1 -1
  326. package/dist/x/uniq.min.js +1 -1
  327. package/dist/x/uniq.mjs +1 -1
  328. package/dist/x/unless.es.js +1 -1
  329. package/dist/x/unless.es.min.js +1 -1
  330. package/dist/x/unless.js +1 -1
  331. package/dist/x/unless.min.js +1 -1
  332. package/dist/x/unless.mjs +1 -1
  333. package/dist/x/values.es.js +1 -1
  334. package/dist/x/values.es.min.js +1 -1
  335. package/dist/x/values.js +1 -1
  336. package/dist/x/values.min.js +1 -1
  337. package/dist/x/values.mjs +1 -1
  338. package/dist/x/when.es.js +1 -1
  339. package/dist/x/when.es.min.js +1 -1
  340. package/dist/x/when.js +1 -1
  341. package/dist/x/when.min.js +1 -1
  342. package/dist/x/when.mjs +1 -1
  343. package/eq.js +6 -0
  344. package/es.js +197 -16
  345. package/every.js +6 -0
  346. package/filter.js +9 -0
  347. package/flatMap.js +7 -0
  348. package/forEach.js +20 -1
  349. package/get.js +6 -0
  350. package/gt.js +6 -0
  351. package/gte.js +6 -0
  352. package/index.js +197 -16
  353. package/lt.js +6 -0
  354. package/lte.js +6 -0
  355. package/map.js +118 -45
  356. package/not.js +8 -0
  357. package/omit.js +7 -0
  358. package/or.js +9 -0
  359. package/package.json +1 -1
  360. package/pick.js +7 -0
  361. package/pipe.js +8 -0
  362. package/reduce.js +8 -0
  363. package/set.js +6 -0
  364. package/some.js +6 -0
  365. package/switchCase.js +12 -0
  366. package/tap.js +11 -0
  367. package/transform.js +38 -10
  368. package/tryCatch.js +14 -0
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.5.0
2
+ * rubico v2.6.0
3
3
  * https://github.com/a-synchronous/rubico
4
4
  * (c) 2019-2024 Richard Tong
5
5
  * rubico may be freely distributed under the MIT license.
@@ -164,6 +164,9 @@ const tap = function (...args) {
164
164
  if (args.length == 0) {
165
165
  return curryArgs2(_tap, __, func)
166
166
  }
167
+ if (areAnyValuesPromises(args)) {
168
+ return promiseAll(args).then(curry2(_tap, __, func))
169
+ }
167
170
  return _tap(args, func)
168
171
  }
169
172
 
@@ -707,6 +710,7 @@ const objectMapSeries = function (object, f) {
707
710
  thunkify4(_objectMapSeriesAsync, object, f, result, doneKeys),
708
711
  ))
709
712
  }
713
+ result[key] = resultItem
710
714
  }
711
715
  return result
712
716
  }
@@ -801,15 +805,14 @@ const tapSync = func => function tapping(...args) {
801
805
  const promiseRace = Promise.race.bind(Promise)
802
806
 
803
807
  const arrayMapPoolAsync = async function (
804
- array, mapper, concurrencyLimit, result, index, promises,
808
+ array, f, concurrencyLimit, result, index, promises,
805
809
  ) {
806
810
  const arrayLength = array.length
807
811
  while (++index < arrayLength) {
808
812
  if (promises.size >= concurrencyLimit) {
809
813
  await promiseRace(promises)
810
814
  }
811
-
812
- const resultItem = mapper(array[index])
815
+ const resultItem = f(array[index])
813
816
  if (isPromise(resultItem)) {
814
817
  const selfDeletingPromise = resultItem.then(
815
818
  tapSync(() => promises.delete(selfDeletingPromise)))
@@ -822,13 +825,12 @@ const arrayMapPoolAsync = async function (
822
825
  return promiseAll(result)
823
826
  }
824
827
 
825
- const arrayMapPool = function (array, mapper, concurrentLimit) {
828
+ const arrayMapPool = function (array, concurrency, f) {
826
829
  const arrayLength = array.length,
827
830
  result = Array(arrayLength)
828
831
  let index = -1
829
832
  while (++index < arrayLength) {
830
-
831
- const resultItem = mapper(array[index])
833
+ const resultItem = f(array[index])
832
834
  if (isPromise(resultItem)) {
833
835
  const promises = new Set(),
834
836
  selfDeletingPromise = resultItem.then(
@@ -836,13 +838,167 @@ const arrayMapPool = function (array, mapper, concurrentLimit) {
836
838
  promises.add(selfDeletingPromise)
837
839
  result[index] = selfDeletingPromise
838
840
  return arrayMapPoolAsync(
839
- array, mapper, concurrentLimit, result, index, promises)
841
+ array, f, concurrency, result, index, promises)
840
842
  }
841
843
  result[index] = resultItem
842
844
  }
843
845
  return result
844
846
  }
845
847
 
848
+ const stringMapPool = function (s, concurrency, f) {
849
+ const result = arrayMapPool(s, concurrency, f)
850
+ return isPromise(result)
851
+ ? result.then(curry3(callPropUnary, __, 'join', ''))
852
+ : result.join('')
853
+ }
854
+
855
+ const _setMapPoolAsync = async function (
856
+ s, iterator, concurrency, f, result, promises,
857
+ ) {
858
+ let iteration = iterator.next()
859
+ while (!iteration.done) {
860
+ if (promises.size >= concurrency) {
861
+ await promiseRace(promises)
862
+ }
863
+ const resultItem = f(iteration.value, iteration.value, s)
864
+ if (isPromise(resultItem)) {
865
+ const selfDeletingPromise = resultItem.then(resolvedValue => {
866
+ promises.delete(selfDeletingPromise)
867
+ result.add(resolvedValue)
868
+ })
869
+ promises.add(selfDeletingPromise)
870
+ } else {
871
+ result.add(resultItem)
872
+ }
873
+ iteration = iterator.next()
874
+ }
875
+ if (promises.size > 0) {
876
+ await promiseAll(promises)
877
+ }
878
+ return result
879
+ }
880
+
881
+ const setMapPool = function (s, concurrency, f) {
882
+ const result = new Set()
883
+ const iterator = s[symbolIterator]()
884
+ let iteration = iterator.next()
885
+ while (!iteration.done) {
886
+ const resultItem = f(iteration.value, iteration.value, s)
887
+ if (isPromise(resultItem)) {
888
+ const promises = new Set()
889
+ const selfDeletingPromise = resultItem.then(resolvedValue => {
890
+ promises.delete(selfDeletingPromise)
891
+ result.add(resolvedValue)
892
+ })
893
+ promises.add(selfDeletingPromise)
894
+ return _setMapPoolAsync(s, iterator, concurrency, f, result, promises)
895
+ }
896
+ result.add(resultItem)
897
+ iteration = iterator.next()
898
+ }
899
+ return result
900
+ }
901
+
902
+ const _mapMapPoolAsync = async function (
903
+ m, iterator, concurrency, f, result, promises,
904
+ ) {
905
+ let iteration = iterator.next()
906
+ while (!iteration.done) {
907
+ if (promises.size >= concurrency) {
908
+ await promiseRace(promises)
909
+ }
910
+ const key = iteration.value[0]
911
+ const resultItem = f(iteration.value[1], key, m)
912
+ if (isPromise(resultItem)) {
913
+ result.set(key, resultItem)
914
+ const selfDeletingPromise = resultItem.then(resolvedValue => {
915
+ promises.delete(selfDeletingPromise)
916
+ result.set(key, resolvedValue)
917
+ })
918
+ promises.add(selfDeletingPromise)
919
+ } else {
920
+ result.set(key, resultItem)
921
+ }
922
+ iteration = iterator.next()
923
+ }
924
+ if (promises.size > 0) {
925
+ await promiseAll(promises)
926
+ }
927
+ return result
928
+ }
929
+
930
+ const mapMapPool = function (m, concurrency, f) {
931
+ const result = new Map()
932
+ const iterator = m[symbolIterator]()
933
+ let iteration = iterator.next()
934
+ while (!iteration.done) {
935
+ const key = iteration.value[0]
936
+ const resultItem = f(iteration.value[1], key, m)
937
+ if (isPromise(resultItem)) {
938
+ const promises = new Set()
939
+ result.set(key, resultItem)
940
+ const selfDeletingPromise = resultItem.then(resolvedValue => {
941
+ promises.delete(selfDeletingPromise)
942
+ result.set(key, resolvedValue)
943
+ })
944
+ promises.add(selfDeletingPromise)
945
+ return _mapMapPoolAsync(m, iterator, concurrency, f, result, promises)
946
+ }
947
+ result.set(key, resultItem)
948
+ iteration = iterator.next()
949
+ }
950
+ return result
951
+ }
952
+
953
+ const _objectMapPoolAsync = async function (
954
+ o, concurrency, f, result, doneKeys, promises,
955
+ ) {
956
+ for (const key in o) {
957
+ if (key in doneKeys) {
958
+ continue
959
+ }
960
+ if (promises.size >= concurrency) {
961
+ await promiseRace(promises)
962
+ }
963
+ const resultItem = f(o[key], key, o)
964
+ if (isPromise(resultItem)) {
965
+ result[key] = resultItem
966
+ const selfDeletingPromise = resultItem.then(resolvedValue => {
967
+ promises.delete(selfDeletingPromise)
968
+ result[key] = resolvedValue
969
+ })
970
+ promises.add(selfDeletingPromise)
971
+ } else {
972
+ result[key] = resultItem
973
+ }
974
+ }
975
+ if (promises.size > 0) {
976
+ await promiseAll(promises)
977
+ }
978
+ return result
979
+ }
980
+
981
+ const objectMapPool = function (o, concurrency, f) {
982
+ const result = {}
983
+ const doneKeys = {}
984
+ for (const key in o) {
985
+ doneKeys[key] = true
986
+ const resultItem = f(o[key], key, o)
987
+ if (isPromise(resultItem)) {
988
+ const promises = new Set()
989
+ result[key] = resultItem
990
+ const selfDeletingPromise = resultItem.then(resolvedValue => {
991
+ promises.delete(selfDeletingPromise)
992
+ result[key] = resolvedValue
993
+ })
994
+ promises.add(selfDeletingPromise)
995
+ return _objectMapPoolAsync(o, concurrency, f, result, doneKeys, promises)
996
+ }
997
+ result[key] = resultItem
998
+ }
999
+ return result
1000
+ }
1001
+
846
1002
  const _curryArity = (arity, func, args) => function curried(...curriedArgs) {
847
1003
  const argsLength = args.length,
848
1004
  curriedArgsLength = curriedArgs.length,
@@ -978,7 +1134,7 @@ const _map = function (value, mapper) {
978
1134
  }
979
1135
 
980
1136
  const map = function (arg0, arg1) {
981
- if (typeof arg0 == 'function') {
1137
+ if (arg1 == null) {
982
1138
  return curry2(_map, __, arg0)
983
1139
  }
984
1140
  return isPromise(arg0)
@@ -1001,7 +1157,7 @@ const _mapEntries = (value, mapper) => {
1001
1157
  }
1002
1158
 
1003
1159
  map.entries = function mapEntries(arg0, arg1) {
1004
- if (typeof arg0 == 'function') {
1160
+ if (arg1 == null) {
1005
1161
  return curry2(_mapEntries, __, arg0)
1006
1162
  }
1007
1163
  return isPromise(arg0)
@@ -1033,7 +1189,7 @@ const _mapSeries = function (collection, f) {
1033
1189
  }
1034
1190
 
1035
1191
  map.series = function mapSeries(arg0, arg1) {
1036
- if (typeof arg0 == 'function') {
1192
+ if (arg1 == null) {
1037
1193
  return curry2(_mapSeries, __, arg0)
1038
1194
  }
1039
1195
  return isPromise(arg0)
@@ -1041,11 +1197,35 @@ map.series = function mapSeries(arg0, arg1) {
1041
1197
  : _mapSeries(arg0, arg1)
1042
1198
  }
1043
1199
 
1044
- map.pool = (concurrencyLimit, mapper) => function concurrentPoolMapping(value) {
1045
- if (isArray(value)) {
1046
- return arrayMapPool(value, mapper, concurrencyLimit)
1200
+ const _mapPool = function (collection, concurrency, f) {
1201
+ if (isArray(collection)) {
1202
+ return arrayMapPool(collection, concurrency, f)
1203
+ }
1204
+ if (collection == null) {
1205
+ throw new TypeError(`invalid collection ${collection}`)
1047
1206
  }
1048
- throw new TypeError(`${value} is not an Array`)
1207
+ if (typeof collection == 'string' || collection.constructor == String) {
1208
+ return stringMapPool(collection, concurrency, f)
1209
+ }
1210
+ if (collection.constructor == Set) {
1211
+ return setMapPool(collection, concurrency, f)
1212
+ }
1213
+ if (collection.constructor == Map) {
1214
+ return mapMapPool(collection, concurrency, f)
1215
+ }
1216
+ if (collection.constructor == Object) {
1217
+ return objectMapPool(collection, concurrency, f)
1218
+ }
1219
+ throw new TypeError(`invalid collection ${collection}`)
1220
+ }
1221
+
1222
+ map.pool = function mapPool(arg0, arg1, arg2) {
1223
+ if (arg2 == null) {
1224
+ return curry3(_mapPool, __, arg0, arg1)
1225
+ }
1226
+ return isPromise(arg0)
1227
+ ? arg0.then(curry3(_mapPool, __, arg1, arg2))
1228
+ : _mapPool(arg0, arg1, arg2)
1049
1229
  }
1050
1230
 
1051
1231
  const FilteringIterator = (iterator, predicate) => ({
@@ -2152,7 +2332,8 @@ const _forEach = function (collection, callback) {
2152
2332
  return collection
2153
2333
  }
2154
2334
  if (typeof collection.forEach == 'function') {
2155
- return collection.forEach(callback)
2335
+ collection.forEach(callback)
2336
+ return collection
2156
2337
  }
2157
2338
  if (typeof collection[symbolIterator] == 'function') {
2158
2339
  return iteratorForEach(collection[symbolIterator](), callback)
package/lt.js CHANGED
@@ -47,6 +47,12 @@ const lessThan = require('./_internal/lessThan')
47
47
  * console.log, // true
48
48
  * ])
49
49
  * ```
50
+ *
51
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
52
+ *
53
+ * ```javascript [playground]
54
+ * lt(Promise.resolve({ a: 1, b: 2 }), get('a'), get('b')).then(console.log) // true
55
+ * ```
50
56
  */
51
57
  const lt = ComparisonOperator(lessThan)
52
58
 
package/lte.js CHANGED
@@ -47,6 +47,12 @@ const lessThanOrEqual = require('./_internal/lessThanOrEqual')
47
47
  * console.log, // true
48
48
  * ])
49
49
  * ```
50
+ *
51
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
52
+ *
53
+ * ```javascript [playground]
54
+ * lte(Promise.resolve({ a: 1, b: 1 }), get('a'), get('b')).then(console.log) // true
55
+ * ```
50
56
  */
51
57
  const lte = ComparisonOperator(lessThanOrEqual)
52
58
 
package/map.js CHANGED
@@ -3,6 +3,7 @@ const MappingIterator = require('./_internal/MappingIterator')
3
3
  const MappingAsyncIterator = require('./_internal/MappingAsyncIterator')
4
4
  const __ = require('./_internal/placeholder')
5
5
  const curry2 = require('./_internal/curry2')
6
+ const curry3 = require('./_internal/curry3')
6
7
  const isArray = require('./_internal/isArray')
7
8
  const isObject = require('./_internal/isObject')
8
9
  const arrayMap = require('./_internal/arrayMap')
@@ -16,6 +17,10 @@ const objectMapSeries = require('./_internal/objectMapSeries')
16
17
  const setMapSeries = require('./_internal/setMapSeries')
17
18
  const mapMapSeries = require('./_internal/mapMapSeries')
18
19
  const arrayMapPool = require('./_internal/arrayMapPool')
20
+ const stringMapPool = require('./_internal/stringMapPool')
21
+ const setMapPool = require('./_internal/setMapPool')
22
+ const mapMapPool = require('./_internal/mapMapPool')
23
+ const objectMapPool = require('./_internal/objectMapPool')
19
24
  const objectMapEntries = require('./_internal/objectMapEntries')
20
25
  const mapMapEntries = require('./_internal/mapMapEntries')
21
26
  const symbolIterator = require('./_internal/symbolIterator')
@@ -45,21 +50,6 @@ const symbolAsyncIterator = require('./_internal/symbolAsyncIterator')
45
50
  * originalMap Map,
46
51
  * mapMapper (value any, key any, originalMap Map)=>Promise|any
47
52
  * ) -> mappedMap Promise|Map
48
- *
49
- * _map(
50
- * generatorFunction ...args=>Generator,
51
- * syncMapper (value any)=>any,
52
- * ) -> mappingGeneratorFunction ...args=>Generator
53
- *
54
- * _map(
55
- * asyncGeneratorFunction ...args=>AsyncGenerator,
56
- * mapper (value any)=>Promise|any
57
- * ) -> mappingAsyncGeneratorFunction ...args=>AsyncGenerator
58
- *
59
- * _map(
60
- * originalReducer Reducer,
61
- * mapper (value any)=>Promise|any,
62
- * ) -> mappingReducer Reducer
63
53
  * ```
64
54
  */
65
55
 
@@ -107,11 +97,11 @@ const _map = function (value, mapper) {
107
97
  *
108
98
  * type Mapper = (
109
99
  * value any,
110
- * indexOrKey number|string,
100
+ * indexOrKey number|string|any,
111
101
  * collection Mappable
112
102
  * )=>(resultItem Promise|any)
113
103
  *
114
- * map(collection Mappable, f Mapper) -> result Promise|Mappable
104
+ * map(collection Promise|Mappable, f Mapper) -> result Promise|Mappable
115
105
  * map(f Mapper)(collection Mappable) -> result Promise|Mappable
116
106
  * ```
117
107
  *
@@ -246,12 +236,21 @@ const _map = function (value, mapper) {
246
236
  * })()
247
237
  * ```
248
238
  *
239
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
240
+ *
241
+ * ```javascript [playground]
242
+ * const asyncSquare = async n => n ** 2
243
+ *
244
+ * map(Promise.resolve([1, 2, 3, 4, 5]), asyncSquare).then(console.log)
245
+ * // [1, 4, 9, 16, 25]
246
+ * ```
247
+ *
249
248
  * @execution concurrent
250
249
  *
251
250
  * @TODO streamMap
252
251
  */
253
252
  const map = function (arg0, arg1) {
254
- if (typeof arg0 == 'function') {
253
+ if (arg1 == null) {
255
254
  return curry2(_map, __, arg0)
256
255
  }
257
256
  return isPromise(arg0)
@@ -278,14 +277,19 @@ const _mapEntries = (value, mapper) => {
278
277
  *
279
278
  * @synopsis
280
279
  * ```coffeescript [specscript]
281
- * map.entries(
282
- * value Map|Object|Promise<Map|Object>,
283
- * mapper ([key any, value any])=>Promise|[any, any],
284
- * ) -> Promise|Map|Object
280
+ * type EntriesMappable = Object|Map
285
281
  *
286
- * map.entries(
287
- * mapper ([key any, value any])=>Promise|[any, any],
288
- * )(value Map|Object) -> Promise|Map|Object
282
+ * type Mapper = (
283
+ * value any,
284
+ * key string|any,
285
+ * collection EntriesMappable
286
+ * )=>(resultItem Promise|any)
287
+ *
288
+ * map.entries(value Promise|EntriesMappable, mapper Mapper)
289
+ * -> Promise|EntriesMappable
290
+ *
291
+ * map.entries(mapper Mapper)(value EntriesMappable)
292
+ * -> Promise|EntriesMappable
289
293
  * ```
290
294
  *
291
295
  * @description
@@ -302,10 +306,22 @@ const _mapEntries = (value, mapper) => {
302
306
  * // Map(3) { 'A' => 1, 'B' => 4, 'C' => 9 }
303
307
  * ```
304
308
  *
309
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
310
+ *
311
+ * ```javascript [playground]
312
+ * const asyncSquareEntries = async ([k, v]) => [k, v ** 2]
313
+ *
314
+ * map.entries(
315
+ * Promise.resolve({ a: 1, b: 2, c: 3 }),
316
+ * asyncSquareEntries,
317
+ * ).then(console.log)
318
+ * // { a: 1, b: 4, c: 9 }
319
+ * ```
320
+ *
305
321
  * @since v1.7.0
306
322
  */
307
323
  map.entries = function mapEntries(arg0, arg1) {
308
- if (typeof arg0 == 'function') {
324
+ if (arg1 == null) {
309
325
  return curry2(_mapEntries, __, arg0)
310
326
  }
311
327
  return isPromise(arg0)
@@ -318,11 +334,11 @@ map.entries = function mapEntries(arg0, arg1) {
318
334
  *
319
335
  * @synopsis
320
336
  * ```coffeescript [specscript]
321
- * type Mappable = Array|Object|Set|Map|Iterator|AsyncIterator
337
+ * type Mappable = Array|Object|Set|Map
322
338
  *
323
339
  * type Mapper = (
324
340
  * value any,
325
- * indexOrKey number|string,
341
+ * indexOrKey number|string|any,
326
342
  * collection Mappable
327
343
  * )=>(mappedItem Promise|any)
328
344
  *
@@ -357,23 +373,20 @@ const _mapSeries = function (collection, f) {
357
373
  *
358
374
  * @synopsis
359
375
  * ```coffeescript [specscript]
360
- * type Mappable = Array|Object|Set|Map|Iterator|AsyncIterator
376
+ * type Mappable = Array|Object|Set|Map
361
377
  *
362
378
  * type Mapper = (
363
379
  * value any,
364
- * indexOrKey number|string,
380
+ * indexOrKey number|string|any,
365
381
  * collection Mappable
366
382
  * )=>(mappedItem Promise|any)
367
383
  *
368
- * map.series( Mappable)
369
- *
370
- * map.series(
371
- * mapperFunc (value any)=>Promise|any,
372
- * )(array Array) -> Promise|Array
384
+ * map.series(collection Promise|Mappable, f Mapper) -> result Mappable
385
+ * map.series(f Mapper)(collection Mappable) -> result Mappable
373
386
  * ```
374
387
  *
375
388
  * @description
376
- * `map` with serial execution.
389
+ * [map](/docs/map) with serial execution.
377
390
  *
378
391
  * ```javascript [playground]
379
392
  * const delayedLog = number => new Promise(function (resolve) {
@@ -384,13 +397,22 @@ const _mapSeries = function (collection, f) {
384
397
  * })
385
398
  *
386
399
  * console.log('start')
387
- * map.series(delayedLog)([1, 2, 3, 4, 5])
400
+ * map.series([1, 2, 3, 4, 5], delayedLog)
401
+ * ```
402
+ *
403
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
404
+ *
405
+ * ```javascript [playground]
406
+ * const asyncSquare = async n => n ** 2
407
+ *
408
+ * map.series(Promise.resolve([1, 2, 3, 4, 5]), asyncSquare).then(console.log)
409
+ * // [1, 4, 9, 16, 25]
388
410
  * ```
389
411
  *
390
412
  * @execution series
391
413
  */
392
414
  map.series = function mapSeries(arg0, arg1) {
393
- if (typeof arg0 == 'function') {
415
+ if (arg1 == null) {
394
416
  return curry2(_mapSeries, __, arg0)
395
417
  }
396
418
  return isPromise(arg0)
@@ -398,19 +420,59 @@ map.series = function mapSeries(arg0, arg1) {
398
420
  : _mapSeries(arg0, arg1)
399
421
  }
400
422
 
423
+ /**
424
+ * @name _mapPool
425
+ *
426
+ * @synopsis
427
+ * ```coffeescript [specscript]
428
+ * type Mappable = Array|Object|Set|Map
429
+ *
430
+ * _mapPool(collection Mappable, concurrency number, f function) -> result Promise|Mappable
431
+ * ```
432
+ */
433
+ const _mapPool = function (collection, concurrency, f) {
434
+ if (isArray(collection)) {
435
+ return arrayMapPool(collection, concurrency, f)
436
+ }
437
+ if (collection == null) {
438
+ throw new TypeError(`invalid collection ${collection}`)
439
+ }
440
+ if (typeof collection == 'string' || collection.constructor == String) {
441
+ return stringMapPool(collection, concurrency, f)
442
+ }
443
+ if (collection.constructor == Set) {
444
+ return setMapPool(collection, concurrency, f)
445
+ }
446
+ if (collection.constructor == Map) {
447
+ return mapMapPool(collection, concurrency, f)
448
+ }
449
+ if (collection.constructor == Object) {
450
+ return objectMapPool(collection, concurrency, f)
451
+ }
452
+ throw new TypeError(`invalid collection ${collection}`)
453
+ }
454
+
401
455
  /**
402
456
  * @name map.pool
403
457
  *
404
458
  * @synopsis
405
459
  * ```coffeescript [specscript]
460
+ * type Mappable = Array|Object|Set|Map
461
+ *
462
+ * map.pool(
463
+ * concurrency number,
464
+ * mapper (value any)=>Promise|any,
465
+ * )(collection Mappable) -> result Promise|Array
466
+ *
406
467
  * map.pool(
407
- * maxConcurrency number,
468
+ * collection Mappable,
469
+ * concurrency number,
408
470
  * mapper (value any)=>Promise|any,
409
- * )(array Array) -> result Promise|Array
471
+ * ) -> result Promise|Array
410
472
  * ```
411
473
  *
412
474
  * @description
413
- * `map` that specifies the maximum concurrency (number of ongoing promises at any time) of the execution. Only works for arrays.
475
+ * [map](/docs/map) with limited [concurrency](https://web.mit.edu/6.005/www/fa14/classes/17-concurrency/).
414
476
  *
415
477
  * ```javascript [playground]
416
478
  * const ids = [1, 2, 3, 4, 5]
@@ -428,15 +490,26 @@ map.series = function mapSeries(arg0, arg1) {
428
490
  * ]))(ids)
429
491
  * ```
430
492
  *
493
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
494
+ *
495
+ * ```javascript [playground]
496
+ * const asyncSquare = async n => n ** 2
497
+ *
498
+ * map.pool(Promise.resolve([1, 2, 3, 4, 5]), 5, asyncSquare).then(console.log)
499
+ * // [1, 4, 9, 16, 25]
500
+ * ```
501
+ *
431
502
  * @TODO objectMapPool
432
503
  *
433
504
  * @execution concurrent
434
505
  */
435
- map.pool = (concurrencyLimit, mapper) => function concurrentPoolMapping(value) {
436
- if (isArray(value)) {
437
- return arrayMapPool(value, mapper, concurrencyLimit)
506
+ map.pool = function mapPool(arg0, arg1, arg2) {
507
+ if (arg2 == null) {
508
+ return curry3(_mapPool, __, arg0, arg1)
438
509
  }
439
- throw new TypeError(`${value} is not an Array`)
510
+ return isPromise(arg0)
511
+ ? arg0.then(curry3(_mapPool, __, arg1, arg2))
512
+ : _mapPool(arg0, arg1, arg2)
440
513
  }
441
514
 
442
515
  module.exports = map
package/not.js CHANGED
@@ -45,6 +45,14 @@ const _not = function (args, predicate) {
45
45
  * not(isOdd)(3),
46
46
  * ) // false
47
47
  * ```
48
+ *
49
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
50
+ *
51
+ * ```javascript [playground]
52
+ * const isOdd = number => number % 2 == 1
53
+ *
54
+ * not(Promise.resolve(3), isOdd).then(console.log) // false
55
+ * ```
48
56
  */
49
57
 
50
58
  const not = function (...args) {
package/omit.js CHANGED
@@ -62,6 +62,13 @@ const _omit = function (source, paths) {
62
62
  * console.log, // { c: 9 }
63
63
  * ])
64
64
  * ```
65
+ *
66
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
67
+ *
68
+ * ```javascript [playground]
69
+ * omit(Promise.resolve({ a: 1, b: 2, c: 3 }), ['a', 'b']).then(console.log)
70
+ * // { c: 3 }
71
+ * ```
65
72
  */
66
73
  const omit = function (arg0, arg1) {
67
74
  if (arg1 == null) {
package/or.js CHANGED
@@ -129,6 +129,15 @@ const areAnyPredicatesTruthy = function (args, predicates) {
129
129
  * ) // true
130
130
  * ```
131
131
  *
132
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
133
+ *
134
+ * ```javascript [playground]
135
+ * or(Promise.resolve('aaa'), [
136
+ * s => s.startsWith('b'),
137
+ * s => s.endsWith('a'),
138
+ * ]).then(console.log) // true
139
+ * ```
140
+ *
132
141
  * @execution series
133
142
  *
134
143
  * @note ...args slows down here by an order of magnitude
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubico",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "[a]synchronous functional programming",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
package/pick.js CHANGED
@@ -62,6 +62,13 @@ const _pick = function (source, keys) {
62
62
  * console.log, // { a: 1, c: 9 }
63
63
  * ])
64
64
  * ```
65
+ *
66
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
67
+ *
68
+ * ```javascript [playground]
69
+ * pick(Promise.resolve({ a: 1, b: 2, c: 3 }), ['a', 'b']).then(console.log)
70
+ * // { a: 1, b: 2 }
71
+ * ```
65
72
  */
66
73
  const pick = function (arg0, arg1) {
67
74
  if (arg1 == null) {