rubico 2.6.5 → 2.7.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 (382) hide show
  1. package/Transducer.d.ts +1 -1
  2. package/Transducer.js +65 -16
  3. package/__.js +10 -1
  4. package/all.d.ts +2 -2
  5. package/all.js +11 -2
  6. package/always.js +8 -0
  7. package/and.js +6 -0
  8. package/assign.js +9 -0
  9. package/compose.js +33 -8
  10. package/curry.js +18 -0
  11. package/dist/Transducer.es.js +2 -2
  12. package/dist/Transducer.es.min.js +2 -2
  13. package/dist/Transducer.js +2 -2
  14. package/dist/Transducer.min.js +2 -2
  15. package/dist/Transducer.mjs +2 -2
  16. package/dist/__.es.js +2 -2
  17. package/dist/__.es.min.js +2 -2
  18. package/dist/__.js +2 -2
  19. package/dist/__.min.js +2 -2
  20. package/dist/__.mjs +2 -2
  21. package/dist/all.es.js +2 -22
  22. package/dist/all.es.min.js +2 -2
  23. package/dist/all.js +2 -22
  24. package/dist/all.min.js +2 -2
  25. package/dist/all.mjs +2 -22
  26. package/dist/always.es.js +2 -2
  27. package/dist/always.es.min.js +2 -2
  28. package/dist/always.js +2 -2
  29. package/dist/always.min.js +2 -2
  30. package/dist/always.mjs +2 -2
  31. package/dist/and.es.js +2 -2
  32. package/dist/and.es.min.js +2 -2
  33. package/dist/and.js +2 -2
  34. package/dist/and.min.js +2 -2
  35. package/dist/and.mjs +2 -2
  36. package/dist/assign.es.js +2 -2
  37. package/dist/assign.es.min.js +2 -2
  38. package/dist/assign.js +2 -2
  39. package/dist/assign.min.js +2 -2
  40. package/dist/assign.mjs +2 -2
  41. package/dist/compose.es.js +6 -2
  42. package/dist/compose.es.min.js +3 -3
  43. package/dist/compose.js +6 -2
  44. package/dist/compose.min.js +3 -3
  45. package/dist/compose.mjs +6 -2
  46. package/dist/curry.es.js +2 -2
  47. package/dist/curry.es.min.js +2 -2
  48. package/dist/curry.js +2 -2
  49. package/dist/curry.min.js +2 -2
  50. package/dist/curry.mjs +2 -2
  51. package/dist/eq.es.js +2 -2
  52. package/dist/eq.es.min.js +2 -2
  53. package/dist/eq.js +2 -2
  54. package/dist/eq.min.js +2 -2
  55. package/dist/eq.mjs +2 -2
  56. package/dist/every.es.js +2 -2
  57. package/dist/every.es.min.js +2 -2
  58. package/dist/every.js +2 -2
  59. package/dist/every.min.js +2 -2
  60. package/dist/every.mjs +2 -2
  61. package/dist/filter.es.js +5 -3
  62. package/dist/filter.es.min.js +3 -3
  63. package/dist/filter.js +5 -3
  64. package/dist/filter.min.js +3 -3
  65. package/dist/filter.mjs +5 -3
  66. package/dist/flatMap.es.js +2 -2
  67. package/dist/flatMap.es.min.js +2 -2
  68. package/dist/flatMap.js +2 -2
  69. package/dist/flatMap.min.js +2 -2
  70. package/dist/flatMap.mjs +2 -2
  71. package/dist/forEach.es.js +2 -2
  72. package/dist/forEach.es.min.js +2 -2
  73. package/dist/forEach.js +2 -2
  74. package/dist/forEach.min.js +2 -2
  75. package/dist/forEach.mjs +2 -2
  76. package/dist/get.es.js +2 -2
  77. package/dist/get.es.min.js +2 -2
  78. package/dist/get.js +2 -2
  79. package/dist/get.min.js +2 -2
  80. package/dist/get.mjs +2 -2
  81. package/dist/gt.es.js +2 -2
  82. package/dist/gt.es.min.js +2 -2
  83. package/dist/gt.js +2 -2
  84. package/dist/gt.min.js +2 -2
  85. package/dist/gt.mjs +2 -2
  86. package/dist/gte.es.js +2 -2
  87. package/dist/gte.es.min.js +2 -2
  88. package/dist/gte.js +2 -2
  89. package/dist/gte.min.js +2 -2
  90. package/dist/gte.mjs +2 -2
  91. package/dist/lt.es.js +2 -2
  92. package/dist/lt.es.min.js +2 -2
  93. package/dist/lt.js +2 -2
  94. package/dist/lt.min.js +2 -2
  95. package/dist/lt.mjs +2 -2
  96. package/dist/lte.es.js +2 -2
  97. package/dist/lte.es.min.js +2 -2
  98. package/dist/lte.js +2 -2
  99. package/dist/lte.min.js +2 -2
  100. package/dist/lte.mjs +2 -2
  101. package/dist/map.es.js +31 -31
  102. package/dist/map.es.min.js +3 -3
  103. package/dist/map.js +31 -31
  104. package/dist/map.min.js +3 -3
  105. package/dist/map.mjs +31 -31
  106. package/dist/not.es.js +2 -2
  107. package/dist/not.es.min.js +2 -2
  108. package/dist/not.js +2 -2
  109. package/dist/not.min.js +2 -2
  110. package/dist/not.mjs +2 -2
  111. package/dist/omit.es.js +2 -2
  112. package/dist/omit.es.min.js +2 -2
  113. package/dist/omit.js +2 -2
  114. package/dist/omit.min.js +2 -2
  115. package/dist/omit.mjs +2 -2
  116. package/dist/or.es.js +2 -2
  117. package/dist/or.es.min.js +2 -2
  118. package/dist/or.js +2 -2
  119. package/dist/or.min.js +2 -2
  120. package/dist/or.mjs +2 -2
  121. package/dist/pick.es.js +2 -2
  122. package/dist/pick.es.min.js +2 -2
  123. package/dist/pick.js +2 -2
  124. package/dist/pick.min.js +2 -2
  125. package/dist/pick.mjs +2 -2
  126. package/dist/pipe.es.js +6 -2
  127. package/dist/pipe.es.min.js +3 -3
  128. package/dist/pipe.js +6 -2
  129. package/dist/pipe.min.js +3 -3
  130. package/dist/pipe.mjs +6 -2
  131. package/dist/reduce.es.js +9 -9
  132. package/dist/reduce.es.min.js +2 -2
  133. package/dist/reduce.js +9 -9
  134. package/dist/reduce.min.js +2 -2
  135. package/dist/reduce.mjs +9 -9
  136. package/dist/rubico.es.js +49 -59
  137. package/dist/rubico.es.min.js +3 -3
  138. package/dist/rubico.global.js +49 -59
  139. package/dist/rubico.global.min.js +3 -3
  140. package/dist/rubico.js +49 -59
  141. package/dist/rubico.min.js +3 -3
  142. package/dist/rubico.mjs +49 -59
  143. package/dist/set.es.js +2 -2
  144. package/dist/set.es.min.js +2 -2
  145. package/dist/set.js +2 -2
  146. package/dist/set.min.js +2 -2
  147. package/dist/set.mjs +2 -2
  148. package/dist/some.es.js +2 -2
  149. package/dist/some.es.min.js +2 -2
  150. package/dist/some.js +2 -2
  151. package/dist/some.min.js +2 -2
  152. package/dist/some.mjs +2 -2
  153. package/dist/switchCase.es.js +2 -2
  154. package/dist/switchCase.es.min.js +2 -2
  155. package/dist/switchCase.js +2 -2
  156. package/dist/switchCase.min.js +2 -2
  157. package/dist/switchCase.mjs +2 -2
  158. package/dist/tap.es.js +2 -2
  159. package/dist/tap.es.min.js +2 -2
  160. package/dist/tap.js +2 -2
  161. package/dist/tap.min.js +2 -2
  162. package/dist/tap.mjs +2 -2
  163. package/dist/thunkify.es.js +2 -2
  164. package/dist/thunkify.es.min.js +2 -2
  165. package/dist/thunkify.js +2 -2
  166. package/dist/thunkify.min.js +2 -2
  167. package/dist/thunkify.mjs +2 -2
  168. package/dist/transform.es.js +2 -2
  169. package/dist/transform.es.min.js +2 -2
  170. package/dist/transform.js +2 -2
  171. package/dist/transform.min.js +2 -2
  172. package/dist/transform.mjs +2 -2
  173. package/dist/tryCatch.es.js +2 -2
  174. package/dist/tryCatch.es.min.js +2 -2
  175. package/dist/tryCatch.js +2 -2
  176. package/dist/tryCatch.min.js +2 -2
  177. package/dist/tryCatch.mjs +2 -2
  178. package/dist/x/append.es.js +2 -2
  179. package/dist/x/append.es.min.js +2 -2
  180. package/dist/x/append.js +2 -2
  181. package/dist/x/append.min.js +2 -2
  182. package/dist/x/append.mjs +2 -2
  183. package/dist/x/callProp.es.js +2 -2
  184. package/dist/x/callProp.es.min.js +2 -2
  185. package/dist/x/callProp.js +2 -2
  186. package/dist/x/callProp.min.js +2 -2
  187. package/dist/x/callProp.mjs +2 -2
  188. package/dist/x/defaultsDeep.es.js +2 -2
  189. package/dist/x/defaultsDeep.es.min.js +2 -2
  190. package/dist/x/defaultsDeep.js +2 -2
  191. package/dist/x/defaultsDeep.min.js +2 -2
  192. package/dist/x/defaultsDeep.mjs +2 -2
  193. package/dist/x/differenceWith.es.js +2 -2
  194. package/dist/x/differenceWith.es.min.js +2 -2
  195. package/dist/x/differenceWith.js +2 -2
  196. package/dist/x/differenceWith.min.js +2 -2
  197. package/dist/x/differenceWith.mjs +2 -2
  198. package/dist/x/filterOut.es.js +5 -3
  199. package/dist/x/filterOut.es.min.js +3 -3
  200. package/dist/x/filterOut.js +5 -3
  201. package/dist/x/filterOut.min.js +3 -3
  202. package/dist/x/filterOut.mjs +5 -3
  203. package/dist/x/find.es.js +2 -2
  204. package/dist/x/find.es.min.js +2 -2
  205. package/dist/x/find.js +2 -2
  206. package/dist/x/find.min.js +2 -2
  207. package/dist/x/find.mjs +2 -2
  208. package/dist/x/findIndex.es.js +2 -2
  209. package/dist/x/findIndex.es.min.js +2 -2
  210. package/dist/x/findIndex.js +2 -2
  211. package/dist/x/findIndex.min.js +2 -2
  212. package/dist/x/findIndex.mjs +2 -2
  213. package/dist/x/first.es.js +2 -2
  214. package/dist/x/first.es.min.js +2 -2
  215. package/dist/x/first.js +2 -2
  216. package/dist/x/first.min.js +2 -2
  217. package/dist/x/first.mjs +2 -2
  218. package/dist/x/flatten.es.js +2 -2
  219. package/dist/x/flatten.es.min.js +2 -2
  220. package/dist/x/flatten.js +2 -2
  221. package/dist/x/flatten.min.js +2 -2
  222. package/dist/x/flatten.mjs +2 -2
  223. package/dist/x/groupBy.es.js +9 -9
  224. package/dist/x/groupBy.es.min.js +2 -2
  225. package/dist/x/groupBy.js +9 -9
  226. package/dist/x/groupBy.min.js +2 -2
  227. package/dist/x/groupBy.mjs +9 -9
  228. package/dist/x/has.es.js +2 -2
  229. package/dist/x/has.es.min.js +2 -2
  230. package/dist/x/has.js +2 -2
  231. package/dist/x/has.min.js +2 -2
  232. package/dist/x/has.mjs +2 -2
  233. package/dist/x/identity.es.js +2 -2
  234. package/dist/x/identity.es.min.js +2 -2
  235. package/dist/x/identity.js +2 -2
  236. package/dist/x/identity.min.js +2 -2
  237. package/dist/x/identity.mjs +2 -2
  238. package/dist/x/includes.es.js +2 -2
  239. package/dist/x/includes.es.min.js +2 -2
  240. package/dist/x/includes.js +2 -2
  241. package/dist/x/includes.min.js +2 -2
  242. package/dist/x/includes.mjs +2 -2
  243. package/dist/x/isDeepEqual.es.js +2 -2
  244. package/dist/x/isDeepEqual.es.min.js +2 -2
  245. package/dist/x/isDeepEqual.js +2 -2
  246. package/dist/x/isDeepEqual.min.js +2 -2
  247. package/dist/x/isDeepEqual.mjs +2 -2
  248. package/dist/x/isEmpty.es.js +2 -2
  249. package/dist/x/isEmpty.es.min.js +2 -2
  250. package/dist/x/isEmpty.js +2 -2
  251. package/dist/x/isEmpty.min.js +2 -2
  252. package/dist/x/isEmpty.mjs +2 -2
  253. package/dist/x/isEqual.es.js +2 -2
  254. package/dist/x/isEqual.es.min.js +2 -2
  255. package/dist/x/isEqual.js +2 -2
  256. package/dist/x/isEqual.min.js +2 -2
  257. package/dist/x/isEqual.mjs +2 -2
  258. package/dist/x/isFunction.es.js +2 -2
  259. package/dist/x/isFunction.es.min.js +2 -2
  260. package/dist/x/isFunction.js +2 -2
  261. package/dist/x/isFunction.min.js +2 -2
  262. package/dist/x/isFunction.mjs +2 -2
  263. package/dist/x/isIn.es.js +2 -2
  264. package/dist/x/isIn.es.min.js +2 -2
  265. package/dist/x/isIn.js +2 -2
  266. package/dist/x/isIn.min.js +2 -2
  267. package/dist/x/isIn.mjs +2 -2
  268. package/dist/x/isObject.es.js +2 -2
  269. package/dist/x/isObject.es.min.js +2 -2
  270. package/dist/x/isObject.js +2 -2
  271. package/dist/x/isObject.min.js +2 -2
  272. package/dist/x/isObject.mjs +2 -2
  273. package/dist/x/isString.es.js +2 -2
  274. package/dist/x/isString.es.min.js +2 -2
  275. package/dist/x/isString.js +2 -2
  276. package/dist/x/isString.min.js +2 -2
  277. package/dist/x/isString.mjs +2 -2
  278. package/dist/x/keys.es.js +2 -2
  279. package/dist/x/keys.es.min.js +2 -2
  280. package/dist/x/keys.js +2 -2
  281. package/dist/x/keys.min.js +2 -2
  282. package/dist/x/keys.mjs +2 -2
  283. package/dist/x/last.es.js +2 -2
  284. package/dist/x/last.es.min.js +2 -2
  285. package/dist/x/last.js +2 -2
  286. package/dist/x/last.min.js +2 -2
  287. package/dist/x/last.mjs +2 -2
  288. package/dist/x/maxBy.es.js +2 -2
  289. package/dist/x/maxBy.es.min.js +2 -2
  290. package/dist/x/maxBy.js +2 -2
  291. package/dist/x/maxBy.min.js +2 -2
  292. package/dist/x/maxBy.mjs +2 -2
  293. package/dist/x/noop.es.js +2 -2
  294. package/dist/x/noop.es.min.js +2 -2
  295. package/dist/x/noop.js +2 -2
  296. package/dist/x/noop.min.js +2 -2
  297. package/dist/x/noop.mjs +2 -2
  298. package/dist/x/pluck.es.js +31 -31
  299. package/dist/x/pluck.es.min.js +3 -3
  300. package/dist/x/pluck.js +31 -31
  301. package/dist/x/pluck.min.js +3 -3
  302. package/dist/x/pluck.mjs +31 -31
  303. package/dist/x/prepend.es.js +2 -2
  304. package/dist/x/prepend.es.min.js +2 -2
  305. package/dist/x/prepend.js +2 -2
  306. package/dist/x/prepend.min.js +2 -2
  307. package/dist/x/prepend.mjs +2 -2
  308. package/dist/x/size.es.js +2 -2
  309. package/dist/x/size.es.min.js +2 -2
  310. package/dist/x/size.js +2 -2
  311. package/dist/x/size.min.js +2 -2
  312. package/dist/x/size.mjs +2 -2
  313. package/dist/x/trace.es.js +2 -2
  314. package/dist/x/trace.es.min.js +2 -2
  315. package/dist/x/trace.js +2 -2
  316. package/dist/x/trace.min.js +2 -2
  317. package/dist/x/trace.mjs +2 -2
  318. package/dist/x/unionWith.es.js +2 -2
  319. package/dist/x/unionWith.es.min.js +2 -2
  320. package/dist/x/unionWith.js +2 -2
  321. package/dist/x/unionWith.min.js +2 -2
  322. package/dist/x/unionWith.mjs +2 -2
  323. package/dist/x/uniq.es.js +2 -2
  324. package/dist/x/uniq.es.min.js +2 -2
  325. package/dist/x/uniq.js +2 -2
  326. package/dist/x/uniq.min.js +2 -2
  327. package/dist/x/uniq.mjs +2 -2
  328. package/dist/x/unless.es.js +2 -2
  329. package/dist/x/unless.es.min.js +2 -2
  330. package/dist/x/unless.js +2 -2
  331. package/dist/x/unless.min.js +2 -2
  332. package/dist/x/unless.mjs +2 -2
  333. package/dist/x/values.es.js +2 -2
  334. package/dist/x/values.es.min.js +2 -2
  335. package/dist/x/values.js +2 -2
  336. package/dist/x/values.min.js +2 -2
  337. package/dist/x/values.mjs +2 -2
  338. package/dist/x/when.es.js +2 -2
  339. package/dist/x/when.es.min.js +2 -2
  340. package/dist/x/when.js +2 -2
  341. package/dist/x/when.min.js +2 -2
  342. package/dist/x/when.mjs +2 -2
  343. package/eq.d.ts +6 -6
  344. package/eq.js +14 -6
  345. package/es.js +49 -59
  346. package/every.js +19 -5
  347. package/filter.js +87 -47
  348. package/flatMap.js +38 -32
  349. package/forEach.js +107 -13
  350. package/get.js +9 -0
  351. package/gt.js +9 -0
  352. package/gte.js +9 -0
  353. package/index.js +49 -59
  354. package/lte.js +9 -0
  355. package/map.js +198 -103
  356. package/not.js +7 -0
  357. package/omit.d.ts +2 -2
  358. package/omit.js +11 -2
  359. package/or.js +6 -0
  360. package/package.json +1 -3
  361. package/pick.js +9 -0
  362. package/pipe.js +30 -3
  363. package/reduce.js +132 -89
  364. package/set.js +9 -0
  365. package/some.js +17 -3
  366. package/switchCase.js +6 -0
  367. package/tap.js +14 -0
  368. package/thunkify.js +8 -0
  369. package/transform.js +112 -44
  370. package/tryCatch.js +5 -0
  371. package/x/append.js +3 -0
  372. package/x/callProp.js +5 -0
  373. package/x/defaultsDeep.d.ts +2 -2
  374. package/x/defaultsDeep.js +7 -2
  375. package/x/differenceWith.js +5 -0
  376. package/x/find.d.ts +2 -2
  377. package/x/find.js +2 -2
  378. package/x/groupBy.d.ts +2 -2
  379. package/x/groupBy.js +2 -2
  380. package/x/pluck.d.ts +2 -2
  381. package/x/pluck.js +2 -2
  382. package/x/unionWith.test.js +3 -3
