rubico 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. package/_internal/arrayMapPool.js +11 -19
  2. package/_internal/mapMapPool.js +80 -0
  3. package/_internal/objectMapPool.js +77 -0
  4. package/_internal/objectMapSeries.js +1 -0
  5. package/_internal/setMapPool.js +79 -0
  6. package/_internal/stringMapPool.js +22 -0
  7. package/all.js +11 -1
  8. package/and.js +9 -0
  9. package/assign.js +14 -1
  10. package/compose.js +8 -0
  11. package/dist/Transducer.es.js +1 -1
  12. package/dist/Transducer.es.min.js +1 -1
  13. package/dist/Transducer.js +1 -1
  14. package/dist/Transducer.min.js +1 -1
  15. package/dist/Transducer.mjs +1 -1
  16. package/dist/__.es.js +1 -1
  17. package/dist/__.es.min.js +1 -1
  18. package/dist/__.js +1 -1
  19. package/dist/__.min.js +1 -1
  20. package/dist/__.mjs +1 -1
  21. package/dist/all.es.js +1 -1
  22. package/dist/all.es.min.js +1 -1
  23. package/dist/all.js +1 -1
  24. package/dist/all.min.js +1 -1
  25. package/dist/all.mjs +1 -1
  26. package/dist/always.es.js +1 -1
  27. package/dist/always.es.min.js +1 -1
  28. package/dist/always.js +1 -1
  29. package/dist/always.min.js +1 -1
  30. package/dist/always.mjs +1 -1
  31. package/dist/and.es.js +1 -1
  32. package/dist/and.es.min.js +1 -1
  33. package/dist/and.js +1 -1
  34. package/dist/and.min.js +1 -1
  35. package/dist/and.mjs +1 -1
  36. package/dist/assign.es.js +1 -1
  37. package/dist/assign.es.min.js +1 -1
  38. package/dist/assign.js +1 -1
  39. package/dist/assign.min.js +1 -1
  40. package/dist/assign.mjs +1 -1
  41. package/dist/compose.es.js +1 -1
  42. package/dist/compose.es.min.js +1 -1
  43. package/dist/compose.js +1 -1
  44. package/dist/compose.min.js +1 -1
  45. package/dist/compose.mjs +1 -1
  46. package/dist/curry.es.js +1 -1
  47. package/dist/curry.es.min.js +1 -1
  48. package/dist/curry.js +1 -1
  49. package/dist/curry.min.js +1 -1
  50. package/dist/curry.mjs +1 -1
  51. package/dist/eq.es.js +1 -1
  52. package/dist/eq.es.min.js +1 -1
  53. package/dist/eq.js +1 -1
  54. package/dist/eq.min.js +1 -1
  55. package/dist/eq.mjs +1 -1
  56. package/dist/every.es.js +1 -1
  57. package/dist/every.es.min.js +1 -1
  58. package/dist/every.js +1 -1
  59. package/dist/every.min.js +1 -1
  60. package/dist/every.mjs +1 -1
  61. package/dist/filter.es.js +1 -1
  62. package/dist/filter.es.min.js +1 -1
  63. package/dist/filter.js +1 -1
  64. package/dist/filter.min.js +1 -1
  65. package/dist/filter.mjs +1 -1
  66. package/dist/flatMap.es.js +1 -1
  67. package/dist/flatMap.es.min.js +1 -1
  68. package/dist/flatMap.js +1 -1
  69. package/dist/flatMap.min.js +1 -1
  70. package/dist/flatMap.mjs +1 -1
  71. package/dist/forEach.es.js +3 -2
  72. package/dist/forEach.es.min.js +2 -2
  73. package/dist/forEach.js +3 -2
  74. package/dist/forEach.min.js +2 -2
  75. package/dist/forEach.mjs +3 -2
  76. package/dist/get.es.js +1 -1
  77. package/dist/get.es.min.js +1 -1
  78. package/dist/get.js +1 -1
  79. package/dist/get.min.js +1 -1
  80. package/dist/get.mjs +1 -1
  81. package/dist/gt.es.js +1 -1
  82. package/dist/gt.es.min.js +1 -1
  83. package/dist/gt.js +1 -1
  84. package/dist/gt.min.js +1 -1
  85. package/dist/gt.mjs +1 -1
  86. package/dist/gte.es.js +1 -1
  87. package/dist/gte.es.min.js +1 -1
  88. package/dist/gte.js +1 -1
  89. package/dist/gte.min.js +1 -1
  90. package/dist/gte.mjs +1 -1
  91. package/dist/lt.es.js +1 -1
  92. package/dist/lt.es.min.js +1 -1
  93. package/dist/lt.js +1 -1
  94. package/dist/lt.min.js +1 -1
  95. package/dist/lt.mjs +1 -1
  96. package/dist/lte.es.js +1 -1
  97. package/dist/lte.es.min.js +1 -1
  98. package/dist/lte.js +1 -1
  99. package/dist/lte.min.js +1 -1
  100. package/dist/lte.mjs +1 -1
  101. package/dist/map.es.js +221 -44
  102. package/dist/map.es.min.js +2 -2
  103. package/dist/map.js +221 -44
  104. package/dist/map.min.js +2 -2
  105. package/dist/map.mjs +221 -44
  106. package/dist/not.es.js +1 -1
  107. package/dist/not.es.min.js +1 -1
  108. package/dist/not.js +1 -1
  109. package/dist/not.min.js +1 -1
  110. package/dist/not.mjs +1 -1
  111. package/dist/omit.es.js +1 -1
  112. package/dist/omit.es.min.js +1 -1
  113. package/dist/omit.js +1 -1
  114. package/dist/omit.min.js +1 -1
  115. package/dist/omit.mjs +1 -1
  116. package/dist/or.es.js +1 -1
  117. package/dist/or.es.min.js +1 -1
  118. package/dist/or.js +1 -1
  119. package/dist/or.min.js +1 -1
  120. package/dist/or.mjs +1 -1
  121. package/dist/pick.es.js +1 -1
  122. package/dist/pick.es.min.js +1 -1
  123. package/dist/pick.js +1 -1
  124. package/dist/pick.min.js +1 -1
  125. package/dist/pick.mjs +1 -1
  126. package/dist/pipe.es.js +1 -1
  127. package/dist/pipe.es.min.js +1 -1
  128. package/dist/pipe.js +1 -1
  129. package/dist/pipe.min.js +1 -1
  130. package/dist/pipe.mjs +1 -1
  131. package/dist/reduce.es.js +1 -1
  132. package/dist/reduce.es.min.js +1 -1
  133. package/dist/reduce.js +1 -1
  134. package/dist/reduce.min.js +1 -1
  135. package/dist/reduce.mjs +1 -1
  136. package/dist/rubico.es.js +259 -60
  137. package/dist/rubico.es.min.js +2 -2
  138. package/dist/rubico.global.js +259 -60
  139. package/dist/rubico.global.min.js +2 -2
  140. package/dist/rubico.js +259 -60
  141. package/dist/rubico.min.js +2 -2
  142. package/dist/rubico.mjs +259 -60
  143. package/dist/set.es.js +1 -1
  144. package/dist/set.es.min.js +1 -1
  145. package/dist/set.js +1 -1
  146. package/dist/set.min.js +1 -1
  147. package/dist/set.mjs +1 -1
  148. package/dist/some.es.js +1 -1
  149. package/dist/some.es.min.js +1 -1
  150. package/dist/some.js +1 -1
  151. package/dist/some.min.js +1 -1
  152. package/dist/some.mjs +1 -1
  153. package/dist/switchCase.es.js +1 -1
  154. package/dist/switchCase.es.min.js +1 -1
  155. package/dist/switchCase.js +1 -1
  156. package/dist/switchCase.min.js +1 -1
  157. package/dist/switchCase.mjs +1 -1
  158. package/dist/tap.es.js +100 -14
  159. package/dist/tap.es.min.js +2 -2
  160. package/dist/tap.js +100 -14
  161. package/dist/tap.min.js +2 -2
  162. package/dist/tap.mjs +100 -14
  163. package/dist/thunkify.es.js +1 -1
  164. package/dist/thunkify.es.min.js +1 -1
  165. package/dist/thunkify.js +1 -1
  166. package/dist/thunkify.min.js +1 -1
  167. package/dist/thunkify.mjs +1 -1
  168. package/dist/transform.es.js +1 -1
  169. package/dist/transform.es.min.js +1 -1
  170. package/dist/transform.js +1 -1
  171. package/dist/transform.min.js +1 -1
  172. package/dist/transform.mjs +1 -1
  173. package/dist/tryCatch.es.js +1 -1
  174. package/dist/tryCatch.es.min.js +1 -1
  175. package/dist/tryCatch.js +1 -1
  176. package/dist/tryCatch.min.js +1 -1
  177. package/dist/tryCatch.mjs +1 -1
  178. package/dist/x/append.es.js +1 -1
  179. package/dist/x/append.es.min.js +1 -1
  180. package/dist/x/append.js +1 -1
  181. package/dist/x/append.min.js +1 -1
  182. package/dist/x/append.mjs +1 -1
  183. package/dist/x/callProp.es.js +1 -1
  184. package/dist/x/callProp.es.min.js +1 -1
  185. package/dist/x/callProp.js +1 -1
  186. package/dist/x/callProp.min.js +1 -1
  187. package/dist/x/callProp.mjs +1 -1
  188. package/dist/x/defaultsDeep.es.js +1 -1
  189. package/dist/x/defaultsDeep.es.min.js +1 -1
  190. package/dist/x/defaultsDeep.js +1 -1
  191. package/dist/x/defaultsDeep.min.js +1 -1
  192. package/dist/x/defaultsDeep.mjs +1 -1
  193. package/dist/x/differenceWith.es.js +1 -1
  194. package/dist/x/differenceWith.es.min.js +1 -1
  195. package/dist/x/differenceWith.js +1 -1
  196. package/dist/x/differenceWith.min.js +1 -1
  197. package/dist/x/differenceWith.mjs +1 -1
  198. package/dist/x/filterOut.es.js +1 -1
  199. package/dist/x/filterOut.es.min.js +1 -1
  200. package/dist/x/filterOut.js +1 -1
  201. package/dist/x/filterOut.min.js +1 -1
  202. package/dist/x/filterOut.mjs +1 -1
  203. package/dist/x/find.es.js +1 -1
  204. package/dist/x/find.es.min.js +1 -1
  205. package/dist/x/find.js +1 -1
  206. package/dist/x/find.min.js +1 -1
  207. package/dist/x/find.mjs +1 -1
  208. package/dist/x/findIndex.es.js +1 -1
  209. package/dist/x/findIndex.es.min.js +1 -1
  210. package/dist/x/findIndex.js +1 -1
  211. package/dist/x/findIndex.min.js +1 -1
  212. package/dist/x/findIndex.mjs +1 -1
  213. package/dist/x/first.es.js +1 -1
  214. package/dist/x/first.es.min.js +1 -1
  215. package/dist/x/first.js +1 -1
  216. package/dist/x/first.min.js +1 -1
  217. package/dist/x/first.mjs +1 -1
  218. package/dist/x/flatten.es.js +1 -1
  219. package/dist/x/flatten.es.min.js +1 -1
  220. package/dist/x/flatten.js +1 -1
  221. package/dist/x/flatten.min.js +1 -1
  222. package/dist/x/flatten.mjs +1 -1
  223. package/dist/x/groupBy.es.js +1 -1
  224. package/dist/x/groupBy.es.min.js +1 -1
  225. package/dist/x/groupBy.js +1 -1
  226. package/dist/x/groupBy.min.js +1 -1
  227. package/dist/x/groupBy.mjs +1 -1
  228. package/dist/x/has.es.js +1 -1
  229. package/dist/x/has.es.min.js +1 -1
  230. package/dist/x/has.js +1 -1
  231. package/dist/x/has.min.js +1 -1
  232. package/dist/x/has.mjs +1 -1
  233. package/dist/x/identity.es.js +1 -1
  234. package/dist/x/identity.es.min.js +1 -1
  235. package/dist/x/identity.js +1 -1
  236. package/dist/x/identity.min.js +1 -1
  237. package/dist/x/identity.mjs +1 -1
  238. package/dist/x/includes.es.js +1 -1
  239. package/dist/x/includes.es.min.js +1 -1
  240. package/dist/x/includes.js +1 -1
  241. package/dist/x/includes.min.js +1 -1
  242. package/dist/x/includes.mjs +1 -1
  243. package/dist/x/isDeepEqual.es.js +1 -1
  244. package/dist/x/isDeepEqual.es.min.js +1 -1
  245. package/dist/x/isDeepEqual.js +1 -1
  246. package/dist/x/isDeepEqual.min.js +1 -1
  247. package/dist/x/isDeepEqual.mjs +1 -1
  248. package/dist/x/isEmpty.es.js +1 -1
  249. package/dist/x/isEmpty.es.min.js +1 -1
  250. package/dist/x/isEmpty.js +1 -1
  251. package/dist/x/isEmpty.min.js +1 -1
  252. package/dist/x/isEmpty.mjs +1 -1
  253. package/dist/x/isEqual.es.js +1 -1
  254. package/dist/x/isEqual.es.min.js +1 -1
  255. package/dist/x/isEqual.js +1 -1
  256. package/dist/x/isEqual.min.js +1 -1
  257. package/dist/x/isEqual.mjs +1 -1
  258. package/dist/x/isFunction.es.js +1 -1
  259. package/dist/x/isFunction.es.min.js +1 -1
  260. package/dist/x/isFunction.js +1 -1
  261. package/dist/x/isFunction.min.js +1 -1
  262. package/dist/x/isFunction.mjs +1 -1
  263. package/dist/x/isIn.es.js +1 -1
  264. package/dist/x/isIn.es.min.js +1 -1
  265. package/dist/x/isIn.js +1 -1
  266. package/dist/x/isIn.min.js +1 -1
  267. package/dist/x/isIn.mjs +1 -1
  268. package/dist/x/isObject.es.js +1 -1
  269. package/dist/x/isObject.es.min.js +1 -1
  270. package/dist/x/isObject.js +1 -1
  271. package/dist/x/isObject.min.js +1 -1
  272. package/dist/x/isObject.mjs +1 -1
  273. package/dist/x/isString.es.js +1 -1
  274. package/dist/x/isString.es.min.js +1 -1
  275. package/dist/x/isString.js +1 -1
  276. package/dist/x/isString.min.js +1 -1
  277. package/dist/x/isString.mjs +1 -1
  278. package/dist/x/keys.es.js +1 -1
  279. package/dist/x/keys.es.min.js +1 -1
  280. package/dist/x/keys.js +1 -1
  281. package/dist/x/keys.min.js +1 -1
  282. package/dist/x/keys.mjs +1 -1
  283. package/dist/x/last.es.js +1 -1
  284. package/dist/x/last.es.min.js +1 -1
  285. package/dist/x/last.js +1 -1
  286. package/dist/x/last.min.js +1 -1
  287. package/dist/x/last.mjs +1 -1
  288. package/dist/x/maxBy.es.js +1 -1
  289. package/dist/x/maxBy.es.min.js +1 -1
  290. package/dist/x/maxBy.js +1 -1
  291. package/dist/x/maxBy.min.js +1 -1
  292. package/dist/x/maxBy.mjs +1 -1
  293. package/dist/x/noop.es.js +1 -1
  294. package/dist/x/noop.es.min.js +1 -1
  295. package/dist/x/noop.js +1 -1
  296. package/dist/x/noop.min.js +1 -1
  297. package/dist/x/noop.mjs +1 -1
  298. package/dist/x/pluck.es.js +221 -44
  299. package/dist/x/pluck.es.min.js +2 -2
  300. package/dist/x/pluck.js +221 -44
  301. package/dist/x/pluck.min.js +2 -2
  302. package/dist/x/pluck.mjs +221 -44
  303. package/dist/x/prepend.es.js +1 -1
  304. package/dist/x/prepend.es.min.js +1 -1
  305. package/dist/x/prepend.js +1 -1
  306. package/dist/x/prepend.min.js +1 -1
  307. package/dist/x/prepend.mjs +1 -1
  308. package/dist/x/size.es.js +1 -1
  309. package/dist/x/size.es.min.js +1 -1
  310. package/dist/x/size.js +1 -1
  311. package/dist/x/size.min.js +1 -1
  312. package/dist/x/size.mjs +1 -1
  313. package/dist/x/trace.es.js +100 -14
  314. package/dist/x/trace.es.min.js +2 -2
  315. package/dist/x/trace.js +100 -14
  316. package/dist/x/trace.min.js +2 -2
  317. package/dist/x/trace.mjs +100 -14
  318. package/dist/x/unionWith.es.js +1 -1
  319. package/dist/x/unionWith.es.min.js +1 -1
  320. package/dist/x/unionWith.js +1 -1
  321. package/dist/x/unionWith.min.js +1 -1
  322. package/dist/x/unionWith.mjs +1 -1
  323. package/dist/x/uniq.es.js +1 -1
  324. package/dist/x/uniq.es.min.js +1 -1
  325. package/dist/x/uniq.js +1 -1
  326. package/dist/x/uniq.min.js +1 -1
  327. package/dist/x/uniq.mjs +1 -1
  328. package/dist/x/unless.es.js +1 -1
  329. package/dist/x/unless.es.min.js +1 -1
  330. package/dist/x/unless.js +1 -1
  331. package/dist/x/unless.min.js +1 -1
  332. package/dist/x/unless.mjs +1 -1
  333. package/dist/x/values.es.js +1 -1
  334. package/dist/x/values.es.min.js +1 -1
  335. package/dist/x/values.js +1 -1
  336. package/dist/x/values.min.js +1 -1
  337. package/dist/x/values.mjs +1 -1
  338. package/dist/x/when.es.js +1 -1
  339. package/dist/x/when.es.min.js +1 -1
  340. package/dist/x/when.js +1 -1
  341. package/dist/x/when.min.js +1 -1
  342. package/dist/x/when.mjs +1 -1
  343. package/eq.js +6 -0
  344. package/es.js +259 -60
  345. package/every.js +6 -0
  346. package/filter.js +9 -0
  347. package/flatMap.js +7 -0
  348. package/forEach.js +20 -1
  349. package/get.js +6 -0
  350. package/gt.js +6 -0
  351. package/gte.js +6 -0
  352. package/index.js +259 -60
  353. package/lt.js +6 -0
  354. package/lte.js +6 -0
  355. package/map.js +118 -45
  356. package/not.js +8 -0
  357. package/omit.js +7 -0
  358. package/or.js +9 -0
  359. package/package.json +1 -1
  360. package/pick.js +7 -0
  361. package/pipe.js +8 -0
  362. package/reduce.js +8 -0
  363. package/set.js +6 -0
  364. package/some.js +6 -0
  365. package/switchCase.js +12 -0
  366. package/tap.js +75 -26
  367. package/transform.js +38 -10
  368. package/tryCatch.js +14 -0
