rubico 2.3.7 → 2.4.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 (342) hide show
  1. package/_internal/arrayForEachSeries.js +48 -0
  2. package/_internal/asyncIteratorForEachSeries.js +28 -0
  3. package/_internal/iteratorForEachSeries.js +46 -0
  4. package/_internal/objectForEachSeries.js +44 -0
  5. package/_internal/series.js +4 -0
  6. package/dist/Transducer.es.js +1 -1
  7. package/dist/Transducer.es.min.js +1 -1
  8. package/dist/Transducer.js +1 -1
  9. package/dist/Transducer.min.js +1 -1
  10. package/dist/Transducer.mjs +1 -1
  11. package/dist/__.es.js +1 -1
  12. package/dist/__.es.min.js +1 -1
  13. package/dist/__.js +1 -1
  14. package/dist/__.min.js +1 -1
  15. package/dist/__.mjs +1 -1
  16. package/dist/all.es.js +1 -1
  17. package/dist/all.es.min.js +1 -1
  18. package/dist/all.js +1 -1
  19. package/dist/all.min.js +1 -1
  20. package/dist/all.mjs +1 -1
  21. package/dist/always.es.js +1 -1
  22. package/dist/always.es.min.js +1 -1
  23. package/dist/always.js +1 -1
  24. package/dist/always.min.js +1 -1
  25. package/dist/always.mjs +1 -1
  26. package/dist/and.es.js +1 -1
  27. package/dist/and.es.min.js +1 -1
  28. package/dist/and.js +1 -1
  29. package/dist/and.min.js +1 -1
  30. package/dist/and.mjs +1 -1
  31. package/dist/assign.es.js +1 -1
  32. package/dist/assign.es.min.js +1 -1
  33. package/dist/assign.js +1 -1
  34. package/dist/assign.min.js +1 -1
  35. package/dist/assign.mjs +1 -1
  36. package/dist/compose.es.js +1 -1
  37. package/dist/compose.es.min.js +1 -1
  38. package/dist/compose.js +1 -1
  39. package/dist/compose.min.js +1 -1
  40. package/dist/compose.mjs +1 -1
  41. package/dist/curry.es.js +1 -1
  42. package/dist/curry.es.min.js +1 -1
  43. package/dist/curry.js +1 -1
  44. package/dist/curry.min.js +1 -1
  45. package/dist/curry.mjs +1 -1
  46. package/dist/eq.es.js +1 -1
  47. package/dist/eq.es.min.js +1 -1
  48. package/dist/eq.js +1 -1
  49. package/dist/eq.min.js +1 -1
  50. package/dist/eq.mjs +1 -1
  51. package/dist/every.es.js +1 -1
  52. package/dist/every.es.min.js +1 -1
  53. package/dist/every.js +1 -1
  54. package/dist/every.min.js +1 -1
  55. package/dist/every.mjs +1 -1
  56. package/dist/filter.es.js +1 -1
  57. package/dist/filter.es.min.js +1 -1
  58. package/dist/filter.js +1 -1
  59. package/dist/filter.min.js +1 -1
  60. package/dist/filter.mjs +1 -1
  61. package/dist/flatMap.es.js +1 -1
  62. package/dist/flatMap.es.min.js +1 -1
  63. package/dist/flatMap.js +1 -1
  64. package/dist/flatMap.min.js +1 -1
  65. package/dist/flatMap.mjs +1 -1
  66. package/dist/forEach.es.js +140 -9
  67. package/dist/forEach.es.min.js +2 -2
  68. package/dist/forEach.js +140 -9
  69. package/dist/forEach.min.js +2 -2
  70. package/dist/forEach.mjs +140 -9
  71. package/dist/get.es.js +1 -1
  72. package/dist/get.es.min.js +1 -1
  73. package/dist/get.js +1 -1
  74. package/dist/get.min.js +1 -1
  75. package/dist/get.mjs +1 -1
  76. package/dist/gt.es.js +1 -1
  77. package/dist/gt.es.min.js +1 -1
  78. package/dist/gt.js +1 -1
  79. package/dist/gt.min.js +1 -1
  80. package/dist/gt.mjs +1 -1
  81. package/dist/gte.es.js +1 -1
  82. package/dist/gte.es.min.js +1 -1
  83. package/dist/gte.js +1 -1
  84. package/dist/gte.min.js +1 -1
  85. package/dist/gte.mjs +1 -1
  86. package/dist/lt.es.js +1 -1
  87. package/dist/lt.es.min.js +1 -1
  88. package/dist/lt.js +1 -1
  89. package/dist/lt.min.js +1 -1
  90. package/dist/lt.mjs +1 -1
  91. package/dist/lte.es.js +1 -1
  92. package/dist/lte.es.min.js +1 -1
  93. package/dist/lte.js +1 -1
  94. package/dist/lte.min.js +1 -1
  95. package/dist/lte.mjs +1 -1
  96. package/dist/map.es.js +1 -1
  97. package/dist/map.es.min.js +1 -1
  98. package/dist/map.js +1 -1
  99. package/dist/map.min.js +1 -1
  100. package/dist/map.mjs +1 -1
  101. package/dist/not.es.js +1 -1
  102. package/dist/not.es.min.js +1 -1
  103. package/dist/not.js +1 -1
  104. package/dist/not.min.js +1 -1
  105. package/dist/not.mjs +1 -1
  106. package/dist/omit.es.js +1 -1
  107. package/dist/omit.es.min.js +1 -1
  108. package/dist/omit.js +1 -1
  109. package/dist/omit.min.js +1 -1
  110. package/dist/omit.mjs +1 -1
  111. package/dist/or.es.js +1 -1
  112. package/dist/or.es.min.js +1 -1
  113. package/dist/or.js +1 -1
  114. package/dist/or.min.js +1 -1
  115. package/dist/or.mjs +1 -1
  116. package/dist/pick.es.js +1 -1
  117. package/dist/pick.es.min.js +1 -1
  118. package/dist/pick.js +1 -1
  119. package/dist/pick.min.js +1 -1
  120. package/dist/pick.mjs +1 -1
  121. package/dist/pipe.es.js +1 -1
  122. package/dist/pipe.es.min.js +1 -1
  123. package/dist/pipe.js +1 -1
  124. package/dist/pipe.min.js +1 -1
  125. package/dist/pipe.mjs +1 -1
  126. package/dist/reduce.es.js +1 -1
  127. package/dist/reduce.es.min.js +1 -1
  128. package/dist/reduce.js +1 -1
  129. package/dist/reduce.min.js +1 -1
  130. package/dist/reduce.mjs +1 -1
  131. package/dist/rubico.es.js +132 -9
  132. package/dist/rubico.es.min.js +2 -2
  133. package/dist/rubico.global.js +132 -9
  134. package/dist/rubico.global.min.js +2 -2
  135. package/dist/rubico.js +132 -9
  136. package/dist/rubico.min.js +2 -2
  137. package/dist/rubico.mjs +132 -9
  138. package/dist/set.es.js +1 -1
  139. package/dist/set.es.min.js +1 -1
  140. package/dist/set.js +1 -1
  141. package/dist/set.min.js +1 -1
  142. package/dist/set.mjs +1 -1
  143. package/dist/some.es.js +1 -1
  144. package/dist/some.es.min.js +1 -1
  145. package/dist/some.js +1 -1
  146. package/dist/some.min.js +1 -1
  147. package/dist/some.mjs +1 -1
  148. package/dist/switchCase.es.js +1 -1
  149. package/dist/switchCase.es.min.js +1 -1
  150. package/dist/switchCase.js +1 -1
  151. package/dist/switchCase.min.js +1 -1
  152. package/dist/switchCase.mjs +1 -1
  153. package/dist/tap.es.js +1 -1
  154. package/dist/tap.es.min.js +1 -1
  155. package/dist/tap.js +1 -1
  156. package/dist/tap.min.js +1 -1
  157. package/dist/tap.mjs +1 -1
  158. package/dist/thunkify.es.js +1 -1
  159. package/dist/thunkify.es.min.js +1 -1
  160. package/dist/thunkify.js +1 -1
  161. package/dist/thunkify.min.js +1 -1
  162. package/dist/thunkify.mjs +1 -1
  163. package/dist/transform.es.js +1 -1
  164. package/dist/transform.es.min.js +1 -1
  165. package/dist/transform.js +1 -1
  166. package/dist/transform.min.js +1 -1
  167. package/dist/transform.mjs +1 -1
  168. package/dist/tryCatch.es.js +1 -1
  169. package/dist/tryCatch.es.min.js +1 -1
  170. package/dist/tryCatch.js +1 -1
  171. package/dist/tryCatch.min.js +1 -1
  172. package/dist/tryCatch.mjs +1 -1
  173. package/dist/x/append.es.js +1 -1
  174. package/dist/x/append.es.min.js +1 -1
  175. package/dist/x/append.js +1 -1
  176. package/dist/x/append.min.js +1 -1
  177. package/dist/x/append.mjs +1 -1
  178. package/dist/x/callProp.es.js +1 -1
  179. package/dist/x/callProp.es.min.js +1 -1
  180. package/dist/x/callProp.js +1 -1
  181. package/dist/x/callProp.min.js +1 -1
  182. package/dist/x/callProp.mjs +1 -1
  183. package/dist/x/defaultsDeep.es.js +1 -1
  184. package/dist/x/defaultsDeep.es.min.js +1 -1
  185. package/dist/x/defaultsDeep.js +1 -1
  186. package/dist/x/defaultsDeep.min.js +1 -1
  187. package/dist/x/defaultsDeep.mjs +1 -1
  188. package/dist/x/differenceWith.es.js +1 -1
  189. package/dist/x/differenceWith.es.min.js +1 -1
  190. package/dist/x/differenceWith.js +1 -1
  191. package/dist/x/differenceWith.min.js +1 -1
  192. package/dist/x/differenceWith.mjs +1 -1
  193. package/dist/x/filterOut.es.js +1 -1
  194. package/dist/x/filterOut.es.min.js +1 -1
  195. package/dist/x/filterOut.js +1 -1
  196. package/dist/x/filterOut.min.js +1 -1
  197. package/dist/x/filterOut.mjs +1 -1
  198. package/dist/x/find.es.js +1 -1
  199. package/dist/x/find.es.min.js +1 -1
  200. package/dist/x/find.js +1 -1
  201. package/dist/x/find.min.js +1 -1
  202. package/dist/x/find.mjs +1 -1
  203. package/dist/x/findIndex.es.js +1 -1
  204. package/dist/x/findIndex.es.min.js +1 -1
  205. package/dist/x/findIndex.js +1 -1
  206. package/dist/x/findIndex.min.js +1 -1
  207. package/dist/x/findIndex.mjs +1 -1
  208. package/dist/x/first.es.js +1 -1
  209. package/dist/x/first.es.min.js +1 -1
  210. package/dist/x/first.js +1 -1
  211. package/dist/x/first.min.js +1 -1
  212. package/dist/x/first.mjs +1 -1
  213. package/dist/x/flatten.es.js +1 -1
  214. package/dist/x/flatten.es.min.js +1 -1
  215. package/dist/x/flatten.js +1 -1
  216. package/dist/x/flatten.min.js +1 -1
  217. package/dist/x/flatten.mjs +1 -1
  218. package/dist/x/groupBy.es.js +1 -1
  219. package/dist/x/groupBy.es.min.js +1 -1
  220. package/dist/x/groupBy.js +1 -1
  221. package/dist/x/groupBy.min.js +1 -1
  222. package/dist/x/groupBy.mjs +1 -1
  223. package/dist/x/has.es.js +1 -1
  224. package/dist/x/has.es.min.js +1 -1
  225. package/dist/x/has.js +1 -1
  226. package/dist/x/has.min.js +1 -1
  227. package/dist/x/has.mjs +1 -1
  228. package/dist/x/identity.es.js +1 -1
  229. package/dist/x/identity.es.min.js +1 -1
  230. package/dist/x/identity.js +1 -1
  231. package/dist/x/identity.min.js +1 -1
  232. package/dist/x/identity.mjs +1 -1
  233. package/dist/x/includes.es.js +1 -1
  234. package/dist/x/includes.es.min.js +1 -1
  235. package/dist/x/includes.js +1 -1
  236. package/dist/x/includes.min.js +1 -1
  237. package/dist/x/includes.mjs +1 -1
  238. package/dist/x/isDeepEqual.es.js +1 -1
  239. package/dist/x/isDeepEqual.es.min.js +1 -1
  240. package/dist/x/isDeepEqual.js +1 -1
  241. package/dist/x/isDeepEqual.min.js +1 -1
  242. package/dist/x/isDeepEqual.mjs +1 -1
  243. package/dist/x/isEmpty.es.js +1 -1
  244. package/dist/x/isEmpty.es.min.js +1 -1
  245. package/dist/x/isEmpty.js +1 -1
  246. package/dist/x/isEmpty.min.js +1 -1
  247. package/dist/x/isEmpty.mjs +1 -1
  248. package/dist/x/isEqual.es.js +1 -1
  249. package/dist/x/isEqual.es.min.js +1 -1
  250. package/dist/x/isEqual.js +1 -1
  251. package/dist/x/isEqual.min.js +1 -1
  252. package/dist/x/isEqual.mjs +1 -1
  253. package/dist/x/isFunction.es.js +1 -1
  254. package/dist/x/isFunction.es.min.js +1 -1
  255. package/dist/x/isFunction.js +1 -1
  256. package/dist/x/isFunction.min.js +1 -1
  257. package/dist/x/isFunction.mjs +1 -1
  258. package/dist/x/isIn.es.js +1 -1
  259. package/dist/x/isIn.es.min.js +1 -1
  260. package/dist/x/isIn.js +1 -1
  261. package/dist/x/isIn.min.js +1 -1
  262. package/dist/x/isIn.mjs +1 -1
  263. package/dist/x/isObject.es.js +1 -1
  264. package/dist/x/isObject.es.min.js +1 -1
  265. package/dist/x/isObject.js +1 -1
  266. package/dist/x/isObject.min.js +1 -1
  267. package/dist/x/isObject.mjs +1 -1
  268. package/dist/x/isString.es.js +1 -1
  269. package/dist/x/isString.es.min.js +1 -1
  270. package/dist/x/isString.js +1 -1
  271. package/dist/x/isString.min.js +1 -1
  272. package/dist/x/isString.mjs +1 -1
  273. package/dist/x/keys.es.js +1 -1
  274. package/dist/x/keys.es.min.js +1 -1
  275. package/dist/x/keys.js +1 -1
  276. package/dist/x/keys.min.js +1 -1
  277. package/dist/x/keys.mjs +1 -1
  278. package/dist/x/last.es.js +1 -1
  279. package/dist/x/last.es.min.js +1 -1
  280. package/dist/x/last.js +1 -1
  281. package/dist/x/last.min.js +1 -1
  282. package/dist/x/last.mjs +1 -1
  283. package/dist/x/maxBy.es.js +1 -1
  284. package/dist/x/maxBy.es.min.js +1 -1
  285. package/dist/x/maxBy.js +1 -1
  286. package/dist/x/maxBy.min.js +1 -1
  287. package/dist/x/maxBy.mjs +1 -1
  288. package/dist/x/noop.es.js +1 -1
  289. package/dist/x/noop.es.min.js +1 -1
  290. package/dist/x/noop.js +1 -1
  291. package/dist/x/noop.min.js +1 -1
  292. package/dist/x/noop.mjs +1 -1
  293. package/dist/x/pluck.es.js +1 -1
  294. package/dist/x/pluck.es.min.js +1 -1
  295. package/dist/x/pluck.js +1 -1
  296. package/dist/x/pluck.min.js +1 -1
  297. package/dist/x/pluck.mjs +1 -1
  298. package/dist/x/prepend.es.js +1 -1
  299. package/dist/x/prepend.es.min.js +1 -1
  300. package/dist/x/prepend.js +1 -1
  301. package/dist/x/prepend.min.js +1 -1
  302. package/dist/x/prepend.mjs +1 -1
  303. package/dist/x/size.es.js +1 -1
  304. package/dist/x/size.es.min.js +1 -1
  305. package/dist/x/size.js +1 -1
  306. package/dist/x/size.min.js +1 -1
  307. package/dist/x/size.mjs +1 -1
  308. package/dist/x/trace.es.js +1 -1
  309. package/dist/x/trace.es.min.js +1 -1
  310. package/dist/x/trace.js +1 -1
  311. package/dist/x/trace.min.js +1 -1
  312. package/dist/x/trace.mjs +1 -1
  313. package/dist/x/unionWith.es.js +1 -1
  314. package/dist/x/unionWith.es.min.js +1 -1
  315. package/dist/x/unionWith.js +1 -1
  316. package/dist/x/unionWith.min.js +1 -1
  317. package/dist/x/unionWith.mjs +1 -1
  318. package/dist/x/uniq.es.js +1 -1
  319. package/dist/x/uniq.es.min.js +1 -1
  320. package/dist/x/uniq.js +1 -1
  321. package/dist/x/uniq.min.js +1 -1
  322. package/dist/x/uniq.mjs +1 -1
  323. package/dist/x/unless.es.js +1 -1
  324. package/dist/x/unless.es.min.js +1 -1
  325. package/dist/x/unless.js +1 -1
  326. package/dist/x/unless.min.js +1 -1
  327. package/dist/x/unless.mjs +1 -1
  328. package/dist/x/values.es.js +1 -1
  329. package/dist/x/values.es.min.js +1 -1
  330. package/dist/x/values.js +1 -1
  331. package/dist/x/values.min.js +1 -1
  332. package/dist/x/values.mjs +1 -1
  333. package/dist/x/when.es.js +1 -1
  334. package/dist/x/when.es.min.js +1 -1
  335. package/dist/x/when.js +1 -1
  336. package/dist/x/when.min.js +1 -1
  337. package/dist/x/when.mjs +1 -1
  338. package/es.js +132 -9
  339. package/forEach.js +73 -12
  340. package/index.js +132 -9
  341. package/package.json +1 -1
  342. package/tap.js +1 -1