package/reduce.js CHANGED
@@ -3,17 +3,17 @@ const __ = require('./_internal/placeholder')
3
3
  const curry3 = require('./_internal/curry3')
4
4
  const genericReduce = require('./_internal/genericReduce')
5
5
 
6
- // _reduce(collection any, reducer function, initialValue function|any) -> Promise
7
- const _reduce = function (collection, reducer, initialValue) {
8
- if (typeof initialValue == 'function') {
9
- const actualInitialValue = initialValue(collection)
6
+ // _reduce(collection any, reducer function, initial function|any) -> Promise
7
+ const _reduce = function (collection, reducer, initial) {
8
+ if (typeof initial == 'function') {
9
+ const actualInitialValue = initial(collection)
10
10
  return isPromise(actualInitialValue)
11
11
  ? actualInitialValue.then(curry3(genericReduce, collection, reducer, __))
12
12
  : genericReduce(collection, reducer, actualInitialValue)
13
13
  }
14
- return isPromise(initialValue)
15
- ? initialValue.then(curry3(genericReduce, collection, reducer, __))
16
- : genericReduce(collection, reducer, initialValue)
14
+ return isPromise(initial)
15
+ ? initial.then(curry3(genericReduce, collection, reducer, __))
16
+ : genericReduce(collection, reducer, initial)
17
17
  }
18
18
 
19
19
  /**
@@ -21,155 +21,181 @@ const _reduce = function (collection, reducer, initialValue) {
21
21
  *
22
22
  * @synopsis
23
23
  * ```coffeescript [specscript]
24
- * type Foldable = Array|Object|Map|Iterator|AsyncIterator
24
+ * type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
25
25
  *
26
26
  * type Reducer = (
27
27
  * accumulator any,
28
- * value any,
29
- * indexOrKey? number|string,
30
- * collection? Foldable,
28
+ * item any,
29
+ * indexOrKey number|string|any,
30
+ * fold Foldable
31
31
  * )=>(nextAccumulator Promise|any)
32
32
  *
33
- * type Resolver = (collection Foldable)=>Promise|any
33
+ * type Resolver = (fold Foldable)=>Promise|any
34
34
  *
35
35
  * reduce(
36
- * collection Foldable,
36
+ * fold Foldable,
37
37
  * reducer Reducer,
38
- * initialValue? Resolver|any
38
+ * initial? Resolver|any
39
39
  * ) -> result Promise|any
40
40
  *
41
41
  * reduce(
42
42
  * reducer Reducer,
43
- * initialValue? Resolver|any
44
- * )(collection Foldable) -> result Promise|any
43
+ * initial? Resolver|any
44
+ * )(fold Foldable) -> result Promise|any
45
45
  * ```
46
46
  *
47
47
  * @description
48
- * Transforms a collection based on a reducer function and optional initial value. In a reducing operation, the result is defined in the beginning as either the initial value if supplied or the first item of the collection. The reducing operation then iterates through the remaining items in the collection, executing the reducer at each iteration to return the result to be used in the next iteration. The final result is the result of the execution of the reducer at the last item of the iteration. `reduce` accepts the following collections:
48
+ * Reduces a foldable to a single value.
49
+ *
50
+ * The following data types are considered to be foldables:
51
+ * * `array`
52
+ * * `set`
53
+ * * `map`
54
+ * * `generator`
55
+ * * `async generator`
56
+ * * `object with .reduce method`
57
+ * * `object`
58
+ *
59
+ * The reducing operation is dictated by a provided reducer function, which defines a transformation between the accumulator and a given item of the foldable.
60
+ *
61
+ * ```javascript
62
+ * const reducer = function (accumulator, item) {
63
+ * // nextAccumulator is the result of some operation between accumulator and item
64
+ * // and becomes the accumulator for the next iteration and invocation of the reducer
65
+ * return nextAccumulator
66
+ * }
67
+ * ```
49
68
  *
50
- * * `Array`
51
- * * `Object`
52
- * * `Set`
53
- * * `Map`
54
- * * `Iterator`/`Generator`
55
- * * `AsyncIterator`/`AsyncGenerator`
69
+ * The reducer function signature changes depending on the provided foldable.
56
70
  *
57
- * For arrays (type `Array`), `reduce` executes the reducer function for each item of the array in order, returning a new result at each execution to be used in the next execution. On each iteration, the reducer is passed the accumulator, the item of the iteration, the index of the item in the array, and a reference to the original array.
71
+ * If the foldable is an array:
72
+ * ```coffeescript [specscript]
73
+ * reducer(
74
+ * accumulator any,
75
+ * item any,
76
+ * index number,
77
+ * fold Array
78
+ * ) -> nextAccumulator Promise|any
79
+ * ```
58
80
  *
59
- * ```javascript [playground]
60
- * const max = (a, b) => a > b ? a : b
81
+ * If the foldable is a set:
82
+ * ```coffeescript [specscript]
83
+ * reducer(
84
+ * accumulator any,
85
+ * item any
86
+ * ) -> nextAccumulator Promise|any
87
+ * ```
61
88
  *
62
- * console.log(
63
- * reduce([1, 3, 5, 4, 2], max)
64
- * ) // 5
89
+ * If the foldable is a map:
90
+ * ```coffeescript [specscript]
91
+ * reducer(
92
+ * accumulator any,
93
+ * item any,
94
+ * key any,
95
+ * fold Map
96
+ * ) -> nextAccumulator Promise|any
97
+ * ```
65
98
  *
66
- * console.log(
67
- * reduce(max)([1, 3, 5, 4, 2])
68
- * ) // 5
99
+ * If the foldable is a generator:
100
+ * ```coffeescript [specscript]
101
+ * reducer(
102
+ * accumulator any,
103
+ * item any
104
+ * ) -> nextAccumulator Promise|any
69
105
  * ```
70
106
  *
71
- * If an optional initial value is provided, the result starts as the provided initial value rather than the first item of the collection.
107
+ * If the foldable is a async generator:
108
+ * ```coffeescript [specscript]
109
+ * reducer(
110
+ * accumulator any,
111
+ * item any
112
+ * ) -> nextAccumulator Promise|any
113
+ * ```
72
114
  *
73
- * ```javascript [playground]
74
- * const add = (a, b) => a + b
115
+ * If the foldable is an object with a `.reduce` method, the reducer function signature is defined externally.
75
116
  *
76
- * console.log(reduce([1, 2, 3, 4, 5], add, 0)) // 15
77
- * console.log(reduce(add, 0)([1, 2, 3, 4, 5])) // 15
117
+ * If the foldable is a plain object:
118
+ * ```coffeescript [specscript]
119
+ * reducer(
120
+ * accumulator any,
121
+ * item any,
122
+ * key string,
123
+ * fold Object
124
+ * ) -> nextAccumulator Promise|any
78
125
  * ```
79
126
  *
80
- * If the initialization parameter is a function, it is treated as a resolver and called with the arguments to resolve the initial value.
127
+ * `reduce` executes a reducer function for each item of the array in order. If no initial value is provided, `reduce` uses the first item of the foldable as the initial value and starts iterating from the second item of the foldable.
81
128
  *
82
129
  * ```javascript [playground]
83
- * const concatSquares = (array, value) => array.concat(value ** 2)
84
- *
85
- * const contrivedInitializer = array => [`initial length ${array.length}`]
86
- *
87
- * const array = [1, 2, 3, 4, 5]
130
+ * const max = (a, b) => a > b ? a : b
88
131
  *
89
- * console.log(reduce(concatSquares, contrivedInitializer)(array))
90
- * // ['initial length 5', 1, 4, 9, 16, 25]
91
- * console.log(reduce(array, concatSquares, contrivedInitializer))
92
- * // ['initial length 5', 1, 4, 9, 16, 25]
132
+ * const result = reduce([1, 3, 5, 4, 2], max)
133
+ * console.log(result) // 5
93
134
  * ```
94
135
  *
95
- * For objects (type `Object`), `reduce` executes the reducer function for each value of the object. On each iteration, the reducer is passed the accumulator, the object value, the key of the object value, and a reference to the original object.
136
+ * If an initial value is provided, the accumulator starts as the initial value rather than the first item of the foldable.
96
137
  *
97
138
  * ```javascript [playground]
98
139
  * const add = (a, b) => a + b
99
140
  *
100
- * const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
141
+ * const result = reduce([1, 2, 3, 4, 5], add, 0)
142
+ * console.log(result) // 15
143
+ * ```
101
144
  *
102
- * console.log(
103
- * reduce(obj, add)
104
- * ) // 15
145
+ * If the reducer is asynchronous, all promises created by the reducer are resolved before continuing with the reducing operation.
146
+ *
147
+ * ```javascript [playground]
148
+ * const asyncAdd = async (a, b) => a + b
105
149
  *
106
- * console.log(
107
- * reduce(add)(obj)
108
- * ) // 15
150
+ * const promise = reduce([1, 2, 3, 4, 5], asyncAdd, 0)
151
+ * promise.then(console.log) // 15
109
152
  * ```
110
153
  *
111
- * For sets (type `Set`), `reduce` executes the reducer function for each item of the set. On each iteration, the reducer is passed the accumulator and item of the set.
154
+ * If the initialization parameter is a function, it is treated as a resolver of the initial value and called with the foldable.
112
155
  *
113
156
  * ```javascript [playground]
114
- * const add = (a, b) => a + b
157
+ * const concatSquares = (array, value) => array.concat(value ** 2)
115
158
  *
116
- * const set = new Set([1, 2, 3, 4, 5])
159
+ * const contrivedInitializer = array => [`initial length ${array.length}`]
117
160
  *
118
- * console.log(
119
- * reduce(set, add)
120
- * ) // 15
161
+ * const array = [1, 2, 3, 4, 5]
121
162
  *
122
- * console.log(
123
- * reduce(add)(set)
124
- * ) // 15
163
+ * console.log(reduce(array, concatSquares, contrivedInitializer))
164
+ * // ['initial length 5', 1, 4, 9, 16, 25]
125
165
  * ```
126
166
  *
127
- * For maps (type `Map`), `reduce` executes the reducer function for each value of each entry of the map. On each iteration, the reducer is passed the accumulator, the map item, the key of the map item, and a reference to the original map.
167
+ * For objects, `reduce` iterates over just the values.
128
168
  *
129
169
  * ```javascript [playground]
130
170
  * const add = (a, b) => a + b
131
171
  *
132
- * const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
133
- *
134
- * console.log(
135
- * reduce(m, add)
136
- * ) // 15
172
+ * const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
137
173
  *
138
- * console.log(
139
- * reduce(add)(m)
140
- * ) // 15
174
+ * const result = reduce(obj, add)
175
+ * console.log(result) // 15
141
176
  * ```
142
177
  *
143
- * For iterators (type `Iterator`) and generators (type `Generator`), `reduce` executes the reducer function for each value of the iterator/generator. On each iteration, the reducer is passed the accumulator and the item of the iteration. The iterator/generator is consumed in the process.
178
+ * For maps, `reduce` iterates over the values of the entries.
144
179
  *
145
180
  * ```javascript [playground]
146
181
  * const add = (a, b) => a + b
147
182
  *
148
- * const generate12345 = function* () {
149
- * yield 1; yield 2; yield 3; yield 4; yield 5
150
- * }
151
- *
152
- * console.log(
153
- * reduce(generate12345(), add)
154
- * ) // 15
183
+ * const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
155
184
  *
156
- * console.log(
157
- * reduce(add)(generate12345())
158
- * ) // 15
185
+ * const result = reduce(m, add)
186
+ * console.log(result) // 15
159
187
  * ```
160
188
  *
161
- * For asyncIterators (type `AsyncIterator`) and asyncGenerators (type `AsyncGenerator`), `reduce` executes the reducer function for each value of the asyncIterator/asyncGenerator. On each iteration, the reducer is passed the accumulator and the item of the async iteration. The asyncIterator/asyncGenerator is consumed in the process.
189
+ * `reduce` works for async generators.
162
190
  *
163
191
  * ```javascript [playground]
164
192
  * const asyncAdd = async (a, b) => a + b
165
193
  *
166
- * const asyncGenerate12345 = async function* () {
194
+ * const asyncGenerate = async function* () {
167
195
  * yield 1; yield 2; yield 3; yield 4; yield 5
168
196
  * }
169
197
  *
170
- * reduce(asyncGenerate12345(), asyncAdd).then(console.log) // 15
171
- *
172
- * reduce(asyncAdd)(asyncGenerate12345()).then(console.log) // 15
198
+ * reduce(asyncGenerate(), asyncAdd).then(console.log) // 15
173
199
  * ```
174
200
  *
175
201
  * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
@@ -180,6 +206,23 @@ const _reduce = function (collection, reducer, initialValue) {
180
206
  * reduce(Promise.resolve([1, 2, 3, 4, 5]), add, 0).then(console.log) // 15
181
207
  * ```
182
208
  *
209
+ * Any promises passed for the initial value are also resolved before further execution.
210
+ *
211
+ * ```javascript [playground]
212
+ * const add = (a, b) => a + b
213
+ *
214
+ * const promise = reduce([1, 2, 3, 4, 5], add, Promise.resolve(0))
215
+ * promise.then(console.log) // 15
216
+ * ```
217
+ *
218
+ * See also:
219
+ * * [forEach](/docs/forEach)
220
+ * * [map](/docs/map)
221
+ * * [filter](/docs/filter)
222
+ * * [transform](/docs/transform)
223
+ * * [flatMap](/docs/flatMap)
224
+ * * [some](/docs/some)
225
+ *
183
226
  * @execution series
184
227
  *
185
228
  * @transducing
package/set.js CHANGED
@@ -96,6 +96,15 @@ const _set = function (obj, path, value) {
96
96
  * set(Promise.resolve({}), 'a', 1).then(console.log) // { a: 1 }
97
97
  * ```
98
98
  *
99
+ * See also:
100
+ * * [pipe](/docs/pipe)
101
+ * * [all](/docs/all)
102
+ * * [assign](/docs/assign)
103
+ * * [get](/docs/get)
104
+ * * [pick](/docs/pick)
105
+ * * [omit](/docs/omit)
106
+ * * [forEach](/docs/forEach)
107
+ *
99
108
  * @since 1.7.0
100
109
  */
101
110
 
package/some.js CHANGED
@@ -40,7 +40,7 @@ const _some = function (collection, predicate) {
40
40
  *
41
41
  * @synopsis
42
42
  * ```coffeescript [specscript]
43
- * type Foldable = Array|Iterable|AsyncIterable|{ reduce: function }|Object
43
+ * type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
44
44
  *
45
45
  * some(collection Foldable, predicate function) -> Promise|boolean
46
46
  *
@@ -48,7 +48,7 @@ const _some = function (collection, predicate) {
48
48
  * ```
49
49
  *
50
50
  * @description
51
- * Test a predicate concurrently across all items of a collection, returning true if any executions return truthy.
51
+ * Test a predicate concurrently across all items of a foldable, returning true if any executions return true.
52
52
  *
53
53
  * ```javascript [playground]
54
54
  * const isOdd = number => number % 2 == 1
@@ -58,7 +58,16 @@ const _some = function (collection, predicate) {
58
58
  * ) // true
59
59
  * ```
60
60
  *
61
- * The collection can be any iterable, async iterable, or object values iterable collection. Below is an example of `some` accepting an async generator as the collection.
61
+ * The following data types are considered to be foldables:
62
+ * * `array`
63
+ * * `set`
64
+ * * `map`
65
+ * * `generator`
66
+ * * `async generator`
67
+ * * `object with .reduce method`
68
+ * * `object`
69
+ *
70
+ * `some` works for async generators.
62
71
  *
63
72
  * ```javascript [playground]
64
73
  * const toTodosUrl = id => 'https://jsonplaceholder.typicode.com/todos/' + id
@@ -98,6 +107,11 @@ const _some = function (collection, predicate) {
98
107
  * some(Promise.resolve([1, 2, 3, 4, 5]), n => n > 6).then(console.log) // false
99
108
  * ```
100
109
  *
110
+ * See also:
111
+ * * [map](/docs/map)
112
+ * * [every](/docs/every)
113
+ * * [and](/docs/and)
114
+ *
101
115
  * @execution concurrent
102
116
  *
103
117
  * @muxing
package/switchCase.js CHANGED
@@ -91,6 +91,12 @@ const curryArgs3 = require('./_internal/curryArgs3')
91
91
  * ]) // 1 + 2 + 3 == 6
92
92
  * ```
93
93
  *
94
+ * See also:
95
+ * * [pipe](/docs/pipe)
96
+ * * [tap.if](/docs/tap.if)
97
+ * * [tryCatch](/docs/tryCatch)
98
+ * * [all](/docs/all)
99
+ *
94
100
  * @execution series
95
101
  */
96
102
  const switchCase = (...args) => {
package/tap.js CHANGED
@@ -46,6 +46,13 @@ const _tap = function (args, f) {
46
46
  * ```javascript [playground]
47
47
  * tap(Promise.resolve(1), Promise.resolve(2), 3, console.log) // 1 2 3
48
48
  * ```
49
+ *
50
+ * See also:
51
+ * * [pipe](/docs/pipe)
52
+ * * [compose](/docs/compose)
53
+ * * [tap.if](/docs/tap.if)
54
+ * * [switchCase](/docs/switchCase)
55
+ * * [tryCatch](/docs/tryCatch)
49
56
  */
50
57
  const tap = function (...args) {
51
58
  const f = args.pop()
@@ -116,6 +123,13 @@ const _tapIf = function (predicate, f, args) {
116
123
  * tap.if(Promise.resolve(1), n => n < 5, console.log) // 1
117
124
  * tap.if(Promise.resolve(6), n => n < 5, console.log)
118
125
  * ```
126
+ *
127
+ * See also:
128
+ * * [pipe](/docs/pipe)
129
+ * * [compose](/docs/compose)
130
+ * * [tap](/docs/tap)
131
+ * * [switchCase](/docs/switchCase)
132
+ * * [tryCatch](/docs/tryCatch)
119
133
  */
120
134
 
121
135
  tap.if = function (...args) {
package/thunkify.js CHANGED
@@ -22,6 +22,14 @@ const funcApply = require('./_internal/funcApply')
22
22
  *
23
23
  * console.log(thunkAdd12()) // 3
24
24
  * ```
25
+ *
26
+ * See also:
27
+ * * [eq](/docs/eq)
28
+ * * [always](/docs/always)
29
+ * * [curry](/docs/curry)
30
+ * * [__](/docs/__)
31
+ * * [Transducer.map](/docs/Transducer.map)
32
+ *
25
33
  */
26
34
  const thunkify = (func, ...args) => function thunk() {
27
35
  if (areAnyValuesPromises(args)) {
package/transform.js CHANGED
@@ -21,46 +21,106 @@ const _transform = function (collection, transducer, initialValue) {
21
21
  *
22
22
  * @synopsis
23
23
  * ```coffeescript [specscript]
24
- * type Foldable = Iterable|AsyncIterable|Object<value any>
24
+ * type Foldable = Array|Set|Map|Generator|AsyncGenerator|{ reduce: function }|Object
25
25
  *
26
26
  * type Reducer = (
27
27
  * accumulator any,
28
28
  * value any,
29
- * indexOrKey? number|string,
30
- * collection? Foldable,
31
29
  * )=>(nextAccumulator Promise|any)
32
30
  *
33
31
  * type Transducer = Reducer=>Reducer
34
32
  *
35
- * type Transformable =
33
+ * type Semigroup =
36
34
  * Array|String|Set|TypedArray|{ concat: function }|{ write: function }|Object
37
35
  *
38
- * type TransformableResolver = (collection Foldable)=>Promise|Transformable
36
+ * type SemigroupResolver = (fold Foldable)=>Promise|Semigroup
39
37
  *
40
38
  * transform(
41
- * collection Foldable,
39
+ * fold Foldable,
42
40
  * transducer Transducer,
43
- * initialValue? Transformable|TransformableResolver,
44
- * ) -> result Promise|Transformable
41
+ * initial? Semigroup|SemigroupResolver,
42
+ * ) -> result Promise|Semigroup
45
43
  *
46
44
  * transform(
47
45
  * transducer Transducer,
48
- * initialValue? Transformable|TransformableResolver,
49
- * )(collection Foldable) -> result Promise|Transformable
46
+ * initial? Semigroup|SemigroupResolver,
47
+ * )(fold Foldable) -> result Promise|Semigroup
50
48
  * ```
51
49
  *
52
50
  * @description
53
- * Transforms a transformable collection into any other transformable collection. The type of transformation depends on the collection provided by the initial value. If the initial is a function it is used as a resolver for the provided collection. `transform` accepts transformable collections, or collections that support a concatenation operation:
51
+ * Transforms a foldable with [transducers](https://rubico.land/blog/transducers-crash-course-rubico-v2) into a semigroup.
54
52
  *
55
- * * `Array`; concatenation defined by `result.concat(values)`
56
- * * `string`; concatenation defined by `result + values`
57
- * * `Set`; concatenation defined by `result.add(...values)`
58
- * * `TypedArray`; concatenation defined by `result.set(prevResult); result.set(values, offset)`
59
- * * `{ concat: function }`; concatenation defined by `result.concat(values)`
60
- * * `{ write: function }`; concatenation defined by `result.write(item)`
61
- * * `Object`; concatenation defined by `({ ...result, ...values })`
53
+ * The following data types are considered to be foldables:
54
+ * * `array`
55
+ * * `set`
56
+ * * `map`
57
+ * * `generator`
58
+ * * `async generator`
59
+ * * `object with .reduce method`
60
+ * * `object`
62
61
  *
63
- * `transform` can transform any of the above collections into any of the other above collections.
62
+ * Transducers, due to their lazy nature, don't have knowledge of the foldable they are transforming. As such, the transducer signature for all foldables is the same:
63
+ *
64
+ * ```coffeescript [specscript]
65
+ * type Reducer = (
66
+ * accumulator any,
67
+ * value any,
68
+ * )=>(nextAccumulator Promise|any)
69
+ *
70
+ * type Transducer = Reducer=>Reducer
71
+ * ```
72
+ *
73
+ * The following data types are considered to be semigroups:
74
+ * * `array`
75
+ * * `string`
76
+ * * `set`
77
+ * * `binary`
78
+ * * `{ concat: function }`
79
+ * * `{ write: function }`
80
+ * * `object`
81
+ *
82
+ * The concatenation operation changes depending on the provided semigroup:
83
+ *
84
+ * If the semigroup is an array, concatenation is defined as:
85
+ * ```javascript
86
+ * nextAccumulator = accumulator.concat(values)
87
+ * ```
88
+ *
89
+ * If the semigroup is a string, concatenation is defined as:
90
+ * ```javascript
91
+ * nextAccumulator = accumulator + values
92
+ * ```
93
+ *
94
+ * If the semigroup is a set, concatenation is defined as:
95
+ * ```javascript
96
+ * nextAccumulator = accumulator.add(...values)
97
+ * ```
98
+ *
99
+ * If the semigroup is binary, concatenation is defined as:
100
+ * ```javascript
101
+ * nextAccumulator = new accumulator.constructor(accumulator.length + values.length)
102
+ * nextAccumulator.set(accumulator)
103
+ * nextAccumulator.set(values, accumulator.length)
104
+ * ```
105
+ *
106
+ * If the semigroup is an object with a `.concat` method, concatenation is defined as:
107
+ * ```javascript
108
+ * nextAccumulator = accumulator
109
+ * accumulator.concat(values)
110
+ * ```
111
+ *
112
+ * If the semigroup is an object with a `.write` method, concatenation is defined as:
113
+ * ```javascript
114
+ * nextAccumulator = accumulator
115
+ * accumulator.write(values)
116
+ * ```
117
+ *
118
+ * If the semigroup is a plain object, concatenation is defined as:
119
+ * ```javascript
120
+ * nextAccumulator = ({ ...accumulator, ...values })
121
+ * ```
122
+ *
123
+ * `transform` transforms numbers from an array into another array.
64
124
  *
65
125
  * ```javascript [playground]