package/map.js CHANGED
@@ -3,6 +3,7 @@ const MappingIterator = require('./_internal/MappingIterator')
3
3
  const MappingAsyncIterator = require('./_internal/MappingAsyncIterator')
4
4
  const __ = require('./_internal/placeholder')
5
5
  const curry2 = require('./_internal/curry2')
6
+ const curry3 = require('./_internal/curry3')
6
7
  const isArray = require('./_internal/isArray')
7
8
  const isObject = require('./_internal/isObject')
8
9
  const arrayMap = require('./_internal/arrayMap')
@@ -16,6 +17,10 @@ const objectMapSeries = require('./_internal/objectMapSeries')
16
17
  const setMapSeries = require('./_internal/setMapSeries')
17
18
  const mapMapSeries = require('./_internal/mapMapSeries')
18
19
  const arrayMapPool = require('./_internal/arrayMapPool')
20
+ const stringMapPool = require('./_internal/stringMapPool')
21
+ const setMapPool = require('./_internal/setMapPool')
22
+ const mapMapPool = require('./_internal/mapMapPool')
23
+ const objectMapPool = require('./_internal/objectMapPool')
19
24
  const objectMapEntries = require('./_internal/objectMapEntries')
20
25
  const mapMapEntries = require('./_internal/mapMapEntries')