package/dist/x/values.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.3.7
2
+ * rubico v2.4.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.
package/dist/x/when.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.3.7
2
+ * rubico v2.4.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.3.7
2
+ * rubico v2.4.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.
package/dist/x/when.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.3.7
2
+ * rubico v2.4.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.3.7
2
+ * rubico v2.4.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.
package/dist/x/when.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.3.7
2
+ * rubico v2.4.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.
package/es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.3.7
2
+ * rubico v2.4.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.
@@ -1902,6 +1902,103 @@ const iteratorForEach = function (iterator, callback) {
1902
1902
  return promises.length == 0 ? iterator : promiseAll(promises).then(always(iterator))
1903
1903
  }
1904
1904
 
1905
+ // _arrayForEachSeriesAsync(
1906
+ // array Array,
1907
+ // callback function,
1908
+ // index number
1909
+ // ) -> Promise<array>
1910
+ const _arrayForEachSeriesAsync = async function (array, callback, index) {
1911
+ const length = array.length
1912
+ while (++index < length) {
1913
+ const operation = callback(array[index])
1914
+ if (isPromise(operation)) {
1915
+ await operation
1916
+ }
1917
+ }
1918
+ return array
1919
+ }
1920
+
1921
+ const arrayForEachSeries = function (array, callback) {
1922
+ const length = array.length
1923
+ let index = -1
1924
+ while (++index < length) {
1925
+ const operation = callback(array[index])
1926
+ if (isPromise(operation)) {
1927
+ return operation
1928
+ .then(thunkify3(_arrayForEachSeriesAsync, array, callback, index))
1929
+ }
1930
+ }
1931
+ return array
1932
+ }
1933
+
1934
+ // _objectForEachSeriesAsync(
1935
+ // object Object,
1936
+ // callback function,
1937
+ // firstKey string
1938
+ // ) -> Promise<object>
1939
+ const _objectForEachSeriesAsync = async function (object, callback, firstKey) {
1940
+ for (const key in object) {
1941
+ if (key == firstKey) {
1942
+ continue
1943
+ }
1944
+ const operation = callback(object[key])
1945
+ if (isPromise(operation)) {
1946
+ await operation
1947
+ }
1948
+ }
1949
+ return object
1950
+ }
1951
+
1952
+ const objectForEachSeries = function (object, callback) {
1953
+ for (const key in object) {
1954
+ const operation = callback(object[key])
1955
+ if (isPromise(operation)) {
1956
+ return operation
1957
+ .then(thunkify3(_objectForEachSeriesAsync, object, callback, key))
1958
+ }
1959
+ }
1960
+ return object
1961
+ }
1962
+
1963
+ // _iteratorForEachSeriesAsync(
1964
+ // iterator Iterator,
1965
+ // callback function,
1966
+ // ) -> Promise<iterator>
1967
+ const _iteratorForEachSeriesAsync = async function (iterator, callback) {
1968
+ let iteration = iterator.next()
1969
+ while (!iteration.done) {
1970
+ const operation = callback(iteration.value)
1971
+ if (isPromise(operation)) {
1972
+ await operation
1973
+ }
1974
+ iteration = iterator.next()
1975
+ }
1976
+ return iterator
1977
+ }
1978
+
1979
+ const iteratorForEachSeries = function (iterator, callback) {
1980
+ let iteration = iterator.next()
1981
+ while (!iterator.done) {
1982
+ const operation = callback(iteration.value)
1983
+ if (isPromise(operation)) {
1984
+ return operation
1985
+ .then(thunkify2(_iteratorForEachSeriesAsync, iterator, callback))
1986
+ }
1987
+ iteration = iterator.next()
1988
+ }
1989
+ return iterator
1990
+ }
1991
+
1992
+ const asyncIteratorForEachSeries = async function (asyncIterator, callback) {
1993
+ for await (const item of asyncIterator) {
1994
+ const operation = callback(item)
1995
+ if (isPromise(operation)) {
1996
+ await operation
1997
+ }
1998
+ }
1999
+ return asyncIterator
2000
+ }
2001
+
1905
2002
  // type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
