rubico 2.6.5 → 2.6.6

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 (340) hide show
  1. package/dist/Transducer.es.js +2 -2
  2. package/dist/Transducer.es.min.js +2 -2
  3. package/dist/Transducer.js +2 -2
  4. package/dist/Transducer.min.js +2 -2
  5. package/dist/Transducer.mjs +2 -2
  6. package/dist/__.es.js +2 -2
  7. package/dist/__.es.min.js +2 -2
  8. package/dist/__.js +2 -2
  9. package/dist/__.min.js +2 -2
  10. package/dist/__.mjs +2 -2
  11. package/dist/all.es.js +2 -22
  12. package/dist/all.es.min.js +2 -2
  13. package/dist/all.js +2 -22
  14. package/dist/all.min.js +2 -2
  15. package/dist/all.mjs +2 -22
  16. package/dist/always.es.js +2 -2
  17. package/dist/always.es.min.js +2 -2
  18. package/dist/always.js +2 -2
  19. package/dist/always.min.js +2 -2
  20. package/dist/always.mjs +2 -2
  21. package/dist/and.es.js +2 -2
  22. package/dist/and.es.min.js +2 -2
  23. package/dist/and.js +2 -2
  24. package/dist/and.min.js +2 -2
  25. package/dist/and.mjs +2 -2
  26. package/dist/assign.es.js +2 -2
  27. package/dist/assign.es.min.js +2 -2
  28. package/dist/assign.js +2 -2
  29. package/dist/assign.min.js +2 -2
  30. package/dist/assign.mjs +2 -2
  31. package/dist/compose.es.js +2 -2
  32. package/dist/compose.es.min.js +2 -2
  33. package/dist/compose.js +2 -2
  34. package/dist/compose.min.js +2 -2
  35. package/dist/compose.mjs +2 -2
  36. package/dist/curry.es.js +2 -2
  37. package/dist/curry.es.min.js +2 -2
  38. package/dist/curry.js +2 -2
  39. package/dist/curry.min.js +2 -2
  40. package/dist/curry.mjs +2 -2
  41. package/dist/eq.es.js +2 -2
  42. package/dist/eq.es.min.js +2 -2
  43. package/dist/eq.js +2 -2
  44. package/dist/eq.min.js +2 -2
  45. package/dist/eq.mjs +2 -2
  46. package/dist/every.es.js +2 -2
  47. package/dist/every.es.min.js +2 -2
  48. package/dist/every.js +2 -2
  49. package/dist/every.min.js +2 -2
  50. package/dist/every.mjs +2 -2
  51. package/dist/filter.es.js +5 -3
  52. package/dist/filter.es.min.js +3 -3
  53. package/dist/filter.js +5 -3
  54. package/dist/filter.min.js +3 -3
  55. package/dist/filter.mjs +5 -3
  56. package/dist/flatMap.es.js +2 -2
  57. package/dist/flatMap.es.min.js +2 -2
  58. package/dist/flatMap.js +2 -2
  59. package/dist/flatMap.min.js +2 -2
  60. package/dist/flatMap.mjs +2 -2
  61. package/dist/forEach.es.js +2 -2
  62. package/dist/forEach.es.min.js +2 -2
  63. package/dist/forEach.js +2 -2
  64. package/dist/forEach.min.js +2 -2
  65. package/dist/forEach.mjs +2 -2
  66. package/dist/get.es.js +2 -2
  67. package/dist/get.es.min.js +2 -2
  68. package/dist/get.js +2 -2
  69. package/dist/get.min.js +2 -2
  70. package/dist/get.mjs +2 -2
  71. package/dist/gt.es.js +2 -2
  72. package/dist/gt.es.min.js +2 -2
  73. package/dist/gt.js +2 -2
  74. package/dist/gt.min.js +2 -2
  75. package/dist/gt.mjs +2 -2
  76. package/dist/gte.es.js +2 -2
  77. package/dist/gte.es.min.js +2 -2
  78. package/dist/gte.js +2 -2
  79. package/dist/gte.min.js +2 -2
  80. package/dist/gte.mjs +2 -2
  81. package/dist/lt.es.js +2 -2
  82. package/dist/lt.es.min.js +2 -2
  83. package/dist/lt.js +2 -2
  84. package/dist/lt.min.js +2 -2
  85. package/dist/lt.mjs +2 -2
  86. package/dist/lte.es.js +2 -2
  87. package/dist/lte.es.min.js +2 -2
  88. package/dist/lte.js +2 -2
  89. package/dist/lte.min.js +2 -2
  90. package/dist/lte.mjs +2 -2
  91. package/dist/map.es.js +31 -31
  92. package/dist/map.es.min.js +3 -3
  93. package/dist/map.js +31 -31
  94. package/dist/map.min.js +3 -3
  95. package/dist/map.mjs +31 -31
  96. package/dist/not.es.js +2 -2
  97. package/dist/not.es.min.js +2 -2
  98. package/dist/not.js +2 -2
  99. package/dist/not.min.js +2 -2
  100. package/dist/not.mjs +2 -2
  101. package/dist/omit.es.js +2 -2
  102. package/dist/omit.es.min.js +2 -2
  103. package/dist/omit.js +2 -2
  104. package/dist/omit.min.js +2 -2
  105. package/dist/omit.mjs +2 -2
  106. package/dist/or.es.js +2 -2
  107. package/dist/or.es.min.js +2 -2
  108. package/dist/or.js +2 -2
  109. package/dist/or.min.js +2 -2
  110. package/dist/or.mjs +2 -2
  111. package/dist/pick.es.js +2 -2
  112. package/dist/pick.es.min.js +2 -2
  113. package/dist/pick.js +2 -2
  114. package/dist/pick.min.js +2 -2
  115. package/dist/pick.mjs +2 -2
  116. package/dist/pipe.es.js +2 -2
  117. package/dist/pipe.es.min.js +2 -2
  118. package/dist/pipe.js +2 -2
  119. package/dist/pipe.min.js +2 -2
  120. package/dist/pipe.mjs +2 -2
  121. package/dist/reduce.es.js +2 -2
  122. package/dist/reduce.es.min.js +2 -2
  123. package/dist/reduce.js +2 -2
  124. package/dist/reduce.min.js +2 -2
  125. package/dist/reduce.mjs +2 -2
  126. package/dist/rubico.es.js +34 -52
  127. package/dist/rubico.es.min.js +3 -3
  128. package/dist/rubico.global.js +34 -52
  129. package/dist/rubico.global.min.js +3 -3
  130. package/dist/rubico.js +34 -52
  131. package/dist/rubico.min.js +3 -3
  132. package/dist/rubico.mjs +34 -52
  133. package/dist/set.es.js +2 -2
  134. package/dist/set.es.min.js +2 -2
  135. package/dist/set.js +2 -2
  136. package/dist/set.min.js +2 -2
  137. package/dist/set.mjs +2 -2
  138. package/dist/some.es.js +2 -2
  139. package/dist/some.es.min.js +2 -2
  140. package/dist/some.js +2 -2
  141. package/dist/some.min.js +2 -2
  142. package/dist/some.mjs +2 -2
  143. package/dist/switchCase.es.js +2 -2
  144. package/dist/switchCase.es.min.js +2 -2
  145. package/dist/switchCase.js +2 -2
  146. package/dist/switchCase.min.js +2 -2
  147. package/dist/switchCase.mjs +2 -2
  148. package/dist/tap.es.js +2 -2
  149. package/dist/tap.es.min.js +2 -2
  150. package/dist/tap.js +2 -2
  151. package/dist/tap.min.js +2 -2
  152. package/dist/tap.mjs +2 -2
  153. package/dist/thunkify.es.js +2 -2
  154. package/dist/thunkify.es.min.js +2 -2
  155. package/dist/thunkify.js +2 -2
  156. package/dist/thunkify.min.js +2 -2
  157. package/dist/thunkify.mjs +2 -2
  158. package/dist/transform.es.js +2 -2
  159. package/dist/transform.es.min.js +2 -2
  160. package/dist/transform.js +2 -2
  161. package/dist/transform.min.js +2 -2
  162. package/dist/transform.mjs +2 -2
  163. package/dist/tryCatch.es.js +2 -2
  164. package/dist/tryCatch.es.min.js +2 -2
  165. package/dist/tryCatch.js +2 -2
  166. package/dist/tryCatch.min.js +2 -2
  167. package/dist/tryCatch.mjs +2 -2
  168. package/dist/x/append.es.js +2 -2
  169. package/dist/x/append.es.min.js +2 -2
  170. package/dist/x/append.js +2 -2
  171. package/dist/x/append.min.js +2 -2
  172. package/dist/x/append.mjs +2 -2
  173. package/dist/x/callProp.es.js +2 -2
  174. package/dist/x/callProp.es.min.js +2 -2
  175. package/dist/x/callProp.js +2 -2
  176. package/dist/x/callProp.min.js +2 -2
  177. package/dist/x/callProp.mjs +2 -2
  178. package/dist/x/defaultsDeep.es.js +2 -2
  179. package/dist/x/defaultsDeep.es.min.js +2 -2
  180. package/dist/x/defaultsDeep.js +2 -2
  181. package/dist/x/defaultsDeep.min.js +2 -2
  182. package/dist/x/defaultsDeep.mjs +2 -2
  183. package/dist/x/differenceWith.es.js +2 -2
  184. package/dist/x/differenceWith.es.min.js +2 -2
  185. package/dist/x/differenceWith.js +2 -2
  186. package/dist/x/differenceWith.min.js +2 -2
  187. package/dist/x/differenceWith.mjs +2 -2
  188. package/dist/x/filterOut.es.js +5 -3
  189. package/dist/x/filterOut.es.min.js +3 -3
  190. package/dist/x/filterOut.js +5 -3
  191. package/dist/x/filterOut.min.js +3 -3
  192. package/dist/x/filterOut.mjs +5 -3
  193. package/dist/x/find.es.js +2 -2
  194. package/dist/x/find.es.min.js +2 -2
  195. package/dist/x/find.js +2 -2
  196. package/dist/x/find.min.js +2 -2
  197. package/dist/x/find.mjs +2 -2
  198. package/dist/x/findIndex.es.js +2 -2
  199. package/dist/x/findIndex.es.min.js +2 -2
  200. package/dist/x/findIndex.js +2 -2
  201. package/dist/x/findIndex.min.js +2 -2
  202. package/dist/x/findIndex.mjs +2 -2
  203. package/dist/x/first.es.js +2 -2
  204. package/dist/x/first.es.min.js +2 -2
  205. package/dist/x/first.js +2 -2
  206. package/dist/x/first.min.js +2 -2
  207. package/dist/x/first.mjs +2 -2
  208. package/dist/x/flatten.es.js +2 -2
  209. package/dist/x/flatten.es.min.js +2 -2
  210. package/dist/x/flatten.js +2 -2
  211. package/dist/x/flatten.min.js +2 -2
  212. package/dist/x/flatten.mjs +2 -2
  213. package/dist/x/groupBy.es.js +2 -2
  214. package/dist/x/groupBy.es.min.js +2 -2
  215. package/dist/x/groupBy.js +2 -2
  216. package/dist/x/groupBy.min.js +2 -2
  217. package/dist/x/groupBy.mjs +2 -2
  218. package/dist/x/has.es.js +2 -2
  219. package/dist/x/has.es.min.js +2 -2
  220. package/dist/x/has.js +2 -2
  221. package/dist/x/has.min.js +2 -2
  222. package/dist/x/has.mjs +2 -2
  223. package/dist/x/identity.es.js +2 -2
  224. package/dist/x/identity.es.min.js +2 -2
  225. package/dist/x/identity.js +2 -2
  226. package/dist/x/identity.min.js +2 -2
  227. package/dist/x/identity.mjs +2 -2
  228. package/dist/x/includes.es.js +2 -2
  229. package/dist/x/includes.es.min.js +2 -2
  230. package/dist/x/includes.js +2 -2
  231. package/dist/x/includes.min.js +2 -2
  232. package/dist/x/includes.mjs +2 -2
  233. package/dist/x/isDeepEqual.es.js +2 -2
  234. package/dist/x/isDeepEqual.es.min.js +2 -2
  235. package/dist/x/isDeepEqual.js +2 -2
  236. package/dist/x/isDeepEqual.min.js +2 -2
  237. package/dist/x/isDeepEqual.mjs +2 -2
  238. package/dist/x/isEmpty.es.js +2 -2
  239. package/dist/x/isEmpty.es.min.js +2 -2
  240. package/dist/x/isEmpty.js +2 -2
  241. package/dist/x/isEmpty.min.js +2 -2
  242. package/dist/x/isEmpty.mjs +2 -2
  243. package/dist/x/isEqual.es.js +2 -2
  244. package/dist/x/isEqual.es.min.js +2 -2
  245. package/dist/x/isEqual.js +2 -2
  246. package/dist/x/isEqual.min.js +2 -2
  247. package/dist/x/isEqual.mjs +2 -2
  248. package/dist/x/isFunction.es.js +2 -2
  249. package/dist/x/isFunction.es.min.js +2 -2
  250. package/dist/x/isFunction.js +2 -2
  251. package/dist/x/isFunction.min.js +2 -2
  252. package/dist/x/isFunction.mjs +2 -2
  253. package/dist/x/isIn.es.js +2 -2
  254. package/dist/x/isIn.es.min.js +2 -2
  255. package/dist/x/isIn.js +2 -2
  256. package/dist/x/isIn.min.js +2 -2
  257. package/dist/x/isIn.mjs +2 -2
  258. package/dist/x/isObject.es.js +2 -2
  259. package/dist/x/isObject.es.min.js +2 -2
  260. package/dist/x/isObject.js +2 -2
  261. package/dist/x/isObject.min.js +2 -2
  262. package/dist/x/isObject.mjs +2 -2
  263. package/dist/x/isString.es.js +2 -2
  264. package/dist/x/isString.es.min.js +2 -2
  265. package/dist/x/isString.js +2 -2
  266. package/dist/x/isString.min.js +2 -2
  267. package/dist/x/isString.mjs +2 -2
  268. package/dist/x/keys.es.js +2 -2
  269. package/dist/x/keys.es.min.js +2 -2
  270. package/dist/x/keys.js +2 -2
  271. package/dist/x/keys.min.js +2 -2
  272. package/dist/x/keys.mjs +2 -2
  273. package/dist/x/last.es.js +2 -2
  274. package/dist/x/last.es.min.js +2 -2
  275. package/dist/x/last.js +2 -2
  276. package/dist/x/last.min.js +2 -2
  277. package/dist/x/last.mjs +2 -2
  278. package/dist/x/maxBy.es.js +2 -2
  279. package/dist/x/maxBy.es.min.js +2 -2
  280. package/dist/x/maxBy.js +2 -2
  281. package/dist/x/maxBy.min.js +2 -2
  282. package/dist/x/maxBy.mjs +2 -2
  283. package/dist/x/noop.es.js +2 -2
  284. package/dist/x/noop.es.min.js +2 -2
  285. package/dist/x/noop.js +2 -2
  286. package/dist/x/noop.min.js +2 -2
  287. package/dist/x/noop.mjs +2 -2
  288. package/dist/x/pluck.es.js +31 -31
  289. package/dist/x/pluck.es.min.js +3 -3
  290. package/dist/x/pluck.js +31 -31
  291. package/dist/x/pluck.min.js +3 -3
  292. package/dist/x/pluck.mjs +31 -31
  293. package/dist/x/prepend.es.js +2 -2
  294. package/dist/x/prepend.es.min.js +2 -2
  295. package/dist/x/prepend.js +2 -2
  296. package/dist/x/prepend.min.js +2 -2
  297. package/dist/x/prepend.mjs +2 -2
  298. package/dist/x/size.es.js +2 -2
  299. package/dist/x/size.es.min.js +2 -2
  300. package/dist/x/size.js +2 -2
  301. package/dist/x/size.min.js +2 -2
  302. package/dist/x/size.mjs +2 -2
  303. package/dist/x/trace.es.js +2 -2
  304. package/dist/x/trace.es.min.js +2 -2
  305. package/dist/x/trace.js +2 -2
  306. package/dist/x/trace.min.js +2 -2
  307. package/dist/x/trace.mjs +2 -2
  308. package/dist/x/unionWith.es.js +2 -2
  309. package/dist/x/unionWith.es.min.js +2 -2
  310. package/dist/x/unionWith.js +2 -2
  311. package/dist/x/unionWith.min.js +2 -2
  312. package/dist/x/unionWith.mjs +2 -2
  313. package/dist/x/uniq.es.js +2 -2
  314. package/dist/x/uniq.es.min.js +2 -2
  315. package/dist/x/uniq.js +2 -2
  316. package/dist/x/uniq.min.js +2 -2
  317. package/dist/x/uniq.mjs +2 -2
  318. package/dist/x/unless.es.js +2 -2
  319. package/dist/x/unless.es.min.js +2 -2
  320. package/dist/x/unless.js +2 -2
  321. package/dist/x/unless.min.js +2 -2
  322. package/dist/x/unless.mjs +2 -2
  323. package/dist/x/values.es.js +2 -2
  324. package/dist/x/values.es.min.js +2 -2
  325. package/dist/x/values.js +2 -2
  326. package/dist/x/values.min.js +2 -2
  327. package/dist/x/values.mjs +2 -2
  328. package/dist/x/when.es.js +2 -2
  329. package/dist/x/when.es.min.js +2 -2
  330. package/dist/x/when.js +2 -2
  331. package/dist/x/when.min.js +2 -2
  332. package/dist/x/when.mjs +2 -2
  333. package/es.js +34 -52
  334. package/filter.js +41 -45
  335. package/flatMap.js +24 -27
  336. package/index.js +34 -52
  337. package/map.js +67 -89
  338. package/package.json +1 -3
  339. package/reduce.js +44 -82
  340. package/transform.js +24 -32