21
26
  const symbolIterator = require('./_internal/symbolIterator')
@@ -45,21 +50,6 @@ const symbolAsyncIterator = require('./_internal/symbolAsyncIterator')
45
50
  * originalMap Map,
46
51
  * mapMapper (value any, key any, originalMap Map)=>Promise|any
47
52
  * ) -> mappedMap Promise|Map
48
- *
49
- * _map(
50
- * generatorFunction ...args=>Generator,
51
- * syncMapper (value any)=>any,
52
- * ) -> mappingGeneratorFunction ...args=>Generator
53
- *
54
- * _map(
55
- * asyncGeneratorFunction ...args=>AsyncGenerator,
56
- * mapper (value any)=>Promise|any
57
- * ) -> mappingAsyncGeneratorFunction ...args=>AsyncGenerator
58
- *
59
- * _map(
60
- * originalReducer Reducer,
61
- * mapper (value any)=>Promise|any,
62
- * ) -> mappingReducer Reducer
63
53
  * ```
64
54
  */
65
55
 
@@ -107,11 +97,11 @@ const _map = function (value, mapper) {
107
97
  *
108
98
  * type Mapper = (
109
99
  * value any,
110
- * indexOrKey number|string,
100
+ * indexOrKey number|string|any,
111
101
  * collection Mappable
112
102
  * )=>(resultItem Promise|any)
113
103
  *
114
- * map(collection Mappable, f Mapper) -> result Promise|Mappable
104
+ * map(collection Promise|Mappable, f Mapper) -> result Promise|Mappable
115
105
  * map(f Mapper)(collection Mappable) -> result Promise|Mappable
116
106
  * ```
