rubico 2.6.0 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/_internal/areAllValuesNonfunctions.js +16 -4
  2. package/_internal/areAnyValuesPromises.js +16 -4
  3. package/_internal/functionArrayAll.js +2 -1
  4. package/_internal/functionObjectAll.js +2 -1
  5. package/all.js +101 -22
  6. package/assign.js +19 -3
  7. package/dist/Transducer.es.js +1 -1
  8. package/dist/Transducer.es.min.js +1 -1
  9. package/dist/Transducer.js +1 -1
  10. package/dist/Transducer.min.js +1 -1
  11. package/dist/Transducer.mjs +1 -1
  12. package/dist/__.es.js +1 -1
  13. package/dist/__.es.min.js +1 -1
  14. package/dist/__.js +1 -1
  15. package/dist/__.min.js +1 -1
  16. package/dist/__.mjs +1 -1
  17. package/dist/all.es.js +107 -8
  18. package/dist/all.es.min.js +2 -2
  19. package/dist/all.js +107 -8
  20. package/dist/all.min.js +2 -2
  21. package/dist/all.mjs +107 -8
  22. package/dist/always.es.js +1 -1
  23. package/dist/always.es.min.js +1 -1
  24. package/dist/always.js +1 -1
  25. package/dist/always.min.js +1 -1
  26. package/dist/always.mjs +1 -1
  27. package/dist/and.es.js +30 -9
  28. package/dist/and.es.min.js +2 -2
  29. package/dist/and.js +30 -9
  30. package/dist/and.min.js +2 -2
  31. package/dist/and.mjs +30 -9
  32. package/dist/assign.es.js +3 -2
  33. package/dist/assign.es.min.js +2 -2
  34. package/dist/assign.js +3 -2
  35. package/dist/assign.min.js +2 -2
  36. package/dist/assign.mjs +3 -2
  37. package/dist/compose.es.js +17 -5
  38. package/dist/compose.es.min.js +2 -2
  39. package/dist/compose.js +17 -5
  40. package/dist/compose.min.js +2 -2
  41. package/dist/compose.mjs +17 -5
  42. package/dist/curry.es.js +1 -1
  43. package/dist/curry.es.min.js +1 -1
  44. package/dist/curry.js +1 -1
  45. package/dist/curry.min.js +1 -1
  46. package/dist/curry.mjs +1 -1
  47. package/dist/eq.es.js +17 -5
  48. package/dist/eq.es.min.js +2 -2
  49. package/dist/eq.js +17 -5
  50. package/dist/eq.min.js +2 -2
  51. package/dist/eq.mjs +17 -5
  52. package/dist/every.es.js +1 -1
  53. package/dist/every.es.min.js +1 -1
  54. package/dist/every.js +1 -1
  55. package/dist/every.min.js +1 -1
  56. package/dist/every.mjs +1 -1
  57. package/dist/filter.es.js +1 -1
  58. package/dist/filter.es.min.js +1 -1
  59. package/dist/filter.js +1 -1
  60. package/dist/filter.min.js +1 -1
  61. package/dist/filter.mjs +1 -1
  62. package/dist/flatMap.es.js +1 -1
  63. package/dist/flatMap.es.min.js +1 -1
  64. package/dist/flatMap.js +1 -1
  65. package/dist/flatMap.min.js +1 -1
  66. package/dist/flatMap.mjs +1 -1
  67. package/dist/forEach.es.js +1 -1
  68. package/dist/forEach.es.min.js +1 -1
  69. package/dist/forEach.js +1 -1
  70. package/dist/forEach.min.js +1 -1
  71. package/dist/forEach.mjs +1 -1
  72. package/dist/get.es.js +1 -1
  73. package/dist/get.es.min.js +1 -1
  74. package/dist/get.js +1 -1
  75. package/dist/get.min.js +1 -1
  76. package/dist/get.mjs +1 -1
  77. package/dist/gt.es.js +17 -5
  78. package/dist/gt.es.min.js +2 -2
  79. package/dist/gt.js +17 -5
  80. package/dist/gt.min.js +2 -2
  81. package/dist/gt.mjs +17 -5
  82. package/dist/gte.es.js +17 -5
  83. package/dist/gte.es.min.js +2 -2
  84. package/dist/gte.js +17 -5
  85. package/dist/gte.min.js +2 -2
  86. package/dist/gte.mjs +17 -5
  87. package/dist/lt.es.js +17 -5
  88. package/dist/lt.es.min.js +2 -2
  89. package/dist/lt.js +17 -5
  90. package/dist/lt.min.js +2 -2
  91. package/dist/lt.mjs +17 -5
  92. package/dist/lte.es.js +17 -5
  93. package/dist/lte.es.min.js +2 -2
  94. package/dist/lte.js +17 -5
  95. package/dist/lte.min.js +2 -2
  96. package/dist/lte.mjs +17 -5
  97. package/dist/map.es.js +1 -1
  98. package/dist/map.es.min.js +1 -1
  99. package/dist/map.js +1 -1
  100. package/dist/map.min.js +1 -1
  101. package/dist/map.mjs +1 -1
  102. package/dist/not.es.js +17 -5
  103. package/dist/not.es.min.js +2 -2
  104. package/dist/not.js +17 -5
  105. package/dist/not.min.js +2 -2
  106. package/dist/not.mjs +17 -5
  107. package/dist/omit.es.js +1 -1
  108. package/dist/omit.es.min.js +1 -1
  109. package/dist/omit.js +1 -1
  110. package/dist/omit.min.js +1 -1
  111. package/dist/omit.mjs +1 -1
  112. package/dist/or.es.js +30 -9
  113. package/dist/or.es.min.js +2 -2
  114. package/dist/or.js +30 -9
  115. package/dist/or.min.js +2 -2
  116. package/dist/or.mjs +30 -9
  117. package/dist/pick.es.js +1 -1
  118. package/dist/pick.es.min.js +1 -1
  119. package/dist/pick.js +1 -1
  120. package/dist/pick.min.js +1 -1
  121. package/dist/pick.mjs +1 -1
  122. package/dist/pipe.es.js +17 -5
  123. package/dist/pipe.es.min.js +2 -2
  124. package/dist/pipe.js +17 -5
  125. package/dist/pipe.min.js +2 -2
  126. package/dist/pipe.mjs +17 -5
  127. package/dist/reduce.es.js +1 -1
  128. package/dist/reduce.es.min.js +1 -1
  129. package/dist/reduce.js +1 -1
  130. package/dist/reduce.min.js +1 -1
  131. package/dist/reduce.mjs +1 -1
  132. package/dist/rubico.es.js +170 -89
  133. package/dist/rubico.es.min.js +2 -2
  134. package/dist/rubico.global.js +170 -89
  135. package/dist/rubico.global.min.js +2 -2
  136. package/dist/rubico.js +170 -89
  137. package/dist/rubico.min.js +2 -2
  138. package/dist/rubico.mjs +170 -89
  139. package/dist/set.es.js +1 -1
  140. package/dist/set.es.min.js +1 -1
  141. package/dist/set.js +1 -1
  142. package/dist/set.min.js +1 -1
  143. package/dist/set.mjs +1 -1
  144. package/dist/some.es.js +1 -1
  145. package/dist/some.es.min.js +1 -1
  146. package/dist/some.js +1 -1
  147. package/dist/some.min.js +1 -1
  148. package/dist/some.mjs +1 -1
  149. package/dist/switchCase.es.js +30 -9
  150. package/dist/switchCase.es.min.js +2 -2
  151. package/dist/switchCase.js +30 -9
  152. package/dist/switchCase.min.js +2 -2
  153. package/dist/switchCase.mjs +30 -9
  154. package/dist/tap.es.js +80 -19
  155. package/dist/tap.es.min.js +2 -2
  156. package/dist/tap.js +80 -19
  157. package/dist/tap.min.js +2 -2
  158. package/dist/tap.mjs +80 -19
  159. package/dist/thunkify.es.js +17 -5
  160. package/dist/thunkify.es.min.js +2 -2
  161. package/dist/thunkify.js +17 -5
  162. package/dist/thunkify.min.js +2 -2
  163. package/dist/thunkify.mjs +17 -5
  164. package/dist/transform.es.js +1 -1
  165. package/dist/transform.es.min.js +1 -1
  166. package/dist/transform.js +1 -1
  167. package/dist/transform.min.js +1 -1
  168. package/dist/transform.mjs +1 -1
  169. package/dist/tryCatch.es.js +17 -5
  170. package/dist/tryCatch.es.min.js +2 -2
  171. package/dist/tryCatch.js +17 -5
  172. package/dist/tryCatch.min.js +2 -2
  173. package/dist/tryCatch.mjs +17 -5
  174. package/dist/x/append.es.js +1 -1
  175. package/dist/x/append.es.min.js +1 -1
  176. package/dist/x/append.js +1 -1
  177. package/dist/x/append.min.js +1 -1
  178. package/dist/x/append.mjs +1 -1
  179. package/dist/x/callProp.es.js +1 -1
  180. package/dist/x/callProp.es.min.js +1 -1
  181. package/dist/x/callProp.js +1 -1
  182. package/dist/x/callProp.min.js +1 -1
  183. package/dist/x/callProp.mjs +1 -1
  184. package/dist/x/defaultsDeep.es.js +1 -1
  185. package/dist/x/defaultsDeep.es.min.js +1 -1
  186. package/dist/x/defaultsDeep.js +1 -1
  187. package/dist/x/defaultsDeep.min.js +1 -1
  188. package/dist/x/defaultsDeep.mjs +1 -1
  189. package/dist/x/differenceWith.es.js +1 -1
  190. package/dist/x/differenceWith.es.min.js +1 -1
  191. package/dist/x/differenceWith.js +1 -1
  192. package/dist/x/differenceWith.min.js +1 -1
  193. package/dist/x/differenceWith.mjs +1 -1
  194. package/dist/x/filterOut.es.js +15 -5
  195. package/dist/x/filterOut.es.min.js +2 -2
  196. package/dist/x/filterOut.js +15 -5
  197. package/dist/x/filterOut.min.js +2 -2
  198. package/dist/x/filterOut.mjs +15 -5
  199. package/dist/x/find.es.js +1 -1
  200. package/dist/x/find.es.min.js +1 -1
  201. package/dist/x/find.js +1 -1
  202. package/dist/x/find.min.js +1 -1
  203. package/dist/x/find.mjs +1 -1
  204. package/dist/x/findIndex.es.js +1 -1
  205. package/dist/x/findIndex.es.min.js +1 -1
  206. package/dist/x/findIndex.js +1 -1
  207. package/dist/x/findIndex.min.js +1 -1
  208. package/dist/x/findIndex.mjs +1 -1
  209. package/dist/x/first.es.js +1 -1
  210. package/dist/x/first.es.min.js +1 -1
  211. package/dist/x/first.js +1 -1
  212. package/dist/x/first.min.js +1 -1
  213. package/dist/x/first.mjs +1 -1
  214. package/dist/x/flatten.es.js +1 -1
  215. package/dist/x/flatten.es.min.js +1 -1
  216. package/dist/x/flatten.js +1 -1
  217. package/dist/x/flatten.min.js +1 -1
  218. package/dist/x/flatten.mjs +1 -1
  219. package/dist/x/groupBy.es.js +1 -1
  220. package/dist/x/groupBy.es.min.js +1 -1
  221. package/dist/x/groupBy.js +1 -1
  222. package/dist/x/groupBy.min.js +1 -1
  223. package/dist/x/groupBy.mjs +1 -1
  224. package/dist/x/has.es.js +1 -1
  225. package/dist/x/has.es.min.js +1 -1
  226. package/dist/x/has.js +1 -1
  227. package/dist/x/has.min.js +1 -1
  228. package/dist/x/has.mjs +1 -1
  229. package/dist/x/identity.es.js +1 -1
  230. package/dist/x/identity.es.min.js +1 -1
  231. package/dist/x/identity.js +1 -1
  232. package/dist/x/identity.min.js +1 -1
  233. package/dist/x/identity.mjs +1 -1
  234. package/dist/x/includes.es.js +1 -1
  235. package/dist/x/includes.es.min.js +1 -1
  236. package/dist/x/includes.js +1 -1
  237. package/dist/x/includes.min.js +1 -1
  238. package/dist/x/includes.mjs +1 -1
  239. package/dist/x/isDeepEqual.es.js +1 -1
  240. package/dist/x/isDeepEqual.es.min.js +1 -1
  241. package/dist/x/isDeepEqual.js +1 -1
  242. package/dist/x/isDeepEqual.min.js +1 -1
  243. package/dist/x/isDeepEqual.mjs +1 -1
  244. package/dist/x/isEmpty.es.js +1 -1
  245. package/dist/x/isEmpty.es.min.js +1 -1
  246. package/dist/x/isEmpty.js +1 -1
  247. package/dist/x/isEmpty.min.js +1 -1
  248. package/dist/x/isEmpty.mjs +1 -1
  249. package/dist/x/isEqual.es.js +1 -1
  250. package/dist/x/isEqual.es.min.js +1 -1
  251. package/dist/x/isEqual.js +1 -1
  252. package/dist/x/isEqual.min.js +1 -1
  253. package/dist/x/isEqual.mjs +1 -1
  254. package/dist/x/isFunction.es.js +1 -1
  255. package/dist/x/isFunction.es.min.js +1 -1
  256. package/dist/x/isFunction.js +1 -1
  257. package/dist/x/isFunction.min.js +1 -1
  258. package/dist/x/isFunction.mjs +1 -1
  259. package/dist/x/isIn.es.js +1 -1
  260. package/dist/x/isIn.es.min.js +1 -1
  261. package/dist/x/isIn.js +1 -1
  262. package/dist/x/isIn.min.js +1 -1
  263. package/dist/x/isIn.mjs +1 -1
  264. package/dist/x/isObject.es.js +1 -1
  265. package/dist/x/isObject.es.min.js +1 -1
  266. package/dist/x/isObject.js +1 -1
  267. package/dist/x/isObject.min.js +1 -1
  268. package/dist/x/isObject.mjs +1 -1
  269. package/dist/x/isString.es.js +1 -1
  270. package/dist/x/isString.es.min.js +1 -1
  271. package/dist/x/isString.js +1 -1
  272. package/dist/x/isString.min.js +1 -1
  273. package/dist/x/isString.mjs +1 -1
  274. package/dist/x/keys.es.js +1 -1
  275. package/dist/x/keys.es.min.js +1 -1
  276. package/dist/x/keys.js +1 -1
  277. package/dist/x/keys.min.js +1 -1
  278. package/dist/x/keys.mjs +1 -1
  279. package/dist/x/last.es.js +1 -1
  280. package/dist/x/last.es.min.js +1 -1
  281. package/dist/x/last.js +1 -1
  282. package/dist/x/last.min.js +1 -1
  283. package/dist/x/last.mjs +1 -1
  284. package/dist/x/maxBy.es.js +1 -1
  285. package/dist/x/maxBy.es.min.js +1 -1
  286. package/dist/x/maxBy.js +1 -1
  287. package/dist/x/maxBy.min.js +1 -1
  288. package/dist/x/maxBy.mjs +1 -1
  289. package/dist/x/noop.es.js +1 -1
  290. package/dist/x/noop.es.min.js +1 -1
  291. package/dist/x/noop.js +1 -1
  292. package/dist/x/noop.min.js +1 -1
  293. package/dist/x/noop.mjs +1 -1
  294. package/dist/x/pluck.es.js +1 -1
  295. package/dist/x/pluck.es.min.js +1 -1
  296. package/dist/x/pluck.js +1 -1
  297. package/dist/x/pluck.min.js +1 -1
  298. package/dist/x/pluck.mjs +1 -1
  299. package/dist/x/prepend.es.js +1 -1
  300. package/dist/x/prepend.es.min.js +1 -1
  301. package/dist/x/prepend.js +1 -1
  302. package/dist/x/prepend.min.js +1 -1
  303. package/dist/x/prepend.mjs +1 -1
  304. package/dist/x/size.es.js +1 -1
  305. package/dist/x/size.es.min.js +1 -1
  306. package/dist/x/size.js +1 -1
  307. package/dist/x/size.min.js +1 -1
  308. package/dist/x/size.mjs +1 -1
  309. package/dist/x/trace.es.js +82 -21
  310. package/dist/x/trace.es.min.js +2 -2
  311. package/dist/x/trace.js +82 -21
  312. package/dist/x/trace.min.js +2 -2
  313. package/dist/x/trace.mjs +82 -21
  314. package/dist/x/unionWith.es.js +1 -1
  315. package/dist/x/unionWith.es.min.js +1 -1
  316. package/dist/x/unionWith.js +1 -1
  317. package/dist/x/unionWith.min.js +1 -1
  318. package/dist/x/unionWith.mjs +1 -1
  319. package/dist/x/uniq.es.js +1 -1
  320. package/dist/x/uniq.es.min.js +1 -1
  321. package/dist/x/uniq.js +1 -1
  322. package/dist/x/uniq.min.js +1 -1
  323. package/dist/x/uniq.mjs +1 -1
  324. package/dist/x/unless.es.js +1 -1
  325. package/dist/x/unless.es.min.js +1 -1
  326. package/dist/x/unless.js +1 -1
  327. package/dist/x/unless.min.js +1 -1
  328. package/dist/x/unless.mjs +1 -1
  329. package/dist/x/values.es.js +1 -1
  330. package/dist/x/values.es.min.js +1 -1
  331. package/dist/x/values.js +1 -1
  332. package/dist/x/values.min.js +1 -1
  333. package/dist/x/values.mjs +1 -1
  334. package/dist/x/when.es.js +1 -1
  335. package/dist/x/when.es.min.js +1 -1
  336. package/dist/x/when.js +1 -1
  337. package/dist/x/when.min.js +1 -1
  338. package/dist/x/when.mjs +1 -1
  339. package/es.js +170 -89
  340. package/index.js +170 -89
  341. package/package.json +1 -1
  342. package/tap.js +66 -28
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * rubico v2.6.0
2
+ * rubico v2.6.2
3
3
  * https://github.com/a-synchronous/rubico