1906
2003
  // _forEach(collection Collection, callback function) -> collection Collection
1907
2004
  const _forEach = function (collection, callback) {
@@ -1926,15 +2023,41 @@ const _forEach = function (collection, callback) {
1926
2023
  return collection
1927
2024
  }
1928
2025
 
1929
- const forEach = function (...args) {
1930
- const callback = args.pop()
1931
- if (args.length == 0) {
1932
- return curry2(_forEach, __, callback)
2026
+ const forEach = function (arg0, arg1) {
2027
+ if (typeof arg0 == 'function') {
2028
+ return curry2(_forEach, __, arg0)
1933
2029
  }
1934
- const collection = args[0]
1935
- return isPromise(collection)
1936
- ? collection.then(curry2(_forEach, __, callback))
1937
- : _forEach(collection, callback)
2030
+ return isPromise(arg0)
2031
+ ? arg0.then(curry2(_forEach, __, arg1))
2032
+ : _forEach(arg0, arg1)
2033
+ }
2034
+
2035
+ const _forEachSeries = function (collection, callback) {
2036
+ if (isArray(collection)) {
2037
+ return arrayForEachSeries(collection, callback)
2038
+ }
2039
+ if (collection == null) {
2040
+ throw new Error(`invalid collection ${collection}`)
2041
+ }
2042
+ if (typeof collection[symbolIterator] == 'function') {
2043
+ return iteratorForEachSeries(collection[symbolIterator](), callback)
2044
+ }
2045
+ if (typeof collection[symbolAsyncIterator] == 'function') {
2046
+ return asyncIteratorForEachSeries(collection[symbolAsyncIterator](), callback)
2047
+ }
2048
+ if (collection.constructor == Object) {
2049
+ return objectForEachSeries(collection, callback)
2050
+ }
2051
+ throw new Error(`invalid collection ${collection}`)
2052
+ }
2053
+
2054
+ forEach.series = function forEachSeries(arg0, arg1) {
2055
+ if (typeof arg0 == 'function') {
2056
+ return curry2(_forEachSeries, __, arg0)
2057
+ }
2058
+ return isPromise(arg0)
2059
+ ? arg0.then(curry2(_forEachSeries, __, arg1))
2060
+ : _forEachSeries(arg0, arg1)
1938
2061
  }
1939
2062
 
1940
2063
  const SelfReferencingPromise = function (basePromise) {
package/forEach.js CHANGED
@@ -10,6 +10,10 @@ const iteratorForEach = require('./_internal/iteratorForEach')
10
10
  const asyncIteratorForEach = require('./_internal/asyncIteratorForEach')
11
11
  const symbolIterator = require('./_internal/symbolIterator')
12
12
  const symbolAsyncIterator = require('./_internal/symbolAsyncIterator')
13
+ const arrayForEachSeries = require('./_internal/arrayForEachSeries')
14
+ const objectForEachSeries = require('./_internal/objectForEachSeries')
15
+ const iteratorForEachSeries = require('./_internal/iteratorForEachSeries')
16
+ const asyncIteratorForEachSeries = require('./_internal/asyncIteratorForEachSeries')
13
17
 
14
18
  // type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
15
19
  // _forEach(collection Collection, callback function) -> collection Collection
@@ -42,16 +46,16 @@ const _forEach = function (collection, callback) {
42
46
  * ```coffeescript [specscript]
43
47
  * type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
44
48
  *
45
- * forEach(collection Collection, callback function) -> collection Collection
49
+ * forEach(collection Collection, callback function) -> collection Promise|Collection
46
50
  *
47
- * forEach(callback function)(collection Collection) -> collection Collection
51
+ * forEach(callback function)(collection Collection) -> collection Promise|Collection
48
52
  * ```
49
53
  *
50
54
  * @description
51
- * Execute a callback for each item of a collection, returning a Promise if the execution is asynchronous.
55
+ * Execute a callback for each item of a collection, returning a Promise if the execution is asynchronous. Asynchronous execution happens concurrently.
52
56
  *
53
57
  * ```javascript [playground]
54
- * forEach([1, 2, 3, 4, 5l], console.log) // 1 2 3 4 5
58
+ * forEach([1, 2, 3, 4, 5], console.log) // 1 2 3 4 5
55
59
  *
56
60
  * forEach({ a: 1, b: 2, c: 3 }, console.log) // 1 2 3
57
61
  * ```
@@ -68,15 +72,72 @@ const _forEach = function (collection, callback) {
68
72
  * ])
69
73
  * ```
70
74
  */
71
- const forEach = function (...args) {
72
- const callback = args.pop()
73
- if (args.length == 0) {
74
- return curry2(_forEach, __, callback)
75
+ const forEach = function (arg0, arg1) {
76
+ if (typeof arg0 == 'function') {
77
+ return curry2(_forEach, __, arg0)
75
78
  }
76
- const collection = args[0]
77
- return isPromise(collection)
78
- ? collection.then(curry2(_forEach, __, callback))
79
- : _forEach(collection, callback)
79
+ return isPromise(arg0)
80
+ ? arg0.then(curry2(_forEach, __, arg1))
81
+ : _forEach(arg0, arg1)
82
+ }
83
+
84
+ /**
85
+ * @name _forEachSeries
86
+ *
87
+ * @synopsis
88
+ * ```coffeescript [specscript]
89
+ * type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
90
+ *
91
+ * _forEachSeries(collection Collection, callback function) -> collection Promise|Collection
92
+ * ```
93
+ */
94
+ const _forEachSeries = function (collection, callback) {
95
+ if (isArray(collection)) {
96
+ return arrayForEachSeries(collection, callback)
97
+ }
98
+ if (collection == null) {
99
+ throw new Error(`invalid collection ${collection}`)
100
+ }
101
+ if (typeof collection[symbolIterator] == 'function') {
102
+ return iteratorForEachSeries(collection[symbolIterator](), callback)
103
+ }
104
+ if (typeof collection[symbolAsyncIterator] == 'function') {
105
+ return asyncIteratorForEachSeries(collection[symbolAsyncIterator](), callback)
106
+ }
107
+ if (collection.constructor == Object) {
108
+ return objectForEachSeries(collection, callback)
109
+ }
110
+ throw new Error(`invalid collection ${collection}`)
111
+ }
112
+
113
+ /**
114
+ * @name forEach.series
115
+ *
116
+ * @synopsis
117
+ * ```coffeescript [specscript]
118
+ * type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
119
+ *
120
+ * forEach.series(collection Collection, callback function) -> collection Promise|Collection
121
+ *
122
+ * forEach.series(callback function)(collection Collection) -> collection Promise|Collection
123
+ * ```
124
+ *
125
+ * @description
126
+ * Execute a callback for each item of a collection, returning a Promise if the execution is asynchronous. Asynchronous execution happens in series.
127
+ *
128
+ * ```javascript [playground]
129
+ * forEach.series([1, 2, 3, 4, 5], console.log) // 1 2 3 4 5
130
+ *
131
+ * forEach.series({ a: 1, b: 2, c: 3 }, console.log) // 1 2 3
132
+ * ```
133
+ */
134
+ forEach.series = function forEachSeries(arg0, arg1) {
135
+ if (typeof arg0 == 'function') {
136
+ return curry2(_forEachSeries, __, arg0)
137
+ }
138
+ return isPromise(arg0)
139
+ ? arg0.then(curry2(_forEachSeries, __, arg1))
140
+ : _forEachSeries(arg0, arg1)
80
141
  }
81
142
 
82
143
  module.exports = forEach
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.3.7
2
+ * rubico v2.4.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.
@@ -1908,6 +1908,103 @@ const iteratorForEach = function (iterator, callback) {
1908
1908
  return promises.length == 0 ? iterator : promiseAll(promises).then(always(iterator))
1909
1909
  }
1910
1910
 
1911
+ // _arrayForEachSeriesAsync(
1912
+ // array Array,
1913
+ // callback function,
1914
+ // index number
1915
+ // ) -> Promise<array>
1916
+ const _arrayForEachSeriesAsync = async function (array, callback, index) {
1917
+ const length = array.length
1918
+ while (++index < length) {
1919
+ const operation = callback(array[index])
1920
+ if (isPromise(operation)) {
1921
+ await operation
1922
+ }
1923
+ }
1924
+ return array
1925
+ }
1926
+
1927
+ const arrayForEachSeries = function (array, callback) {
1928
+ const length = array.length
1929
+ let index = -1
1930
+ while (++index < length) {
1931
+ const operation = callback(array[index])
1932
+ if (isPromise(operation)) {
1933
+ return operation
1934
+ .then(thunkify3(_arrayForEachSeriesAsync, array, callback, index))
1935
+ }
1936
+ }
1937
+ return array
1938
+ }
1939
+
1940
+ // _objectForEachSeriesAsync(
1941
+ // object Object,
1942
+ // callback function,
1943
+ // firstKey string
1944
+ // ) -> Promise<object>
1945
+ const _objectForEachSeriesAsync = async function (object, callback, firstKey) {
1946
+ for (const key in object) {
1947
+ if (key == firstKey) {
1948
+ continue
1949
+ }
1950
+ const operation = callback(object[key])
1951
+ if (isPromise(operation)) {
1952
+ await operation
1953
+ }
1954
+ }
1955
+ return object
1956
+ }
1957
+
1958
+ const objectForEachSeries = function (object, callback) {
1959
+ for (const key in object) {
1960
+ const operation = callback(object[key])
1961
+ if (isPromise(operation)) {
1962
+ return operation
1963
+ .then(thunkify3(_objectForEachSeriesAsync, object, callback, key))
1964
+ }
1965
+ }
1966
+ return object
1967
+ }
1968
+
1969
+ // _iteratorForEachSeriesAsync(
1970
+ // iterator Iterator,
1971
+ // callback function,
1972
+ // ) -> Promise<iterator>
1973
+ const _iteratorForEachSeriesAsync = async function (iterator, callback) {
1974
+ let iteration = iterator.next()
1975
+ while (!iteration.done) {
1976
+ const operation = callback(iteration.value)
1977
+ if (isPromise(operation)) {
1978
+ await operation
1979
+ }
1980
+ iteration = iterator.next()
1981
+ }
1982
+ return iterator
1983
+ }
1984
+
1985
+ const iteratorForEachSeries = function (iterator, callback) {
1986
+ let iteration = iterator.next()
1987
+ while (!iterator.done) {
1988
+ const operation = callback(iteration.value)
1989
+ if (isPromise(operation)) {
1990
+ return operation
1991
+ .then(thunkify2(_iteratorForEachSeriesAsync, iterator, callback))
1992
+ }
1993
+ iteration = iterator.next()
1994
+ }
1995
+ return iterator
1996
+ }
1997
+
1998
+ const asyncIteratorForEachSeries = async function (asyncIterator, callback) {
1999
+ for await (const item of asyncIterator) {
2000
+ const operation = callback(item)
2001
+ if (isPromise(operation)) {
2002
+ await operation
2003
+ }
2004
+ }
2005
+ return asyncIterator
2006
+ }
2007
+
1911
2008
  // type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
1912
2009
  // _forEach(collection Collection, callback function) -> collection Collection
1913
2010
  const _forEach = function (collection, callback) {
@@ -1932,15 +2029,41 @@ const _forEach = function (collection, callback) {
1932
2029
  return collection
1933
2030
  }
1934
2031
 
1935
- const forEach = function (...args) {
1936
- const callback = args.pop()
1937
- if (args.length == 0) {
1938
- return curry2(_forEach, __, callback)
2032
+ const forEach = function (arg0, arg1) {
2033
+ if (typeof arg0 == 'function') {
2034
+ return curry2(_forEach, __, arg0)
1939
2035
  }
1940
- const collection = args[0]
1941
- return isPromise(collection)
1942
- ? collection.then(curry2(_forEach, __, callback))
1943
- : _forEach(collection, callback)
2036
+ return isPromise(arg0)
2037
+ ? arg0.then(curry2(_forEach, __, arg1))
2038
+ : _forEach(arg0, arg1)
2039
+ }
2040
+
2041
+ const _forEachSeries = function (collection, callback) {
2042
+ if (isArray(collection)) {
2043
+ return arrayForEachSeries(collection, callback)
2044
+ }
2045
+ if (collection == null) {
2046
+ throw new Error(`invalid collection ${collection}`)
2047
+ }
2048
+ if (typeof collection[symbolIterator] == 'function') {
2049
+ return iteratorForEachSeries(collection[symbolIterator](), callback)
2050
+ }
2051
+ if (typeof collection[symbolAsyncIterator] == 'function') {
2052
+ return asyncIteratorForEachSeries(collection[symbolAsyncIterator](), callback)
2053
+ }
2054
+ if (collection.constructor == Object) {
2055
+ return objectForEachSeries(collection, callback)
2056
+ }
2057
+ throw new Error(`invalid collection ${collection}`)
2058
+ }
2059
+
2060
+ forEach.series = function forEachSeries(arg0, arg1) {
2061
+ if (typeof arg0 == 'function') {
2062
+ return curry2(_forEachSeries, __, arg0)
2063
+ }
2064
+ return isPromise(arg0)
2065
+ ? arg0.then(curry2(_forEachSeries, __, arg1))
2066
+ : _forEachSeries(arg0, arg1)
1944
2067
  }
1945
2068
 
1946
2069
  const SelfReferencingPromise = function (basePromise) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubico",
3
- "version": "2.3.7",
3
+ "version": "2.4.0",
4
4
  "description": "[a]synchronous functional programming",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
package/tap.js CHANGED
@@ -23,7 +23,7 @@ const _tap = function (args, func) {
23
23
  * ```
24
24
  *
25
25
  * @description
26
- * Call a function with any number of arguments, returning the first argument. Promises created by the tapper are resolved before returning the value.
26
+ * Call a function with provided arguments, returning the first argument. The return value of the function call is discarded.
27
27
  *
28
28
  * ```javascript [playground]
29
29
  * const pipeline = pipe([