117
107
  *
@@ -246,12 +236,21 @@ const _map = function (value, mapper) {
246
236
  * })()
247
237
  * ```
248
238
  *
239
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
240
+ *
241
+ * ```javascript [playground]
242
+ * const asyncSquare = async n => n ** 2
243
+ *
244
+ * map(Promise.resolve([1, 2, 3, 4, 5]), asyncSquare).then(console.log)
245
+ * // [1, 4, 9, 16, 25]
246
+ * ```
247
+ *
249
248
  * @execution concurrent
250
249
  *
251
250
  * @TODO streamMap
252
251
  */
253
252
  const map = function (arg0, arg1) {
254
- if (typeof arg0 == 'function') {
253
+ if (arg1 == null) {
255
254
  return curry2(_map, __, arg0)
256
255
  }
257
256
  return isPromise(arg0)
@@ -278,14 +277,19 @@ const _mapEntries = (value, mapper) => {
278
277
  *
279
278
  * @synopsis
280
279
  * ```coffeescript [specscript]
281
- * map.entries(
282
- * value Map|Object|Promise<Map|Object>,
283
- * mapper ([key any, value any])=>Promise|[any, any],
284
- * ) -> Promise|Map|Object
280
+ * type EntriesMappable = Object|Map
285
281
  *