4
4
  * (c) 2019-2024 Richard Tong
5
5
  * rubico may be freely distributed under the MIT license.
@@ -11,13 +11,25 @@
11
11
  else (root.rubico = rubico) // Browser
12
12
  }(typeof globalThis == 'object' ? globalThis : this, (function () { 'use strict'
13
13
 
14
+ const isArray = Array.isArray
15
+
14
16
  const isPromise = value => value != null && typeof value.then == 'function'
15
17
 
16
18
  const areAnyValuesPromises = function (values) {
17
- const length = values.length
18
- let index = -1
19
- while (++index < length) {
20
- const value = values[index]
19
+ if (isArray(values)) {
20
+ const length = values.length
21
+ let index = -1
22
+ while (++index < length) {
23
+ const value = values[index]
24
+ if (isPromise(value)) {
25
+ return true
26
+ }
27
+ }
28
+ return false
29
+ }
30
+
31
+ for (const key in values) {
32
+ const value = values[key]
21
33
  if (isPromise(value)) {
22
34
  return true
23
35
  }
@@ -152,32 +164,67 @@ const curryArgs2 = function (baseFunc, arg0, arg1) {
152
164
  return curryArgs2ResolveArgs1(baseFunc, arg0)
153
165
  }
154
166
 
155
- // _tap(args Array, func function) -> Promise|any
156
- const _tap = function (args, func) {
167
+ // argument resolver for curryArgs3
168
+ const curryArgs3ResolveArgs0 = (
169
+ baseFunc, arg1, arg2,
170
+ ) => function args0Resolver(...args) {
171
+ return baseFunc(args, arg1, arg2)
172
+ }
173
+
174
+ // argument resolver for curryArgs3
175
+ const curryArgs3ResolveArgs1 = (
176
+ baseFunc, arg0, arg2,
177
+ ) => function arg1Resolver(...args) {
178
+ return baseFunc(arg0, args, arg2)
179
+ }
180
+
181
+ // argument resolver for curryArgs3
182
+ const curryArgs3ResolveArgs2 = (
183
+ baseFunc, arg0, arg1,
184
+ ) => function arg2Resolver(...args) {
185
+ return baseFunc(arg0, arg1, args)
186
+ }
187
+
188
+ const curryArgs3 = function (baseFunc, arg0, arg1, arg2) {
189
+ if (arg0 == __) {
190
+ return curryArgs3ResolveArgs0(baseFunc, arg1, arg2)
191
+ }
192
+ if (arg1 == __) {
193
+ return curryArgs3ResolveArgs1(baseFunc, arg0, arg2)
194
+ }
195
+ return curryArgs3ResolveArgs2(baseFunc, arg0, arg1)
196
+ }
197
+
198
+ // _tap(args Array, f function) -> Promise|any
199
+ const _tap = function (args, f) {
157
200
  const result = args[0],
158
- call = func(...args)
201
+ call = f(...args)
159
202
  return isPromise(call) ? call.then(always(result)) : result
160
203
  }
161
204
 
162
205
  const tap = function (...args) {
163
- const func = args.pop()
206
+ const f = args.pop()
164
207
  if (args.length == 0) {
165
- return curryArgs2(_tap, __, func)
208
+ return curryArgs2(_tap, __, f)
166
209
  }
167
210
  if (areAnyValuesPromises(args)) {
168
- return promiseAll(args).then(curry2(_tap, __, func))
211
+ return promiseAll(args).then(curry2(_tap, __, f))
169
212
  }
170
- return _tap(args, func)
213
+ return _tap(args, f)
171
214
  }
172
215
 
173
- tap.if = (predicate, func) => function tappingIf(...args) {
174
- const predication = predicate(...args)
175
- if (isPromise(predication)) {
176
- return predication.then(curry3(
177
- thunkConditional, __, thunkifyArgs(tap(func), args), always(args[0])))
216
+ const _tapIf = function (predicate, f, args) {
217
+ const b = predicate(...args)
218
+ if (isPromise(b)) {
219
+ return b.then(curry3(
220
+ thunkConditional,
221
+ __,
222
+ thunkifyArgs(tap(f), args),
223
+ always(args[0]),
224
+ ))
178
225
  }
179
- if (predication) {
180
- const execution = func(...args)
226
+ if (b) {
227
+ const execution = f(...args)
181
228
  if (isPromise(execution)) {
182
229
  return execution.then(always(args[0]))
183
230
  }
@@ -185,14 +232,72 @@ tap.if = (predicate, func) => function tappingIf(...args) {
185
232
  return args[0]
186
233
  }
187
234
 
188
- const isArray = Array.isArray
235
+ tap.if = function (...args) {
236
+ if (args.length == 2) {
237
+ return curryArgs3(_tapIf, args[0], args[1], __)
238
+ }
239
+ const argsLength = args.length
240
+ const f = args[argsLength - 1]
241
+ const predicate = args[argsLength - 2]
242
+ const argValues = args.slice(0, -2)
243
+ if (areAnyValuesPromises(argValues)) {
244
+ return promiseAll(argValues).then(curry3(_tapIf, predicate, f, __))
245
+ }
246
+ return _tapIf(predicate, f, args)
247
+ }
248
+
249
+ const areAllValuesNonfunctions = function (values) {
250
+ if (isArray(values)) {
251
+ const length = values.length
252
+ let index = -1
253
+ while (++index < length) {
254
+ if (typeof values[index] == 'function') {
255
+ return false
256
+ }
257
+ }
258
+ return true
259
+ }
260
+
261
+ for (const key in values) {
262
+ if (typeof values[key] == 'function') {
263
+ return false
264
+ }
265
+ }
266
+ return true
267
+ }
268
+
269
+ const promiseObjectAllExecutor = object => function executor(resolve) {
270
+ const result = {}
271
+ let numPromises = 0
272
+ for (const key in object) {
273
+ const value = object[key]
274
+ if (isPromise(value)) {
275
+ numPromises += 1
276
+ value.then((key => function (res) {
277
+ result[key] = res
278
+ numPromises -= 1
279
+ if (numPromises == 0) {
280
+ resolve(result)
281
+ }
282
+ })(key))
283
+ } else {
284
+ result[key] = value
285
+ }
286
+ }
287
+ if (numPromises == 0) {
288
+ resolve(result)
289
+ }
290
+ }
291
+
292
+ const promiseObjectAll = object => new Promise(promiseObjectAllExecutor(object))
189
293
 
190
294
  const functionArrayAll = function (funcs, args) {
191
295
  const funcsLength = funcs.length,
192
296
  result = Array(funcsLength)
193
297
  let funcsIndex = -1, isAsync = false
194
298
  while (++funcsIndex < funcsLength) {
195
- const resultItem = funcs[funcsIndex](...args)
299
+ const f = funcs[funcsIndex]
300
+ const resultItem = typeof f == 'function' ? f(...args) : f
196
301
  if (isPromise(resultItem)) {
197
302
  isAsync = true
198
303
  }
@@ -274,7 +379,8 @@ const functionArrayAllSeries = function (funcs, args) {
274
379
  const functionObjectAll = function (funcs, args) {
275
380
  const result = {}, promises = []
276
381
  for (const key in funcs) {
277
- const resultItem = funcs[key](...args)
382
+ const f = funcs[key]
383
+ const resultItem = typeof f == 'function' ? f(...args) : f
278
384
  if (isPromise(resultItem)) {
279
385
  promises.push(resultItem.then(curry3(objectSet, result, key, __)))
280
386
  } else {
@@ -284,7 +390,48 @@ const functionObjectAll = function (funcs, args) {
284
390
  return promises.length == 0 ? result : promiseAll(promises).then(always(result))
285
391
  }
286
392
 
393
+ const _allValues = function (values) {
394
+ if (isArray(values)) {
395
+ return areAnyValuesPromises(values)
396
+ ? promiseAll(values)
397
+ : values
398
+ }
399
+ return areAnyValuesPromises(values)
400
+ ? promiseObjectAll(values)
401
+ : values
402
+ }
403
+
287
404
  const all = function (...args) {
405
+ if (args.length == 1) {
406
+ const resolversOrValues = args[0]
407
+ if (isPromise(resolversOrValues)) {
408
+ return resolversOrValues.then(_allValues)
409
+ }
410
+ if (areAllValuesNonfunctions(resolversOrValues)) {
411
+ return _allValues(resolversOrValues)
412
+ }
413
+ return isArray(resolversOrValues)
414
+ ? curryArgs2(functionArrayAll, resolversOrValues, __)
415
+ : curryArgs2(functionObjectAll, resolversOrValues, __)
416
+ }
417
+
418
+ const resolversOrValues = args[args.length - 1]
419
+ const argValues = args.slice(0, -1)
420
+
421
+ if (areAnyValuesPromises(argValues)) {
422
+ return isArray(resolversOrValues)
423
+ ? promiseAll(argValues)
424
+ .then(curry2(functionArrayAll, resolversOrValues, __))
425
+ : promiseAll(argValues)
426
+ .then(curry2(functionObjectAll, resolversOrValues, __))
427
+ }
428
+
429
+ return isArray(resolversOrValues)
430
+ ? functionArrayAll(resolversOrValues, argValues)
431
+ : functionObjectAll(resolversOrValues, argValues)
432
+
433
+ /*
434
+ ////////////////////////////////////////////////////////////////
288
435
  const funcs = args.pop()
289
436
  if (args.length == 0) {
290
437
  return isArray(funcs)
@@ -301,6 +448,7 @@ const all = function (...args) {
301
448
  return isArray(funcs)
302
449
  ? functionArrayAll(funcs, args)
303
450
  : functionObjectAll(funcs, args)
451
+ */
304
452
  }
305
453
 
306
454
  all.series = function allSeries(...args) {
@@ -411,17 +559,6 @@ const arrayConditional = function (array, args, funcsIndex) {
411
559
  : defaultResolverOrValue
412
560
  }
413
561
 
414
- const areAllValuesNonfunctions = function (values) {
415
- const length = values.length
416
- let index = -1
417
- while (++index < length) {
418
- if (typeof values[index] == 'function') {
419
- return false
420
- }
421
- }
422
- return true
423
- }
424
-
425
562
  const thunkify2 = (func, arg0, arg1) => function thunk() {
426
563
  return func(arg0, arg1)
427
564
  }
@@ -451,37 +588,6 @@ const nonfunctionsConditional = function (array, index) {
451
588
  return array[index]
452
589
  }
453
590
 
454
- // argument resolver for curryArgs3
455
- const curryArgs3ResolveArgs0 = (
456
- baseFunc, arg1, arg2,
457
- ) => function args0Resolver(...args) {
458
- return baseFunc(args, arg1, arg2)
459
- }
460
-
461
- // argument resolver for curryArgs3
462
- const curryArgs3ResolveArgs1 = (
463
- baseFunc, arg0, arg2,
464
- ) => function arg1Resolver(...args) {
465
- return baseFunc(arg0, args, arg2)
466
- }
467
-
468
- // argument resolver for curryArgs3
469
- const curryArgs3ResolveArgs2 = (
470
- baseFunc, arg0, arg1,
471
- ) => function arg2Resolver(...args) {
472
- return baseFunc(arg0, arg1, args)
473
- }
474
-
475
- const curryArgs3 = function (baseFunc, arg0, arg1, arg2) {
476
- if (arg0 == __) {
477
- return curryArgs3ResolveArgs0(baseFunc, arg1, arg2)
478
- }
479
- if (arg1 == __) {
480
- return curryArgs3ResolveArgs1(baseFunc, arg0, arg2)
481
- }
482
- return curryArgs3ResolveArgs2(baseFunc, arg0, arg1)
483
- }
484
-
485
591
  const switchCase = (...args) => {
486
592
  const values = args.pop()
487
593
  if (areAllValuesNonfunctions(values)) {
@@ -601,31 +707,6 @@ const mapMap = function (value, mapper) {
601
707
  : promiseAll(promises).then(always(result))
602
708
  }
603
709
 
604
- const promiseObjectAllExecutor = object => function executor(resolve) {
605
- const result = {}
606
- let numPromises = 0
607
- for (const key in object) {
608
- const value = object[key]
609
- if (isPromise(value)) {
610
- numPromises += 1
611
- value.then((key => function (res) {
612
- result[key] = res
613
- numPromises -= 1
614
- if (numPromises == 0) {
615
- resolve(result)
616
- }
617
- })(key))
618
- } else {
619
- result[key] = value
620
- }
621
- }
622
- if (numPromises == 0) {
623
- resolve(result)
624
- }
625
- }
626
-
627
- const promiseObjectAll = object => new Promise(promiseObjectAllExecutor(object))
628
-
629
710
  const objectMap = function (object, mapper) {
630
711
  const result = {}
631
712
  let isAsync = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubico",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
4
4
  "description": "[a]synchronous functional programming",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
package/tap.js CHANGED
@@ -5,14 +5,15 @@ const thunkConditional = require('./_internal/thunkConditional')
5
5
  const curry2 = require('./_internal/curry2')
6
6
  const curry3 = require('./_internal/curry3')
7
7
  const curryArgs2 = require('./_internal/curryArgs2')
8
+ const curryArgs3 = require('./_internal/curryArgs3')
8
9
  const __ = require('./_internal/placeholder')
9
10
  const areAnyValuesPromises = require('./_internal/areAnyValuesPromises')
10
11
  const promiseAll = require('./_internal/promiseAll')
11
12
 
12
- // _tap(args Array, func function) -> Promise|any
13
- const _tap = function (args, func) {
13
+ // _tap(args Array, f function) -> Promise|any
14
+ const _tap = function (args, f) {
14
15
  const result = args[0],
15
- call = func(...args)
16
+ call = f(...args)
16
17
  return isPromise(call) ? call.then(always(result)) : result
17
18
  }
18
19
 
@@ -21,8 +22,8 @@ const _tap = function (args, func) {
21
22
  *
22
23
  * @synopsis
23
24
  * ```coffeescript [specscript]
24
- * tap(...args, func function) -> Promise|args[0]
25
- * tap(func function)(...args) -> Promise|args[0]
25
+ * tap(...args, f function) -> Promise|args[0]
26
+ * tap(f function)(...args) -> Promise|args[0]
26
27
  * ```
27
28
  *
28
29
  * @description
@@ -41,19 +42,51 @@ const _tap = function (args, func) {
41
42
  * ```
42
43
  *
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
+ *
44
46
  * ```javascript [playground]
45
- * tap(Promise.resolve(1), Promise.resolve(2), 3, console.log) // 1, 2, 3
47
+ * tap(Promise.resolve(1), Promise.resolve(2), 3, console.log) // 1 2 3
46
48
  * ```
47
49
  */
48
50
  const tap = function (...args) {
49
- const func = args.pop()
51
+ const f = args.pop()
50
52
  if (args.length == 0) {
51
- return curryArgs2(_tap, __, func)
53
+ return curryArgs2(_tap, __, f)
52
54
  }
53
55
  if (areAnyValuesPromises(args)) {
54
- return promiseAll(args).then(curry2(_tap, __, func))
56
+ return promiseAll(args).then(curry2(_tap, __, f))
55
57
  }
56
- return _tap(args, func)
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
+ ))
82
+ }
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]
57
90
  }
58
91
 
59
92
  /**
@@ -61,37 +94,42 @@ const tap = function (...args) {
61
94
  *
62
95
  * @synopsis
63
96
  * ```coffeescript [specscript]
64
- * 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]
65
99
  * ```
66
100
  *
67
101
  * @description
68
- * 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`.
69
103
  *
70
104
  * ```javascript [playground]
71
105
  * const isOdd = number => number % 2 == 1
72
106
  *
73
- * const logIfOdd = tap.if(
74
- * isOdd,
75
- * number => console.log(number, 'is an odd number')
76
- * )
107
+ * const logIfOdd = tap.if(isOdd, console.log)
77
108
  *
78
109
  * logIfOdd(2)
79
- * 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)
80
118
  * ```
81
119
  */
82
- tap.if = (predicate, func) => function tappingIf(...args) {
83
- const predication = predicate(...args)
84
- if (isPromise(predication)) {
85
- return predication.then(curry3(
86
- 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], __)
87
124
  }
88
- if (predication) {
89
- const execution = func(...args)
90
- if (isPromise(execution)) {
91
- return execution.then(always(args[0]))
92
- }
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, __))
93
131
  }
94
- return args[0]
132
+ return _tapIf(predicate, f, args)
95
133
  }
96
134
 
97
135
  module.exports = tap