66
126
  * const square = number => number ** 2
@@ -74,26 +134,26 @@ const _transform = function (collection, transducer, initialValue) {
74
134
  *
75
135
  * // transform arrays into arrays
76
136
  * console.log(
77
- * transform(squaredOdds, [])([1, 2, 3, 4, 5])
137
+ * transform([1, 2, 3, 4, 5], squaredOdds, [])
78
138
  * ) // [1, 9, 25]
79
139
  *
80
140
  * // transform arrays into strings
81
141
  * console.log(
82
- * transform(squaredOdds, '')([1, 2, 3, 4, 5])
142
+ * transform([1, 2, 3, 4, 5], squaredOdds, '')
83
143
  * ) // '1925'
84
144
  *
85
145
  * // transform arrays into sets
86
146
  * console.log(
87
- * transform(squaredOdds, new Set())([1, 2, 3, 4, 5])
147
+ * transform([1, 2, 3, 4, 5], squaredOdds, new Set())
88
148
  * ) // Set (3) { 1, 9, 25 }
89
149
  *
90
150
  * // transform arrays into typed arrays
91
151
  * console.log(
92
- * transform(squaredOdds, new Uint8Array())([1, 2, 3, 4, 5]),
152
+ * transform([1, 2, 3, 4, 5], squaredOdds, new Uint8Array()),
93
153
  * ) // Uint8Array(3) [ 1, 9, 25 ]
94
154
  * ```
95
155
  *
96
- * `transform` arrays into objects that implement `.concat`.
156
+ * `transform` transforms arrays into objects that implement `.concat`.
97
157
  *
98
158
  * ```javascript [playground]
99
159
  * const square = number => number ** 2
@@ -105,7 +165,7 @@ const _transform = function (collection, transducer, initialValue) {
105
165
  * },
106
166
  * }