286
- * map.entries(
287
- * mapper ([key any, value any])=>Promise|[any, any],
288
- * )(value Map|Object) -> Promise|Map|Object
282
+ * type Mapper = (
283
+ * value any,
284
+ * key string|any,
285
+ * collection EntriesMappable
286
+ * )=>(resultItem Promise|any)
287
+ *
288
+ * map.entries(value Promise|EntriesMappable, mapper Mapper)
289
+ * -> Promise|EntriesMappable
290
+ *
291
+ * map.entries(mapper Mapper)(value EntriesMappable)
292
+ * -> Promise|EntriesMappable
289
293
  * ```
290
294
  *
291
295
  * @description
@@ -302,10 +306,22 @@ const _mapEntries = (value, mapper) => {
302
306
  * // Map(3) { 'A' => 1, 'B' => 4, 'C' => 9 }
303
307
  * ```
304
308
  *
309
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
310
+ *
311
+ * ```javascript [playground]
312
+ * const asyncSquareEntries = async ([k, v]) => [k, v ** 2]
313
+ *
314
+ * map.entries(
315
+ * Promise.resolve({ a: 1, b: 2, c: 3 }),
316
+ * asyncSquareEntries,
317
+ * ).then(console.log)
318
+ * // { a: 1, b: 4, c: 9 }
319
+ * ```
320
+ *
305
321
  * @since v1.7.0
306
322
  */