package/map.js CHANGED
@@ -93,93 +93,82 @@ const _map = function (value, f) {
93
93
  *
94
94
  * @synopsis
95
95
  * ```coffeescript [specscript]
96
- * type Mappable = Array|Object|Set|Map|Iterator|AsyncIterator
96
+ * type Functor = Array|Object|Set|Generator|AsyncGenerator
97
97
  *
98
98
  * type Mapper = (
99
- * value any,
99
+ * item any,
100
100
  * indexOrKey number|string|any,
101
- * collection Mappable
101
+ * f Map|Functor
102
102
  * )=>(resultItem Promise|any)
103
103
  *
104
- * map(collection Promise|Mappable, f Mapper) -> result Promise|Mappable
105
- * map(f Mapper)(collection Mappable) -> result Promise|Mappable
104
+ * map(f Promise|Map|Functor, mapper Mapper) -> result Promise|Map|Functor
105
+ * map(mapper Mapper)(f Map|Functor) -> result Promise|Map|Functor
106
106
  * ```
107
107
  *
108
108
  * @description
109
- * Applies a synchronous or asynchronous mapper function `f` concurrently to each item of a collection, returning the results in a new collection of the same type. If order is implied by the collection, it is maintained in the result. `map` accepts the following collections:
109
+ * Applies a mapper function to each item of a functor, returning a functor of the same type with the transformed items. The order of the items is maintained.
110
+ *
111
+ * The following data types are considered functors:
112
+ * * `array`
113
+ * * `object`
114
+ * * `set`
115
+ * * `iterator`
116
+ * * `async iterator`
110
117
  *
111
- * * `Array`
112
- * * `Object`
113
- * * `Set`
114
- * * `Map`
115
- * * `Iterator`/`Generator`
116
- * * `AsyncIterator`/`AsyncGenerator`
118
+ * The mapper function defines the transformation of a given item in the provided functor.
117
119
  *
118
- * With arrays (type `Array`), `map` applies the mapper function `f` to each item of the array, returning the transformed results in a new array ordered the same as the original array.
120
+ * ```javascript
121
+ * const mapper = function (item) {
122
+ * // resultItem is the result of some operation on item
123
+ * return resultItem
124
+ * }
125
+ * ```
126
+ *
127
+ * `map` works for arrays.
119
128
  *
120
129
  * ```javascript [playground]
121
130
  * const square = number => number ** 2
122
131
  *
123
132
  * const array = [1, 2, 3, 4, 5]
124
133
  *
125
- * console.log(
126
- * map(array, square)
127
- * ) // [1, 4, 9, 16, 25]
128
- *
129
- * console.log(
130
- * map(square)(array)
131
- * ) // [1, 4, 9, 16, 25]
134
+ * const result = map(array, square)
135
+ * console.log(result) // [1, 4, 9, 16, 25]
132
136
  * ```
133
137
  *
134
- * With objects (type `Object`), `map` applies the mapper function `f` to each value of the object, returning the transformed results as values in a new object ordered by the keys of the original object
138
+ * The mapper function may be asynchronous, in which case it is applied concurrently.
135
139
  *
136
140
  * ```javascript [playground]
137
- * const square = number => number ** 2
141
+ * const asyncSquare = async number => number ** 2
138
142
  *
139
- * const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
140
- *
141
- * console.log(
142
- * map(square)(obj)
143
- * ) // { a: 1, b: 4, c: 9, d: 16, e: 25 }
143
+ * const array = [1, 2, 3, 4, 5]
144
144
  *
145
- * console.log(
146
- * map(obj, square)
147
- * ) // { a: 1, b: 4, c: 9, d: 16, e: 25 }
145
+ * const promise = map(array, asyncSquare)
146
+ * promise.then(console.log) // [1, 4, 9, 16, 25]
148
147
  * ```
149
148
  *
150
- * With sets (type `Set`), `map` applies the mapper function `f` to each value of the set, returning the transformed results unordered in a new set.
149
+ * For objects, `map` applies the mapper function to just the values.
151
150
  *
152
151
  * ```javascript [playground]
153
152
  * const square = number => number ** 2
154
153
  *
155
- * const set = new Set([1, 2, 3, 4, 5])
156
- *
157
- * console.log(
158
- * map(set, square)
159
- * ) // [1, 4, 9, 16, 25]
154
+ * const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
160
155
  *
161
- * console.log(
162
- * map(square)(set)
163
- * ) // [1, 4, 9, 16, 25]
156
+ * const result = map(obj, square)
157
+ * console.log(result) // { a: 1, b: 4, c: 9, d: 16, e: 25 }
164
158
  * ```
165
159
  *
166
- * With maps (type `Map`), `map` applies the mapper function `f` to each value of the map, returning the results at the same keys in a new map. The entries of the resulting map are in the same order as those of the original map
160
+ * For maps, `map` applies the mapper function to the values of the entries.
167
161
  *
168
162
  * ```javascript [playground]
169
163
  * const square = number => number ** 2
170
164
  *
171
165
  * const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
172
166
  *
173
- * console.log(
174
- * map(square)(m)
175
- * ) // Map { 'a' => 1, 'b' => 4, 'c' => 9, 'd' => 16, 'e' => 25 }
176
- *
177
- * console.log(
178
- * map(m, square)
179
- * ) // Map { 'a' => 1, 'b' => 4, 'c' => 9, 'd' => 16, 'e' => 25 }
167
+ * const result = map(m, square)
168
+ * console.log(result) // Map { 'a' => 1, 'b' => 4, 'c' => 9, 'd' => 16, 'e' => 25 }
180
169
  * ```
181
170
  *
182
- * With iterators (type `Iterator`) or generators (type `Generator`), `map` applies the mapper function `f` lazily to each value of the iterator/generator, creating a new iterator with transformed iterations.
171
+ * For generators, `map` applies the mapper function lazily to each value of the iterator, creating a new iterator with transformed items.
183
172
  *
184
173
  * ```javascript [playground]
185
174
  * const capitalize = string => string.toUpperCase()
@@ -190,16 +179,13 @@ const _map = function (value, f) {
190
179
  *
191
180
  * const abcGenerator = abcGeneratorFunc()
192
181
  * const ABCGenerator = map(abcGeneratorFunc(), capitalize)
193
- * const ABCGenerator2 = map(capitalize)(abcGeneratorFunc())
194
182
  *
195
183
  * console.log([...abcGenerator]) // ['a', 'b', 'c']
196
184
  *
197
185
  * console.log([...ABCGenerator]) // ['A', 'B', 'C']
198
- *
199
- * console.log([...ABCGenerator2]) // ['A', 'B', 'C']
200
186
  * ```
201
187
  *
202
- * With asyncIterators (type `AsyncIterator`, or `AsyncGenerator`), `map` applies the mapper function `f` lazily to each value of the asyncIterator, creating a new asyncIterator with transformed iterations
188
+ * For async generators, `map` applies the mapper function lazily to each value of the async generator, creating a new async generator with transformed items.
203
189
  *
204
190
  * ```javascript [playground]
205
191
  * const capitalize = string => string.toUpperCase()
@@ -210,7 +196,6 @@ const _map = function (value, f) {
210
196
  *
211
197
  * const abcAsyncGenerator = abcAsyncGeneratorFunc()
212
198
  * const ABCGenerator = map(abcAsyncGeneratorFunc(), capitalize)
213
- * const ABCGenerator2 = map(capitalize)(abcAsyncGeneratorFunc())
214
199
  *
215
200
  * ;(async function () {
216
201
  * for await (const letter of abcAsyncGenerator) {
@@ -226,13 +211,6 @@ const _map = function (value, f) {
226
211
  * // B
227
212
  * // C
228
213
  * }
229
- *
230
- * for await (const letter of ABCGenerator2) {
231
- * console.log(letter)
232
- * // A
233
- * // B
234
- * // C
235
- * }
236
214
  * })()
237
215
  * ```
238
216
  *
@@ -334,15 +312,15 @@ map.entries = function mapEntries(arg0, arg1) {
334
312
  *
335
313
  * @synopsis
336
314
  * ```coffeescript [specscript]
337
- * type Mappable = Array|Object|Set|Map
315
+ * type Functor = Array|Object|Set|Map
338
316
  *
339
317
  * type Mapper = (
340
318
  * value any,
341
319
  * indexOrKey number|string|any,
342
- * collection Mappable
320
+ * f Functor
343
321
  * )=>(mappedItem Promise|any)
344
322
  *
345
- * _mapSeries(collection Mappable, f Mapper) -> result Promise|Mappable
323
+ * _mapSeries(f Functor, f Mapper) -> result Promise|Functor
346
324
  * ```
347
325
  */
348
326
  const _mapSeries = function (collection, f) {
@@ -373,16 +351,16 @@ const _mapSeries = function (collection, f) {
373
351
  *
374
352
  * @synopsis
375
353
  * ```coffeescript [specscript]
376
- * type Mappable = Array|Object|Set|Map
354
+ * type Functor = Array|Object|Set|Map
377
355
  *
378
356
  * type Mapper = (
379
357
  * value any,
380
358
  * indexOrKey number|string|any,
381
- * collection Mappable
359
+ * f Functor
382
360
  * )=>(mappedItem Promise|any)
383
361
  *
384
- * map.series(collection Promise|Mappable, f Mapper) -> result Mappable
385
- * map.series(f Mapper)(collection Mappable) -> result Mappable
362
+ * map.series(f Promise|Functor, f Mapper) -> result Functor
363
+ * map.series(f Mapper)(f Functor) -> result Functor
386
364
  * ```
387
365
  *
388
366
  * @description
@@ -425,31 +403,31 @@ map.series = function mapSeries(arg0, arg1) {
425
403
  *
426
404
  * @synopsis
427
405
  * ```coffeescript [specscript]
428
- * type Mappable = Array|Object|Set|Map
406
+ * type Functor = Array|Object|Set|Map
429
407
  *
430
- * _mapPool(collection Mappable, concurrency number, f function) -> result Promise|Mappable
408
+ * _mapPool(f Functor, concurrency number, mapper function) -> result Promise|Functor
431
409
  * ```
432
410
  */
433
- const _mapPool = function (collection, concurrency, f) {
434
- if (isArray(collection)) {
435
- return arrayMapPool(collection, concurrency, f)
411
+ const _mapPool = function (f, concurrency, mapper) {
412
+ if (isArray(f)) {
413
+ return arrayMapPool(f, concurrency, mapper)
436
414
  }
437
- if (collection == null) {
438
- throw new TypeError(`invalid collection ${collection}`)
415
+ if (f == null) {
416
+ throw new TypeError(`invalid functor ${f}`)
439
417
  }
440
- if (typeof collection == 'string' || collection.constructor == String) {
441
- return stringMapPool(collection, concurrency, f)
418
+ if (typeof f == 'string' || f.constructor == String) {
419
+ return stringMapPool(f, concurrency, mapper)
442
420
  }
443
- if (collection.constructor == Set) {
444
- return setMapPool(collection, concurrency, f)
421
+ if (f.constructor == Set) {
422
+ return setMapPool(f, concurrency, mapper)
445
423
  }
446
- if (collection.constructor == Map) {
447
- return mapMapPool(collection, concurrency, f)
424
+ if (f.constructor == Map) {
425
+ return mapMapPool(f, concurrency, mapper)
448
426
  }
449
- if (collection.constructor == Object) {
450
- return objectMapPool(collection, concurrency, f)
427
+ if (f.constructor == Object) {
428
+ return objectMapPool(f, concurrency, mapper)
451
429
  }
452
- throw new TypeError(`invalid collection ${collection}`)
430
+ throw new TypeError(`invalid functor ${f}`)
453
431
  }
454
432
 
455
433
  /**
@@ -457,15 +435,15 @@ const _mapPool = function (collection, concurrency, f) {
457
435
  *
458
436
  * @synopsis
459
437
  * ```coffeescript [specscript]
460
- * type Mappable = Array|Object|Set|Map
438
+ * type Functor = Array|Object|Set|Map
461
439
  *
462
440
  * map.pool(
463
441
  * concurrency number,
464
442
  * mapper (value any)=>Promise|any,
465
- * )(collection Mappable) -> result Promise|Array
443
+ * )(f Functor) -> result Promise|Array
466
444
  *
467
445
  * map.pool(
468
- * collection Mappable,
446
+ * f Functor,
469
447
  * concurrency number,
470
448
  * mapper (value any)=>Promise|any,
471
449
  * ) -> result Promise|Array
@@ -517,15 +495,15 @@ map.pool = function mapPool(arg0, arg1, arg2) {
517
495
  *
518
496
  * @synopsis
519
497
  * ```coffeescript [specscript]
520
- * type Mappable = Array|Object|Set|Map
498
+ * type Functor = Array|Object|Set|Map
521
499
  *
522
500
  * map.rate(
523
501
  * rate number,
524
502
  * f (value any)=>Promise|any,
525
- * )(collection Mappable) -> result Promise|Array
503
+ * )(f Functor) -> result Promise|Array
526
504
  *
527
505
  * map.rate(
528
- * collection Mappable,
506
+ * f Functor,
529
507
  * rate number,
530
508
  * f (value any)=>Promise|any,
531
509
  * ) -> result Promise|Array
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubico",
3
- "version": "2.6.5",
3
+ "version": "2.6.6",
4
4
  "description": "[a]synchronous functional programming",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
@@ -115,7 +115,6 @@
115
115
  "async": "latest",
116
116
  "bluebird": "latest",
117
117
  "codecov": "^3.7.1",
118
- "eslint": "^9.22.0",
119
118
  "fantasy-land": "latest",
120
119
  "lodash": "latest",
121
120
  "mocha": "^11.1.0",
@@ -129,7 +128,6 @@
129
128
  "scripts": {
130
129
  "test": "mocha test.js *.test.js */**.test.js",
131
130
  "test-coverage": "nyc mocha test.js x/*.test.js monad/*.test.js",
132
- "lint": "eslint .",
133
131
  "build": "npm run dts && ./build",
134
132
  "bench": "./bench",
135
133
  "dts": "del *.d.ts _internal/*.d.ts x/*.d.ts && tsc"
package/reduce.js CHANGED
@@ -21,19 +21,19 @@ 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 = Iterable|AsyncIterable|Object<value any>
25
25
  *
26
26
  * type Reducer = (
27
27
  * accumulator any,
28
- * value any,
28
+ * item any,
29
29
  * indexOrKey? number|string,
30
- * collection? Foldable,
30
+ * f? Map|Foldable,
31
31
  * )=>(nextAccumulator Promise|any)
32
32
  *
33
- * type Resolver = (collection Foldable)=>Promise|any
33
+ * type Resolver = (f Map|Foldable)=>Promise|any
34
34
  *
35
35
  * reduce(
36
- * collection Foldable,
36
+ * f Map|Foldable,
37
37
  * reducer Reducer,
38
38
  * initialValue? Resolver|any
39
39
  * ) -> result Promise|any
@@ -41,43 +41,53 @@ const _reduce = function (collection, reducer, initialValue) {
41
41
  * reduce(
42
42
  * reducer Reducer,
43
43
  * initialValue? Resolver|any
44
- * )(collection Foldable) -> result Promise|any
44
+ * )(f Map|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 map or foldable to a single value.
49
49
  *
50
- * * `Array`
51
- * * `Object`
52
- * * `Set`
53
- * * `Map`
54
- * * `Iterator`/`Generator`
55
- * * `AsyncIterator`/`AsyncGenerator`
50
+ * The following data types are considered foldables:
51
+ * * `iterable`
52
+ * * `async iterable`
53
+ * * `object`; only the values of the object are transformed
56
54
  *
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.
55
+ * The following data types are considered iterable:
56
+ * * `array`
57
+ * * `set`
58
+ * * `map`
59
+ *
60
+ * The reducing operation is dictated by a provided reducer function, which defines a transformation between the accumulator and a given item of the map or foldable.
61
+ *
62
+ * ```javascript
63
+ * const reducer = function (accumulator, item) {
64
+ * const nextAccumulator = f(accumulator, item)
65
+ * return nextAccumulator
66
+ * // nextAccumulator becomes the accumulator for the next iteration and invocation of the reducer
67
+ * }
68
+ * ```
69
+ *
70
+ * The result of the last invocation of the reducer is the result of the reducing operation. The reducer may be asynchronous and return a promise, in which case the promise is resolved for its value before continuing with the reducing operation.
71
+ *
72
+ * `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 map or foldable as the initial value and starts iterating from the second item of the map or foldable.
58
73
  *
59
74
  * ```javascript [playground]
60
75
  * const max = (a, b) => a > b ? a : b
61
76
  *
62
- * console.log(
63
- * reduce([1, 3, 5, 4, 2], max)
64
- * ) // 5
65
- *
66
- * console.log(
67
- * reduce(max)([1, 3, 5, 4, 2])
68
- * ) // 5
77
+ * const result = reduce([1, 3, 5, 4, 2], max)
78
+ * console.log(result) // 5
69
79
  * ```
70
80
  *
71
- * If an optional initial value is provided, the result starts as the provided initial value rather than the first item of the collection.
81
+ * If an initial value is provided, the accumulator starts as the initial value rather than the first item of the map or foldable.
72
82
  *
73
83
  * ```javascript [playground]
74
84
  * const add = (a, b) => a + b
75
85
  *
76
- * console.log(reduce([1, 2, 3, 4, 5], add, 0)) // 15
77
- * console.log(reduce(add, 0)([1, 2, 3, 4, 5])) // 15
86
+ * const result = reduce([1, 2, 3, 4, 5], add, 0)
87
+ * console.log(result) // 15
78
88
  * ```
79
89
  *
80
- * If the initialization parameter is a function, it is treated as a resolver and called with the arguments to resolve the initial value.
90
+ * If the initialization parameter is a function, it is treated as a resolver of the initial value and called with the map or foldable.
81
91
  *
82
92
  * ```javascript [playground]
83
93
  * const concatSquares = (array, value) => array.concat(value ** 2)
@@ -86,90 +96,42 @@ const _reduce = function (collection, reducer, initialValue) {
86
96
  *
87
97
  * const array = [1, 2, 3, 4, 5]
88
98
  *
89
- * console.log(reduce(concatSquares, contrivedInitializer)(array))
90
- * // ['initial length 5', 1, 4, 9, 16, 25]
91
99
  * console.log(reduce(array, concatSquares, contrivedInitializer))
92
100
  * // ['initial length 5', 1, 4, 9, 16, 25]
93
101
  * ```
94
102
  *
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.
103
+ * For objects, `reduce` iterates over just the values.
96
104
  *
97
105
  * ```javascript [playground]
98
106
  * const add = (a, b) => a + b
99
107
  *
100
108
  * const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
101
109
  *
102
- * console.log(
103
- * reduce(obj, add)
104
- * ) // 15
105
- *
106
- * console.log(
107
- * reduce(add)(obj)
108
- * ) // 15
110
+ * const result = reduce(obj, add)
111
+ * console.log(result) // 15
109
112
  * ```
110
113
  *
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.
112
- *
113
- * ```javascript [playground]
114
- * const add = (a, b) => a + b
115
- *
116
- * const set = new Set([1, 2, 3, 4, 5])
117
- *
118
- * console.log(
119
- * reduce(set, add)
120
- * ) // 15
121
- *
122
- * console.log(
123
- * reduce(add)(set)
124
- * ) // 15
125
- * ```
126
- *
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.
114
+ * For maps, `reduce` iterates over the values of the entries.
128
115
  *
129
116
  * ```javascript [playground]
130
117
  * const add = (a, b) => a + b
131
118
  *
132
119
  * const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
133
120
  *
134
- * console.log(
135
- * reduce(m, add)
136
- * ) // 15
137
- *
138
- * console.log(
139
- * reduce(add)(m)
140
- * ) // 15
141
- * ```
142
- *
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.
144
- *
145
- * ```javascript [playground]
146
- * const add = (a, b) => a + b
147
- *
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
155
- *
156
- * console.log(
157
- * reduce(add)(generate12345())
158
- * ) // 15
121
+ * const result = reduce(m, add)
122
+ * console.log(result) // 15
159
123
  * ```
160
124
  *
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.
125
+ * `reduce` works for async iterators.
162
126
  *
163
127
  * ```javascript [playground]
164
128
  * const asyncAdd = async (a, b) => a + b
165
129
  *
166
- * const asyncGenerate12345 = async function* () {
130
+ * const asyncGenerate = async function* () {
167
131
  * yield 1; yield 2; yield 3; yield 4; yield 5
168
132
  * }
169
133
  *
170
- * reduce(asyncGenerate12345(), asyncAdd).then(console.log) // 15
171
- *
172
- * reduce(asyncAdd)(asyncGenerate12345()).then(console.log) // 15
134
+ * reduce(asyncGenerate(), asyncAdd).then(console.log) // 15
173
135
  * ```
174
136
  *
175
137
  * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
package/transform.js CHANGED
@@ -26,39 +26,45 @@ const _transform = function (collection, transducer, initialValue) {
26
26
  * type Reducer = (
27
27
  * accumulator any,
28
28
  * value any,
29
- * indexOrKey? number|string,
30
- * collection? Foldable,
29
+ * indexOrKey number|string,
30
+ * f Foldable,
31
31
  * )=>(nextAccumulator Promise|any)
32
32
  *
33
33
  * type Transducer = Reducer=>Reducer
34
34
  *
35
- * type Transformable =
35
+ * type Semigroup =
36
36
  * Array|String|Set|TypedArray|{ concat: function }|{ write: function }|Object
37
37
  *
38
- * type TransformableResolver = (collection Foldable)=>Promise|Transformable
38
+ * type SemigroupResolver = (f Foldable)=>Promise|Semigroup
39
39
  *
40
40
  * transform(
41
- * collection Foldable,
41
+ * f Foldable,
42
42
  * transducer Transducer,
43
- * initialValue? Transformable|TransformableResolver,
44
- * ) -> result Promise|Transformable
43
+ * initialValue? Semigroup|SemigroupResolver,
44
+ * ) -> result Promise|Semigroup
45
45
  *
46
46
  * transform(
47
47
  * transducer Transducer,
48
- * initialValue? Transformable|TransformableResolver,
49
- * )(collection Foldable) -> result Promise|Transformable
48
+ * initialValue? Semigroup|SemigroupResolver,
49
+ * )(f Foldable) -> result Promise|Semigroup
50
50
  * ```
51
51
  *
52
52
  * @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:
53
+ * Transforms a foldable into a semigroup. The type of transformation depends on the type of semigroup provided as the initial value. If the initial value is a function it is treated as a resolver of the semigroup.
54
54
  *
55
- * * `Array`; concatenation defined by `result.concat(values)`
55
+ * The following data types are considered foldables:
56
+ * * `iterable`
57
+ * * `async iterable`
58
+ * * `object`; only the values of the object are transformed
59
+ *
60
+ * The following data types are considered semigroups:
61
+ * * `array`; concatenation defined by `result.concat(values)`
56
62
  * * `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)`
63
+ * * `set`; concatenation defined by `result.add(...values)`
64
+ * * `binary`; concatenation defined by `result.set(prevResult); result.set(values, offset)`
59
65
  * * `{ concat: function }`; concatenation defined by `result.concat(values)`
60
66
  * * `{ write: function }`; concatenation defined by `result.write(item)`
61
- * * `Object`; concatenation defined by `({ ...result, ...values })`
67
+ * * `object`; concatenation defined by `({ ...result, ...values })`
62
68
  *
63
69
  * `transform` can transform any of the above collections into any of the other above collections.
64
70
  *
@@ -93,7 +99,7 @@ const _transform = function (collection, transducer, initialValue) {
93
99
  * ) // Uint8Array(3) [ 1, 9, 25 ]
94
100
  * ```
95
101
  *
96
- * `transform` arrays into objects that implement `.concat`.
102
+ * `transform` transforms arrays into objects that implement `.concat`.
97
103
  *
98
104
  * ```javascript [playground]
99
105
  * const square = number => number ** 2
@@ -113,9 +119,9 @@ const _transform = function (collection, transducer, initialValue) {
113
119
  * // 25
114
120
  * ```
115
121
  *
116
- * `transform` an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
122
+ * `transform` transforms an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
117
123
  *
118
- * ```javascript [playground]
124
+ * ```javascript
119
125
  * const { pipe, compose, transform } = rubico
120
126
  * // global Transducer
121
127
  *
@@ -133,28 +139,14 @@ const _transform = function (collection, transducer, initialValue) {
133
139
  * }
134
140
  * }
135
141
  *
136
- * const Stdout = {
137
- * concat(...args) {
138
- * console.log(...args)
139
- * return this
140
- * },
141
- * }
142
- *
143
142
  * transform(
144
143
  * streamRandomInts(10),
145
144
  * compose([
146
145
  * Transducer.map(square),
147
146
  * Transducer.map(toString),
148
147
  * ]),
149
- * Stdout,
148
+ * process.stdout // 2893600784289441449001600409684644624324923044411225
150
149
  * )
151
- * // 8281
152
- * // 8836
153
- * // 1156
154
- * // 8649
155
- * // 5625
156
- * // 2500
157
- * // ...
158
150
  * ```
159
151
  *
160
152
  * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.