107
167
  *
108
- * transform(Transducer.map(square), Stdout)([1, 2, 3, 4, 5])
168
+ * transform([1, 2, 3, 4, 5], Transducer.map(square), Stdout)
109
169
  * // 1
110
170
  * // 4
111
171
  * // 9
@@ -113,9 +173,9 @@ const _transform = function (collection, transducer, initialValue) {
113
173
  * // 25
114
174
  * ```
115
175
  *
116
- * `transform` an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
176
+ * `transform` transforms an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
117
177
  *
118
- * ```javascript [playground]
178
+ * ```javascript
119
179
  * const { pipe, compose, transform } = rubico
120
180
  * // global Transducer
121
181
  *
@@ -133,40 +193,48 @@ const _transform = function (collection, transducer, initialValue) {
133
193
  * }
134
194
  * }
135
195
  *
136
- * const Stdout = {
137
- * concat(...args) {
138
- * console.log(...args)
139
- * return this
140
- * },
141
- * }
142
- *
143
196
  * transform(
144
197
  * streamRandomInts(10),
145
198
  * compose([
146
199
  * Transducer.map(square),
147
200
  * Transducer.map(toString),
148
201
  * ]),
149
- * Stdout,
202
+ * process.stdout // 2893600784289441449001600409684644624324923044411225
150
203
  * )
151
- * // 8281
152
- * // 8836
153
- * // 1156
154
- * // 8649
155
- * // 5625
156
- * // 2500
157
- * // ...
204
+ * ```
205
+ *
206
+ * If the initial value is a function it is treated as a resolver of the semigroup. The resolver may be asynchronous.
207
+ *
208
+ * ```javascript [playground]
209
+ * const promise = transform(
210
+ * [1, 2, 3, 4, 5],
211
+ * Transducer.map(number => number ** 2),
212
+ * async () => ['a'],
213
+ * )
214
+ *
215
+ * promise.then(console.log)
158
216
  * ```
159
217
  *
160
218
  * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
161
219
  *
162
220
  * ```javascript [playground]
163
- * transform(
221
+ * const promise = transform(
164
222
  * Promise.resolve([1, 2, 3, 4, 5]),
165
223
  * Transducer.map(n => n ** 2),
166
224
  * [],
167
- * ).then(console.log) // [1, 4, 9, 16, 25]
225
+ * )
226
+ *
227
+ * promise.then(console.log) // [1, 4, 9, 16, 25]
168
228
  * ```
169
229
  *
230
+ * See also:
231
+ * * [forEach](/docs/forEach)
232
+ * * [map](/docs/map)
233
+ * * [filter](/docs/filter)
234
+ * * [reduce](/docs/reduce)
235
+ * * [flatMap](/docs/flatMap)
236
+ * * [some](/docs/some)
237
+ *
170
238
  * @execution series
171
239
  *
172
240
  * @transducing