307
323
  map.entries = function mapEntries(arg0, arg1) {
308
- if (typeof arg0 == 'function') {
324
+ if (arg1 == null) {
309
325
  return curry2(_mapEntries, __, arg0)
310
326
  }
311
327
  return isPromise(arg0)
@@ -318,11 +334,11 @@ map.entries = function mapEntries(arg0, arg1) {
318
334
  *
319
335
  * @synopsis
320
336
  * ```coffeescript [specscript]
321
- * type Mappable = Array|Object|Set|Map|Iterator|AsyncIterator
337
+ * type Mappable = Array|Object|Set|Map
322
338
  *
323
339
  * type Mapper = (
324
340
  * value any,
325
- * indexOrKey number|string,
341
+ * indexOrKey number|string|any,
326
342
  * collection Mappable
327
343
  * )=>(mappedItem Promise|any)
328
344
  *
@@ -357,23 +373,20 @@ const _mapSeries = function (collection, f) {
357
373
  *
358
374
  * @synopsis
359
375
  * ```coffeescript [specscript]
360
- * type Mappable = Array|Object|Set|Map|Iterator|AsyncIterator
376
+ * type Mappable = Array|Object|Set|Map
361
377
  *
362
378
  * type Mapper = (
363
379
  * value any,
364
- * indexOrKey number|string,
380
+ * indexOrKey number|string|any,
365
381
  * collection Mappable
366
382
  * )=>(mappedItem Promise|any)
367
383
  *
368
- * map.series( Mappable)
369
- *
370
- * map.series(
371
- * mapperFunc (value any)=>Promise|any,
372
- * )(array Array) -> Promise|Array
384
+ * map.series(collection Promise|Mappable, f Mapper) -> result Mappable
385
+ * map.series(f Mapper)(collection Mappable) -> result Mappable
373
386
  * ```
374
387
  *
375
388
  * @description
376
- * `map` with serial execution.
389
+ * [map](/docs/map) with serial execution.
377
390
  *
378
391
  * ```javascript [playground]
379
392
  * const delayedLog = number => new Promise(function (resolve) {
@@ -384,13 +397,22 @@ const _mapSeries = function (collection, f) {
384
397
  * })
385
398
  *
386
399
  * console.log('start')
387
- * map.series(delayedLog)([1, 2, 3, 4, 5])
400
+ * map.series([1, 2, 3, 4, 5], delayedLog)
401
+ * ```
402
+ *
403
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
404
+ *
405
+ * ```javascript [playground]
406
+ * const asyncSquare = async n => n ** 2
407
+ *
408
+ * map.series(Promise.resolve([1, 2, 3, 4, 5]), asyncSquare).then(console.log)
409
+ * // [1, 4, 9, 16, 25]
388
410
  * ```
389
411
  *
390
412
  * @execution series
391
413
  */
392
414
  map.series = function mapSeries(arg0, arg1) {
393
- if (typeof arg0 == 'function') {
415
+ if (arg1 == null) {
394
416
  return curry2(_mapSeries, __, arg0)
395
417
  }
396
418
  return isPromise(arg0)
@@ -398,19 +420,59 @@ map.series = function mapSeries(arg0, arg1) {
398
420
  : _mapSeries(arg0, arg1)
399
421
  }
400
422
 
423
+ /**
424
+ * @name _mapPool
425
+ *
426
+ * @synopsis
427
+ * ```coffeescript [specscript]
428
+ * type Mappable = Array|Object|Set|Map
429
+ *
430
+ * _mapPool(collection Mappable, concurrency number, f function) -> result Promise|Mappable
431
+ * ```
432
+ */
433
+ const _mapPool = function (collection, concurrency, f) {
434
+ if (isArray(collection)) {
435
+ return arrayMapPool(collection, concurrency, f)
436
+ }
437
+ if (collection == null) {
438
+ throw new TypeError(`invalid collection ${collection}`)
439
+ }
440
+ if (typeof collection == 'string' || collection.constructor == String) {
441
+ return stringMapPool(collection, concurrency, f)
442
+ }
443
+ if (collection.constructor == Set) {
444
+ return setMapPool(collection, concurrency, f)
445
+ }
446
+ if (collection.constructor == Map) {
447
+ return mapMapPool(collection, concurrency, f)
448
+ }
449
+ if (collection.constructor == Object) {
450
+ return objectMapPool(collection, concurrency, f)
451
+ }
452
+ throw new TypeError(`invalid collection ${collection}`)
453
+ }
454
+
401
455
  /**
402
456
  * @name map.pool
403
457
  *
404
458
  * @synopsis
405
459
  * ```coffeescript [specscript]
460
+ * type Mappable = Array|Object|Set|Map
461
+ *
462
+ * map.pool(
463
+ * concurrency number,
464
+ * mapper (value any)=>Promise|any,
465
+ * )(collection Mappable) -> result Promise|Array
466
+ *
406
467
  * map.pool(
407
- * maxConcurrency number,
468
+ * collection Mappable,
469
+ * concurrency number,
408
470
  * mapper (value any)=>Promise|any,
409
- * )(array Array) -> result Promise|Array
471
+ * ) -> result Promise|Array
410
472
  * ```
411
473
  *
412
474
  * @description
413
- * `map` that specifies the maximum concurrency (number of ongoing promises at any time) of the execution. Only works for arrays.
475
+ * [map](/docs/map) with limited [concurrency](https://web.mit.edu/6.005/www/fa14/classes/17-concurrency/).
414
476
  *
415
477
  * ```javascript [playground]
416
478
  * const ids = [1, 2, 3, 4, 5]
@@ -428,15 +490,26 @@ map.series = function mapSeries(arg0, arg1) {
428
490
  * ]))(ids)
429
491
  * ```
430
492
  *
493
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
494
+ *
495
+ * ```javascript [playground]
496
+ * const asyncSquare = async n => n ** 2
497
+ *
498
+ * map.pool(Promise.resolve([1, 2, 3, 4, 5]), 5, asyncSquare).then(console.log)
499
+ * // [1, 4, 9, 16, 25]
500
+ * ```
501
+ *
431
502
  * @TODO objectMapPool
432
503
  *
433
504
  * @execution concurrent
434
505
  */
435
- map.pool = (concurrencyLimit, mapper) => function concurrentPoolMapping(value) {
436
- if (isArray(value)) {
437
- return arrayMapPool(value, mapper, concurrencyLimit)
506
+ map.pool = function mapPool(arg0, arg1, arg2) {
507
+ if (arg2 == null) {
508
+ return curry3(_mapPool, __, arg0, arg1)
438
509
  }
439
- throw new TypeError(`${value} is not an Array`)
510
+ return isPromise(arg0)
511
+ ? arg0.then(curry3(_mapPool, __, arg1, arg2))
512
+ : _mapPool(arg0, arg1, arg2)
440
513
  }
441
514
 
442
515
  module.exports = map
package/not.js CHANGED
@@ -45,6 +45,14 @@ const _not = function (args, predicate) {
45
45
  * not(isOdd)(3),
46
46
  * ) // false
47
47
  * ```
48
+ *
49
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
50
+ *
51
+ * ```javascript [playground]
52
+ * const isOdd = number => number % 2 == 1
53
+ *
54
+ * not(Promise.resolve(3), isOdd).then(console.log) // false
55
+ * ```
48
56
  */
49
57
 
50
58
  const not = function (...args) {
package/omit.js CHANGED
@@ -62,6 +62,13 @@ const _omit = function (source, paths) {
62
62
  * console.log, // { c: 9 }
63
63
  * ])
64
64
  * ```
65
+ *
66
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
67
+ *
68
+ * ```javascript [playground]
69
+ * omit(Promise.resolve({ a: 1, b: 2, c: 3 }), ['a', 'b']).then(console.log)
70
+ * // { c: 3 }
71
+ * ```
65
72
  */
66
73
  const omit = function (arg0, arg1) {
67
74
  if (arg1 == null) {
package/or.js CHANGED
@@ -129,6 +129,15 @@ const areAnyPredicatesTruthy = function (args, predicates) {
129
129
  * ) // true
130
130
  * ```
131
131
  *
132
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
133
+ *
134
+ * ```javascript [playground]
135
+ * or(Promise.resolve('aaa'), [
136
+ * s => s.startsWith('b'),
137
+ * s => s.endsWith('a'),
138
+ * ]).then(console.log) // true
139
+ * ```
140
+ *
132
141
  * @execution series
133
142
  *
134
143
  * @note ...args slows down here by an order of magnitude
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubico",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
4
4
  "description": "[a]synchronous functional programming",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
package/pick.js CHANGED
@@ -62,6 +62,13 @@ const _pick = function (source, keys) {
62
62
  * console.log, // { a: 1, c: 9 }
63
63
  * ])
64
64
  * ```
65
+ *
66
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
67
+ *
68
+ * ```javascript [playground]
69
+ * pick(Promise.resolve({ a: 1, b: 2, c: 3 }), ['a', 'b']).then(console.log)
70
+ * // { a: 1, b: 2 }
71
+ * ```
65
72
  */
66
73
  const pick = function (arg0, arg1) {
67
74
  if (arg1 == null) {
package/pipe.js CHANGED
@@ -46,6 +46,14 @@ const __ = require('./_internal/placeholder')
46
46
  * ])
47
47
  * ```
48
48
  *
49
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
50
+ *
51
+ * ```javascript [playground]
52
+ * pipe(Promise.resolve(1), 2, Promise.resolve(3), [
53
+ * console.log, // [1, 2, 3]
54
+ * ])
55
+ * ```
56
+ *
49
57
  * @execution series
50
58
  *
51
59
  * @transducing
