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.
- package/_internal/areAllValuesNonfunctions.js +16 -4
- package/_internal/areAnyValuesPromises.js +16 -4
- package/_internal/functionArrayAll.js +2 -1
- package/_internal/functionObjectAll.js +2 -1
- package/all.js +101 -22
- package/assign.js +19 -3
- package/dist/Transducer.es.js +1 -1
- package/dist/Transducer.es.min.js +1 -1
- package/dist/Transducer.js +1 -1
- package/dist/Transducer.min.js +1 -1
- package/dist/Transducer.mjs +1 -1
- package/dist/__.es.js +1 -1
- package/dist/__.es.min.js +1 -1
- package/dist/__.js +1 -1
- package/dist/__.min.js +1 -1
- package/dist/__.mjs +1 -1
- package/dist/all.es.js +107 -8
- package/dist/all.es.min.js +2 -2
- package/dist/all.js +107 -8
- package/dist/all.min.js +2 -2
- package/dist/all.mjs +107 -8
- package/dist/always.es.js +1 -1
- package/dist/always.es.min.js +1 -1
- package/dist/always.js +1 -1
- package/dist/always.min.js +1 -1
- package/dist/always.mjs +1 -1
- package/dist/and.es.js +30 -9
- package/dist/and.es.min.js +2 -2
- package/dist/and.js +30 -9
- package/dist/and.min.js +2 -2
- package/dist/and.mjs +30 -9
- package/dist/assign.es.js +3 -2
- package/dist/assign.es.min.js +2 -2
- package/dist/assign.js +3 -2
- package/dist/assign.min.js +2 -2
- package/dist/assign.mjs +3 -2
- package/dist/compose.es.js +17 -5
- package/dist/compose.es.min.js +2 -2
- package/dist/compose.js +17 -5
- package/dist/compose.min.js +2 -2
- package/dist/compose.mjs +17 -5
- package/dist/curry.es.js +1 -1
- package/dist/curry.es.min.js +1 -1
- package/dist/curry.js +1 -1
- package/dist/curry.min.js +1 -1
- package/dist/curry.mjs +1 -1
- package/dist/eq.es.js +17 -5
- package/dist/eq.es.min.js +2 -2
- package/dist/eq.js +17 -5
- package/dist/eq.min.js +2 -2
- package/dist/eq.mjs +17 -5
- package/dist/every.es.js +1 -1
- package/dist/every.es.min.js +1 -1
- package/dist/every.js +1 -1
- package/dist/every.min.js +1 -1
- package/dist/every.mjs +1 -1
- package/dist/filter.es.js +1 -1
- package/dist/filter.es.min.js +1 -1
- package/dist/filter.js +1 -1
- package/dist/filter.min.js +1 -1
- package/dist/filter.mjs +1 -1
- package/dist/flatMap.es.js +1 -1
- package/dist/flatMap.es.min.js +1 -1
- package/dist/flatMap.js +1 -1
- package/dist/flatMap.min.js +1 -1
- package/dist/flatMap.mjs +1 -1
- package/dist/forEach.es.js +1 -1
- package/dist/forEach.es.min.js +1 -1
- package/dist/forEach.js +1 -1
- package/dist/forEach.min.js +1 -1
- package/dist/forEach.mjs +1 -1
- package/dist/get.es.js +1 -1
- package/dist/get.es.min.js +1 -1
- package/dist/get.js +1 -1
- package/dist/get.min.js +1 -1
- package/dist/get.mjs +1 -1
- package/dist/gt.es.js +17 -5
- package/dist/gt.es.min.js +2 -2
- package/dist/gt.js +17 -5
- package/dist/gt.min.js +2 -2
- package/dist/gt.mjs +17 -5
- package/dist/gte.es.js +17 -5
- package/dist/gte.es.min.js +2 -2
- package/dist/gte.js +17 -5
- package/dist/gte.min.js +2 -2
- package/dist/gte.mjs +17 -5
- package/dist/lt.es.js +17 -5
- package/dist/lt.es.min.js +2 -2
- package/dist/lt.js +17 -5
- package/dist/lt.min.js +2 -2
- package/dist/lt.mjs +17 -5
- package/dist/lte.es.js +17 -5
- package/dist/lte.es.min.js +2 -2
- package/dist/lte.js +17 -5
- package/dist/lte.min.js +2 -2
- package/dist/lte.mjs +17 -5
- package/dist/map.es.js +1 -1
- package/dist/map.es.min.js +1 -1
- package/dist/map.js +1 -1
- package/dist/map.min.js +1 -1
- package/dist/map.mjs +1 -1
- package/dist/not.es.js +17 -5
- package/dist/not.es.min.js +2 -2
- package/dist/not.js +17 -5
- package/dist/not.min.js +2 -2
- package/dist/not.mjs +17 -5
- package/dist/omit.es.js +1 -1
- package/dist/omit.es.min.js +1 -1
- package/dist/omit.js +1 -1
- package/dist/omit.min.js +1 -1
- package/dist/omit.mjs +1 -1
- package/dist/or.es.js +30 -9
- package/dist/or.es.min.js +2 -2
- package/dist/or.js +30 -9
- package/dist/or.min.js +2 -2
- package/dist/or.mjs +30 -9
- package/dist/pick.es.js +1 -1
- package/dist/pick.es.min.js +1 -1
- package/dist/pick.js +1 -1
- package/dist/pick.min.js +1 -1
- package/dist/pick.mjs +1 -1
- package/dist/pipe.es.js +17 -5
- package/dist/pipe.es.min.js +2 -2
- package/dist/pipe.js +17 -5
- package/dist/pipe.min.js +2 -2
- package/dist/pipe.mjs +17 -5
- package/dist/reduce.es.js +1 -1
- package/dist/reduce.es.min.js +1 -1
- package/dist/reduce.js +1 -1
- package/dist/reduce.min.js +1 -1
- package/dist/reduce.mjs +1 -1
- package/dist/rubico.es.js +170 -89
- package/dist/rubico.es.min.js +2 -2
- package/dist/rubico.global.js +170 -89
- package/dist/rubico.global.min.js +2 -2
- package/dist/rubico.js +170 -89
- package/dist/rubico.min.js +2 -2
- package/dist/rubico.mjs +170 -89
- package/dist/set.es.js +1 -1
- package/dist/set.es.min.js +1 -1
- package/dist/set.js +1 -1
- package/dist/set.min.js +1 -1
- package/dist/set.mjs +1 -1
- package/dist/some.es.js +1 -1
- package/dist/some.es.min.js +1 -1
- package/dist/some.js +1 -1
- package/dist/some.min.js +1 -1
- package/dist/some.mjs +1 -1
- package/dist/switchCase.es.js +30 -9
- package/dist/switchCase.es.min.js +2 -2
- package/dist/switchCase.js +30 -9
- package/dist/switchCase.min.js +2 -2
- package/dist/switchCase.mjs +30 -9
- package/dist/tap.es.js +80 -19
- package/dist/tap.es.min.js +2 -2
- package/dist/tap.js +80 -19
- package/dist/tap.min.js +2 -2
- package/dist/tap.mjs +80 -19
- package/dist/thunkify.es.js +17 -5
- package/dist/thunkify.es.min.js +2 -2
- package/dist/thunkify.js +17 -5
- package/dist/thunkify.min.js +2 -2
- package/dist/thunkify.mjs +17 -5
- package/dist/transform.es.js +1 -1
- package/dist/transform.es.min.js +1 -1
- package/dist/transform.js +1 -1
- package/dist/transform.min.js +1 -1
- package/dist/transform.mjs +1 -1
- package/dist/tryCatch.es.js +17 -5
- package/dist/tryCatch.es.min.js +2 -2
- package/dist/tryCatch.js +17 -5
- package/dist/tryCatch.min.js +2 -2
- package/dist/tryCatch.mjs +17 -5
- package/dist/x/append.es.js +1 -1
- package/dist/x/append.es.min.js +1 -1
- package/dist/x/append.js +1 -1
- package/dist/x/append.min.js +1 -1
- package/dist/x/append.mjs +1 -1
- package/dist/x/callProp.es.js +1 -1
- package/dist/x/callProp.es.min.js +1 -1
- package/dist/x/callProp.js +1 -1
- package/dist/x/callProp.min.js +1 -1
- package/dist/x/callProp.mjs +1 -1
- package/dist/x/defaultsDeep.es.js +1 -1
- package/dist/x/defaultsDeep.es.min.js +1 -1
- package/dist/x/defaultsDeep.js +1 -1
- package/dist/x/defaultsDeep.min.js +1 -1
- package/dist/x/defaultsDeep.mjs +1 -1
- package/dist/x/differenceWith.es.js +1 -1
- package/dist/x/differenceWith.es.min.js +1 -1
- package/dist/x/differenceWith.js +1 -1
- package/dist/x/differenceWith.min.js +1 -1
- package/dist/x/differenceWith.mjs +1 -1
- package/dist/x/filterOut.es.js +15 -5
- package/dist/x/filterOut.es.min.js +2 -2
- package/dist/x/filterOut.js +15 -5
- package/dist/x/filterOut.min.js +2 -2
- package/dist/x/filterOut.mjs +15 -5
- package/dist/x/find.es.js +1 -1
- package/dist/x/find.es.min.js +1 -1
- package/dist/x/find.js +1 -1
- package/dist/x/find.min.js +1 -1
- package/dist/x/find.mjs +1 -1
- package/dist/x/findIndex.es.js +1 -1
- package/dist/x/findIndex.es.min.js +1 -1
- package/dist/x/findIndex.js +1 -1
- package/dist/x/findIndex.min.js +1 -1
- package/dist/x/findIndex.mjs +1 -1
- package/dist/x/first.es.js +1 -1
- package/dist/x/first.es.min.js +1 -1
- package/dist/x/first.js +1 -1
- package/dist/x/first.min.js +1 -1
- package/dist/x/first.mjs +1 -1
- package/dist/x/flatten.es.js +1 -1
- package/dist/x/flatten.es.min.js +1 -1
- package/dist/x/flatten.js +1 -1
- package/dist/x/flatten.min.js +1 -1
- package/dist/x/flatten.mjs +1 -1
- package/dist/x/groupBy.es.js +1 -1
- package/dist/x/groupBy.es.min.js +1 -1
- package/dist/x/groupBy.js +1 -1
- package/dist/x/groupBy.min.js +1 -1
- package/dist/x/groupBy.mjs +1 -1
- package/dist/x/has.es.js +1 -1
- package/dist/x/has.es.min.js +1 -1
- package/dist/x/has.js +1 -1
- package/dist/x/has.min.js +1 -1
- package/dist/x/has.mjs +1 -1
- package/dist/x/identity.es.js +1 -1
- package/dist/x/identity.es.min.js +1 -1
- package/dist/x/identity.js +1 -1
- package/dist/x/identity.min.js +1 -1
- package/dist/x/identity.mjs +1 -1
- package/dist/x/includes.es.js +1 -1
- package/dist/x/includes.es.min.js +1 -1
- package/dist/x/includes.js +1 -1
- package/dist/x/includes.min.js +1 -1
- package/dist/x/includes.mjs +1 -1
- package/dist/x/isDeepEqual.es.js +1 -1
- package/dist/x/isDeepEqual.es.min.js +1 -1
- package/dist/x/isDeepEqual.js +1 -1
- package/dist/x/isDeepEqual.min.js +1 -1
- package/dist/x/isDeepEqual.mjs +1 -1
- package/dist/x/isEmpty.es.js +1 -1
- package/dist/x/isEmpty.es.min.js +1 -1
- package/dist/x/isEmpty.js +1 -1
- package/dist/x/isEmpty.min.js +1 -1
- package/dist/x/isEmpty.mjs +1 -1
- package/dist/x/isEqual.es.js +1 -1
- package/dist/x/isEqual.es.min.js +1 -1
- package/dist/x/isEqual.js +1 -1
- package/dist/x/isEqual.min.js +1 -1
- package/dist/x/isEqual.mjs +1 -1
- package/dist/x/isFunction.es.js +1 -1
- package/dist/x/isFunction.es.min.js +1 -1
- package/dist/x/isFunction.js +1 -1
- package/dist/x/isFunction.min.js +1 -1
- package/dist/x/isFunction.mjs +1 -1
- package/dist/x/isIn.es.js +1 -1
- package/dist/x/isIn.es.min.js +1 -1
- package/dist/x/isIn.js +1 -1
- package/dist/x/isIn.min.js +1 -1
- package/dist/x/isIn.mjs +1 -1
- package/dist/x/isObject.es.js +1 -1
- package/dist/x/isObject.es.min.js +1 -1
- package/dist/x/isObject.js +1 -1
- package/dist/x/isObject.min.js +1 -1
- package/dist/x/isObject.mjs +1 -1
- package/dist/x/isString.es.js +1 -1
- package/dist/x/isString.es.min.js +1 -1
- package/dist/x/isString.js +1 -1
- package/dist/x/isString.min.js +1 -1
- package/dist/x/isString.mjs +1 -1
- package/dist/x/keys.es.js +1 -1
- package/dist/x/keys.es.min.js +1 -1
- package/dist/x/keys.js +1 -1
- package/dist/x/keys.min.js +1 -1
- package/dist/x/keys.mjs +1 -1
- package/dist/x/last.es.js +1 -1
- package/dist/x/last.es.min.js +1 -1
- package/dist/x/last.js +1 -1
- package/dist/x/last.min.js +1 -1
- package/dist/x/last.mjs +1 -1
- package/dist/x/maxBy.es.js +1 -1
- package/dist/x/maxBy.es.min.js +1 -1
- package/dist/x/maxBy.js +1 -1
- package/dist/x/maxBy.min.js +1 -1
- package/dist/x/maxBy.mjs +1 -1
- package/dist/x/noop.es.js +1 -1
- package/dist/x/noop.es.min.js +1 -1
- package/dist/x/noop.js +1 -1
- package/dist/x/noop.min.js +1 -1
- package/dist/x/noop.mjs +1 -1
- package/dist/x/pluck.es.js +1 -1
- package/dist/x/pluck.es.min.js +1 -1
- package/dist/x/pluck.js +1 -1
- package/dist/x/pluck.min.js +1 -1
- package/dist/x/pluck.mjs +1 -1
- package/dist/x/prepend.es.js +1 -1
- package/dist/x/prepend.es.min.js +1 -1
- package/dist/x/prepend.js +1 -1
- package/dist/x/prepend.min.js +1 -1
- package/dist/x/prepend.mjs +1 -1
- package/dist/x/size.es.js +1 -1
- package/dist/x/size.es.min.js +1 -1
- package/dist/x/size.js +1 -1
- package/dist/x/size.min.js +1 -1
- package/dist/x/size.mjs +1 -1
- package/dist/x/trace.es.js +82 -21
- package/dist/x/trace.es.min.js +2 -2
- package/dist/x/trace.js +82 -21
- package/dist/x/trace.min.js +2 -2
- package/dist/x/trace.mjs +82 -21
- package/dist/x/unionWith.es.js +1 -1
- package/dist/x/unionWith.es.min.js +1 -1
- package/dist/x/unionWith.js +1 -1
- package/dist/x/unionWith.min.js +1 -1
- package/dist/x/unionWith.mjs +1 -1
- package/dist/x/uniq.es.js +1 -1
- package/dist/x/uniq.es.min.js +1 -1
- package/dist/x/uniq.js +1 -1
- package/dist/x/uniq.min.js +1 -1
- package/dist/x/uniq.mjs +1 -1
- package/dist/x/unless.es.js +1 -1
- package/dist/x/unless.es.min.js +1 -1
- package/dist/x/unless.js +1 -1
- package/dist/x/unless.min.js +1 -1
- package/dist/x/unless.mjs +1 -1
- package/dist/x/values.es.js +1 -1
- package/dist/x/values.es.min.js +1 -1
- package/dist/x/values.js +1 -1
- package/dist/x/values.min.js +1 -1
- package/dist/x/values.mjs +1 -1
- package/dist/x/when.es.js +1 -1
- package/dist/x/when.es.min.js +1 -1
- package/dist/x/when.js +1 -1
- package/dist/x/when.min.js +1 -1
- package/dist/x/when.mjs +1 -1
- package/es.js +170 -89
- package/index.js +170 -89
- package/package.json +1 -1
- package/tap.js +66 -28
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* rubico v2.6.
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
//
|
|
156
|
-
const
|
|
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 =
|
|
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
|
|
206
|
+
const f = args.pop()
|
|
164
207
|
if (args.length == 0) {
|
|
165
|
-
return curryArgs2(_tap, __,
|
|
208
|
+
return curryArgs2(_tap, __, f)
|
|
166
209
|
}
|
|
167
210
|
if (areAnyValuesPromises(args)) {
|
|
168
|
-
return promiseAll(args).then(curry2(_tap, __,
|
|
211
|
+
return promiseAll(args).then(curry2(_tap, __, f))
|
|
169
212
|
}
|
|
170
|
-
return _tap(args,
|
|
213
|
+
return _tap(args, f)
|
|
171
214
|
}
|
|
172
215
|
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
if (isPromise(
|
|
176
|
-
return
|
|
177
|
-
thunkConditional,
|
|
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 (
|
|
180
|
-
const execution =
|
|
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
|
-
|
|
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
|
|
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
|
|
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
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,
|
|
13
|
-
const _tap = function (args,
|
|
13
|
+
// _tap(args Array, f function) -> Promise|any
|
|
14
|
+
const _tap = function (args, f) {
|
|
14
15
|
const result = args[0],
|
|
15
|
-
call =
|
|
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,
|
|
25
|
-
* tap(
|
|
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
|
|
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
|
|
51
|
+
const f = args.pop()
|
|
50
52
|
if (args.length == 0) {
|
|
51
|
-
return curryArgs2(_tap, __,
|
|
53
|
+
return curryArgs2(_tap, __, f)
|
|
52
54
|
}
|
|
53
55
|
if (areAnyValuesPromises(args)) {
|
|
54
|
-
return promiseAll(args).then(curry2(_tap, __,
|
|
56
|
+
return promiseAll(args).then(curry2(_tap, __, f))
|
|
55
57
|
}
|
|
56
|
-
return _tap(args,
|
|
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,
|
|
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
|
|
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
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
return
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
132
|
+
return _tapIf(predicate, f, args)
|
|
95
133
|
}
|
|
96
134
|
|
|
97
135
|
module.exports = tap
|