package/reduce.js CHANGED
@@ -172,6 +172,14 @@ const _reduce = function (collection, reducer, initialValue) {
172
172
  * reduce(asyncAdd)(asyncGenerate12345()).then(console.log) // 15
173
173
  * ```
174
174
  *
175
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
176
+ *
177
+ * ```javascript [playground]
178
+ * const add = (a, b) => a + b
179
+ *
180
+ * reduce(Promise.resolve([1, 2, 3, 4, 5]), add, 0).then(console.log) // 15
181
+ * ```
182
+ *
175
183
  * @execution series
176
184
  *
177
185
  * @transducing
package/set.js CHANGED
@@ -90,6 +90,12 @@ const _set = function (obj, path, value) {
90
90
  * ])
91
91
  * ```
92
92
  *
93
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
94
+ *
95
+ * ```javascript [playground]
96
+ * set(Promise.resolve({}), 'a', 1).then(console.log) // { a: 1 }
97
+ * ```
98
+ *
93
99
  * @since 1.7.0
94
100
  */
95
101
 
package/some.js CHANGED
@@ -92,6 +92,12 @@ const _some = function (collection, predicate) {
92
92
  * ])
93
93
  * ```
94
94
  *
95
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
96
+ *
97
+ * ```javascript [playground]
98
+ * some(Promise.resolve([1, 2, 3, 4, 5]), n => n > 6).then(console.log) // false
99
+ * ```
100
+ *
95
101
  * @execution concurrent
96
102
  *
97
103
  * @muxing
package/switchCase.js CHANGED
@@ -79,6 +79,18 @@ const curryArgs3 = require('./_internal/curryArgs3')
79
79
  * console.log(myDrink) // Beer
80
80
  * ```
81
81
  *
82
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
83
+ *
84
+ * ```javascript [playground]
85
+ * switchCase(Promise.resolve(1), 2, Promise.resolve(3), [
86
+ * function doValuesAddUpTo6(a, b, c) {
87
+ * return a + b + c == 6
88
+ * },
89
+ * (a, b, c) => console.log(`${a} + ${b} + ${c} == 6`),
90
+ * (a, b, c) => console.log(`${a} + ${b} + ${c} != 6`),
91
+ * ]) // 1 + 2 + 3 == 6
92
+ * ```
93
+ *
82
94
  * @execution series
83
95
  */
84
96
  const switchCase = (...args) => {
package/tap.js CHANGED
@@ -2,14 +2,18 @@ const isPromise = require('./_internal/isPromise')
2
2
  const always = require('./_internal/always')
3
3
  const thunkifyArgs = require('./_internal/thunkifyArgs')
4
4
  const thunkConditional = require('./_internal/thunkConditional')
5
+ const curry2 = require('./_internal/curry2')
5
6
  const curry3 = require('./_internal/curry3')
6
7
  const curryArgs2 = require('./_internal/curryArgs2')
8
+ const curryArgs3 = require('./_internal/curryArgs3')
7
9
  const __ = require('./_internal/placeholder')
10
+ const areAnyValuesPromises = require('./_internal/areAnyValuesPromises')
11
+ const promiseAll = require('./_internal/promiseAll')
8
12
 
9
- // _tap(args Array, func function) -> Promise|any
10
- const _tap = function (args, func) {
13
+ // _tap(args Array, f function) -> Promise|any
14
+ const _tap = function (args, f) {
11
15
  const result = args[0],
12
- call = func(...args)
16
+ call = f(...args)
13
17
  return isPromise(call) ? call.then(always(result)) : result
14
18
  }
15
19
 
@@ -18,8 +22,8 @@ const _tap = function (args, func) {
18
22
  *
19
23
  * @synopsis
20
24
  * ```coffeescript [specscript]
21
- * tap(...args, func function) -> Promise|args[0]
22
- * tap(func function)(...args) -> Promise|args[0]
25
+ * tap(...args, f function) -> Promise|args[0]
26
+ * tap(f function)(...args) -> Promise|args[0]
23
27
  * ```
24
28
  *
25
29
  * @description
@@ -36,13 +40,53 @@ const _tap = function (args, func) {
36
40
  * // 'foobar'
37
41
  * // 'foobarbaz'
38
42
  * ```
43
+ *
44
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
45
+ *
46
+ * ```javascript [playground]
47
+ * tap(Promise.resolve(1), Promise.resolve(2), 3, console.log) // 1 2 3
48
+ * ```
39
49
  */
40
50
  const tap = function (...args) {
41
- const func = args.pop()
51
+ const f = args.pop()
42
52
  if (args.length == 0) {
43
- return curryArgs2(_tap, __, func)
53
+ return curryArgs2(_tap, __, f)
54
+ }
55
+ if (areAnyValuesPromises(args)) {
56
+ return promiseAll(args).then(curry2(_tap, __, f))
57
+ }
58
+ return _tap(args, f)
59
+ }
60
+
61
+ /**
62
+ * @name _tapIf
63
+ *
64
+ * @synopsis
65
+ * ```coffeescript [specscript]
66
+ * _tapIf(
67
+ * predicate function,
68
+ * f function,
69
+ * args Array,
70
+ * ) -> Promise|args[0]
71
+ * ```
72
+ */
73
+ const _tapIf = function (predicate, f, args) {
74
+ const b = predicate(...args)
75
+ if (isPromise(b)) {
76
+ return b.then(curry3(
77
+ thunkConditional,
78
+ __,
79
+ thunkifyArgs(tap(f), args),
80
+ always(args[0]),
81
+ ))
44
82
  }
45
- return _tap(args, func)
83
+ if (b) {
84
+ const execution = f(...args)
85
+ if (isPromise(execution)) {
86
+ return execution.then(always(args[0]))
87
+ }
88
+ }
89
+ return args[0]
46
90
  }
47
91
 
48
92
  /**
@@ -50,37 +94,42 @@ const tap = function (...args) {
50
94
  *
51
95
  * @synopsis
52
96
  * ```coffeescript [specscript]
53
- * tap.if(predicate function, func function)(...args) -> Promise|args[0]
97
+ * tap.if(...args, predicate function, f function) -> Promise|args[0]
98
+ * tap.if(predicate function, f function)(...args) -> Promise|args[0]
54
99
  * ```
55
100
  *
56
101
  * @description
57
- * A version of `tap` that accepts a predicate function (a function that returns a boolean value) before the function to execute. Only executes the function if the predicate function tests true for the same arguments provided to the execution function.
102
+ * A version of `tap` that accepts a predicate function (a function that returns a boolean value) before the function `f` to execute. Only executes `f` if the predicate function tests true. The arguments are the same to both the predicate function and the function to execute `f`.
58
103
  *
59
104
  * ```javascript [playground]
60
105
  * const isOdd = number => number % 2 == 1
61
106
  *
62
- * const logIfOdd = tap.if(
63
- * isOdd,
64
- * number => console.log(number, 'is an odd number')
65
- * )
107
+ * const logIfOdd = tap.if(isOdd, console.log)
66
108
  *
67
109
  * logIfOdd(2)
68
- * logIfOdd(3) // 3 is an odd number
110
+ * logIfOdd(3) // 3
111
+ * ```
112
+ *
113
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
114
+ *
115
+ * ```javascript [playground]
116
+ * tap.if(Promise.resolve(1), n => n < 5, console.log) // 1
117
+ * tap.if(Promise.resolve(6), n => n < 5, console.log)
69
118
  * ```
70
119
  */
71
- tap.if = (predicate, func) => function tappingIf(...args) {
72
- const predication = predicate(...args)
73
- if (isPromise(predication)) {
74
- return predication.then(curry3(
75
- thunkConditional, __, thunkifyArgs(tap(func), args), always(args[0])))
120
+
121
+ tap.if = function (...args) {
122
+ if (args.length == 2) {
123
+ return curryArgs3(_tapIf, args[0], args[1], __)
76
124
  }
77
- if (predication) {
78
- const execution = func(...args)
79
- if (isPromise(execution)) {
80
- return execution.then(always(args[0]))
81
- }
125
+ const argsLength = args.length
126
+ const f = args[argsLength - 1]
127
+ const predicate = args[argsLength - 2]
128
+ const argValues = args.slice(0, -2)
129
+ if (areAnyValuesPromises(argValues)) {
130
+ return promiseAll(argValues).then(curry3(_tapIf, predicate, f, __))
82
131
  }
83
- return args[0]
132
+ return _tapIf(predicate, f, args)
84
133
  }
85
134
 
86
135
  module.exports = tap
package/transform.js CHANGED
@@ -115,10 +115,9 @@ const _transform = function (collection, transducer, initialValue) {
115
115
  *
116
116
  * `transform` an async generator into `process.stdout`, a Node.js writable stream that implements `.write`.
117
117
  *
118
- * ```javascript [node]
119
- * // this example is duplicated in rubico/examples/transformStreamRandomInts.js
120
- *
121
- * const { pipe, map, transform } = require('rubico')
118
+ * ```javascript [playground]
119
+ * const { pipe, compose, transform } = rubico
120
+ * // global Transducer
122
121
  *
123
122
  * const square = number => number ** 2
124
123
  *
@@ -126,17 +125,46 @@ const _transform = function (collection, transducer, initialValue) {
126
125
  *
127
126
  * const randomInt = () => Math.ceil(Math.random() * 100)
128
127
  *
129
- * const streamRandomInts = async function* () {
130
- * while (true) {
128
+ * const streamRandomInts = async function* (n) {
129
+ * let ct = 0
130
+ * while (ct < n) {
131
+ * ct += 1
131
132
  * yield randomInt()
132
133
  * }
133
134
  * }
134
135
  *
136
+ * const Stdout = {
137
+ * concat(...args) {
138
+ * console.log(...args)
139
+ * return this
140
+ * },
141
+ * }
142
+ *
143
+ * transform(
144
+ * streamRandomInts(10),
145
+ * compose([
146
+ * Transducer.map(square),
147
+ * Transducer.map(toString),
148
+ * ]),
149
+ * Stdout,
150
+ * )
151
+ * // 8281
152
+ * // 8836
153
+ * // 1156
154
+ * // 8649
155
+ * // 5625
156
+ * // 2500
157
+ * // ...
158
+ * ```
159
+ *
160
+ * 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
+ *
162
+ * ```javascript [playground]
135
163
  * transform(
136
- * streamRandomInts(),
137
- * Transducer.map(pipe([square, toString])),
138
- * process.stdout,
139
- * ) // 9216576529289484980147613249169774446246768649...
164
+ * Promise.resolve([1, 2, 3, 4, 5]),
165
+ * Transducer.map(n => n ** 2),
166
+ * [],
167
+ * ).then(console.log) // [1, 4, 9, 16, 25]
140
168
  * ```
141
169
  *
142
170
  * @execution series
package/tryCatch.js CHANGED
@@ -61,6 +61,20 @@ const _tryCatch = function (tryer, catcher, args) {
61
61
  * console.error(error.message) // the sum is 6
62
62
  * })
63
63
  * ```
64
+ *
65
+ * Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
66
+ *
67
+ * ```javascript [playground]
68
+ * tryCatch(Promise.resolve(1), 2, Promise.resolve(3), (a, b, c) => {
69
+ * const sum = a + b + c
70
+ * if (sum > 5) {
71
+ * throw new Error('limit exceeded')
72
+ * }
73
+ * console.log('sum:', sum)
74
+ * }, (error, a, b, c) => {
75
+ * console.error(`${a} + ${b} + ${c}: ${error.message}`)
76
+ * })
77
+ * ```
64
78
  */
65
79
 
66
80
  const tryCatch = function (...args) {