rubico 2.8.5 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/_internal/FlatMappingAsyncIterator.js +41 -30
- package/_internal/LinkedList.js +54 -0
- package/_internal/LinkedList.test.js +34 -0
- package/_internal/MappingAsyncIterator.js +65 -15
- package/_internal/SerialMappingAsyncIterator.js +79 -0
- package/_internal/curryArity.js +3 -3
- package/_internal/iteratorFind.js +0 -2
- package/_internal/iteratorForEachSeries.js +1 -1
- package/_internal/objectFlatten.js +4 -1
- package/all.js +33 -59
- package/and.js +1 -1
- package/assign.js +14 -16
- package/compose.js +12 -13
- package/curry.js +1 -1
- 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 +1 -1
- package/dist/all.es.min.js +1 -1
- package/dist/all.js +1 -1
- package/dist/all.min.js +1 -1
- package/dist/all.mjs +1 -1
- 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 +1 -1
- package/dist/and.es.min.js +1 -1
- package/dist/and.js +1 -1
- package/dist/and.min.js +1 -1
- package/dist/and.mjs +1 -1
- package/dist/assign.es.js +1 -1
- package/dist/assign.es.min.js +1 -1
- package/dist/assign.js +1 -1
- package/dist/assign.min.js +1 -1
- package/dist/assign.mjs +1 -1
- package/dist/compose.es.js +1 -1
- package/dist/compose.es.min.js +1 -1
- package/dist/compose.js +1 -1
- package/dist/compose.min.js +1 -1
- package/dist/compose.mjs +1 -1
- package/dist/curry.es.js +4 -4
- package/dist/curry.es.min.js +2 -2
- package/dist/curry.js +4 -4
- package/dist/curry.min.js +2 -2
- package/dist/curry.mjs +4 -4
- package/dist/eq.es.js +1 -1
- package/dist/eq.es.min.js +1 -1
- package/dist/eq.js +1 -1
- package/dist/eq.min.js +1 -1
- package/dist/eq.mjs +1 -1
- 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 +4 -4
- package/dist/filter.es.min.js +2 -2
- package/dist/filter.js +4 -4
- package/dist/filter.min.js +2 -2
- package/dist/filter.mjs +4 -4
- package/dist/flatMap.es.js +44 -28
- package/dist/flatMap.es.min.js +2 -2
- package/dist/flatMap.js +44 -28
- package/dist/flatMap.min.js +2 -2
- package/dist/flatMap.mjs +44 -28
- package/dist/forEach.es.js +6 -6
- package/dist/forEach.es.min.js +2 -2
- package/dist/forEach.js +6 -6
- package/dist/forEach.min.js +2 -2
- package/dist/forEach.mjs +6 -6
- package/dist/get.es.js +27 -3
- package/dist/get.es.min.js +2 -2
- package/dist/get.js +27 -3
- package/dist/get.min.js +2 -2
- package/dist/get.mjs +27 -3
- package/dist/gt.es.js +1 -1
- package/dist/gt.es.min.js +1 -1
- package/dist/gt.js +1 -1
- package/dist/gt.min.js +1 -1
- package/dist/gt.mjs +1 -1
- package/dist/gte.es.js +1 -1
- package/dist/gte.es.min.js +1 -1
- package/dist/gte.js +1 -1
- package/dist/gte.min.js +1 -1
- package/dist/gte.mjs +1 -1
- package/dist/lt.es.js +1 -1
- package/dist/lt.es.min.js +1 -1
- package/dist/lt.js +1 -1
- package/dist/lt.min.js +1 -1
- package/dist/lt.mjs +1 -1
- package/dist/lte.es.js +1 -1
- package/dist/lte.es.min.js +1 -1
- package/dist/lte.js +1 -1
- package/dist/lte.min.js +1 -1
- package/dist/lte.mjs +1 -1
- package/dist/map.es.js +190 -42
- package/dist/map.es.min.js +2 -2
- package/dist/map.js +190 -42
- package/dist/map.min.js +2 -2
- package/dist/map.mjs +190 -42
- package/dist/not.es.js +1 -1
- package/dist/not.es.min.js +1 -1
- package/dist/not.js +1 -1
- package/dist/not.min.js +1 -1
- package/dist/not.mjs +1 -1
- 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 +1 -1
- package/dist/or.es.min.js +1 -1
- package/dist/or.js +1 -1
- package/dist/or.min.js +1 -1
- package/dist/or.mjs +1 -1
- 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 +1 -1
- package/dist/pipe.es.min.js +1 -1
- package/dist/pipe.js +1 -1
- package/dist/pipe.min.js +1 -1
- package/dist/pipe.mjs +1 -1
- 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 +238 -83
- package/dist/rubico.es.min.js +2 -2
- package/dist/rubico.global.js +238 -83
- package/dist/rubico.global.min.js +2 -2
- package/dist/rubico.js +238 -83
- package/dist/rubico.min.js +2 -2
- package/dist/rubico.mjs +238 -83
- 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 +1 -1
- package/dist/switchCase.es.min.js +1 -1
- package/dist/switchCase.js +1 -1
- package/dist/switchCase.min.js +1 -1
- package/dist/switchCase.mjs +1 -1
- package/dist/tap.es.js +1 -1
- package/dist/tap.es.min.js +1 -1
- package/dist/tap.js +1 -1
- package/dist/tap.min.js +1 -1
- package/dist/tap.mjs +1 -1
- package/dist/thunkify.es.js +1 -1
- package/dist/thunkify.es.min.js +1 -1
- package/dist/thunkify.js +1 -1
- package/dist/thunkify.min.js +1 -1
- package/dist/thunkify.mjs +1 -1
- 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 +1 -1
- package/dist/tryCatch.es.min.js +1 -1
- package/dist/tryCatch.js +1 -1
- package/dist/tryCatch.min.js +1 -1
- package/dist/tryCatch.mjs +1 -1
- 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 +4 -4
- package/dist/x/filterOut.es.min.js +2 -2
- package/dist/x/filterOut.js +4 -4
- package/dist/x/filterOut.min.js +2 -2
- package/dist/x/filterOut.mjs +4 -4
- package/dist/x/find.es.js +1 -3
- package/dist/x/find.es.min.js +1 -1
- package/dist/x/find.js +1 -3
- package/dist/x/find.min.js +1 -1
- package/dist/x/find.mjs +1 -3
- 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 +44 -28
- package/dist/x/flatten.es.min.js +2 -2
- package/dist/x/flatten.js +44 -28
- package/dist/x/flatten.min.js +2 -2
- package/dist/x/flatten.mjs +44 -28
- 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 +27 -23
- package/dist/x/maxBy.es.min.js +2 -2
- package/dist/x/maxBy.js +27 -23
- package/dist/x/maxBy.min.js +2 -2
- package/dist/x/maxBy.mjs +27 -23
- 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 +194 -44
- package/dist/x/pluck.es.min.js +2 -2
- package/dist/x/pluck.js +194 -44
- package/dist/x/pluck.min.js +2 -2
- package/dist/x/pluck.mjs +194 -44
- 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 +1 -1
- package/dist/x/trace.es.min.js +1 -1
- package/dist/x/trace.js +1 -1
- package/dist/x/trace.min.js +1 -1
- package/dist/x/trace.mjs +1 -1
- 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/eq.js +2 -2
- package/es.js +238 -83
- package/every.js +2 -2
- package/filter.js +4 -4
- package/flatMap.js +61 -54
- package/forEach.js +33 -56
- package/get.js +49 -25
- package/gt.js +2 -2
- package/gte.js +2 -2
- package/index.js +238 -83
- package/lt.js +2 -2
- package/lte.js +2 -2
- package/map.js +115 -151
- package/monad/Mux.js +6 -4
- package/monad/PossiblePromise.js +6 -4
- package/monad/README.md +61 -40
- package/monad/Struct.js +6 -4
- package/not.js +1 -1
- package/omit.js +22 -19
- package/or.js +1 -1
- package/package.json +1 -1
- package/pick.js +14 -11
- package/pipe.js +18 -24
- package/reduce.js +1 -1
- package/set.js +17 -18
- package/some.js +2 -2
- package/switchCase.js +51 -43
- package/tap.js +17 -23
- package/transform.js +1 -1
- package/tryCatch.js +16 -24
- package/x/defaultsDeep.js +1 -1
- package/x/defaultsDeep.test.js +1 -1
- package/_internal/NextIteration.js +0 -12
- package/_internal/generatorFunctionFilter.js +0 -28
- package/_internal/iterationMap.js +0 -27
package/dist/map.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Rubico v2.
|
|
2
|
+
* Rubico v2.10.0
|
|
3
3
|
* https://rubico.land/
|
|
4
4
|
*
|
|
5
5
|
* © Richard Yufei Tong, King of Software
|
|
@@ -24,25 +24,7 @@ const MappingIterator = (iterator, mapper) => ({
|
|
|
24
24
|
},
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const symbolAsyncIterator = Symbol.asyncIterator
|
|
30
|
-
|
|
31
|
-
const MappingAsyncIterator = (asyncIterator, mapper) => ({
|
|
32
|
-
[symbolAsyncIterator]() {
|
|
33
|
-
return this
|
|
34
|
-
},
|
|
35
|
-
async next() {
|
|
36
|
-
const iteration = await asyncIterator.next()
|
|
37
|
-
if (iteration.done) {
|
|
38
|
-
return iteration
|
|
39
|
-
}
|
|
40
|
-
const mapped = mapper(iteration.value)
|
|
41
|
-
return isPromise(mapped)
|
|
42
|
-
? mapped.then(NextIteration)
|
|
43
|
-
: { value: mapped, done: false }
|
|
44
|
-
}
|
|
45
|
-
})
|
|
27
|
+
const promiseRace = Promise.race.bind(Promise)
|
|
46
28
|
|
|
47
29
|
const __ = Symbol.for('placeholder')
|
|
48
30
|
|
|
@@ -66,6 +48,165 @@ const curry2 = function (baseFunc, arg0, arg1) {
|
|
|
66
48
|
: curry2ResolveArg1(baseFunc, arg0)
|
|
67
49
|
}
|
|
68
50
|
|
|
51
|
+
class LinkedList {
|
|
52
|
+
constructor() {
|
|
53
|
+
this.first = null
|
|
54
|
+
this.last = null
|
|
55
|
+
this.length = 0
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// popFirst() -> firstValue any
|
|
59
|
+
popFirst() {
|
|
60
|
+
const first = this.first
|
|
61
|
+
|
|
62
|
+
if (first == null) {
|
|
63
|
+
return undefined
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (first.next) {
|
|
67
|
+
this.first = first.next
|
|
68
|
+
} else {
|
|
69
|
+
this.first = null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.length -= 1
|
|
73
|
+
|
|
74
|
+
return first.value
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// append(value any) -> undefined
|
|
78
|
+
append(value) {
|
|
79
|
+
const node = { value }
|
|
80
|
+
if (this.first == null) {
|
|
81
|
+
this.first = node
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.last == null) {
|
|
85
|
+
this.last = node
|
|
86
|
+
} else {
|
|
87
|
+
this.last.next = node
|
|
88
|
+
this.last = node
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.length += 1
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const symbolAsyncIterator = Symbol.asyncIterator
|
|
97
|
+
|
|
98
|
+
const arrayPush = function (array, value) {
|
|
99
|
+
array.push(value)
|
|
100
|
+
return array
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const sleep = time => new Promise(resolve => {
|
|
104
|
+
setTimeout(resolve, time)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const MappingAsyncIterator = (asyncIterator, mapper) => {
|
|
108
|
+
const buffer = new LinkedList()
|
|
109
|
+
|
|
110
|
+
let index = -1
|
|
111
|
+
let consumingAsyncIterator = false
|
|
112
|
+
let isAsyncIteratorDone = false
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
[symbolAsyncIterator]() {
|
|
116
|
+
return this
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// _consumeAsyncIterator() -> Promise<>
|
|
120
|
+
async _consumeAsyncIterator() {
|
|
121
|
+
for await (const item of asyncIterator) {
|
|
122
|
+
index += 1
|
|
123
|
+
const mappedItem = mapper(item)
|
|
124
|
+
buffer.append(mappedItem)
|
|
125
|
+
}
|
|
126
|
+
isAsyncIteratorDone = true
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
async next() {
|
|
131
|
+
if (!consumingAsyncIterator) {
|
|
132
|
+
this._consumeAsyncIterator()
|
|
133
|
+
consumingAsyncIterator = true
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
while (!isAsyncIteratorDone) {
|
|
137
|
+
if (buffer.length > 0) {
|
|
138
|
+
let value = buffer.popFirst()
|
|
139
|
+
if (isPromise(value)) {
|
|
140
|
+
value = await value
|
|
141
|
+
}
|
|
142
|
+
return { value, done: false }
|
|
143
|
+
}
|
|
144
|
+
await sleep(10)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (buffer.length > 0) {
|
|
148
|
+
let value = buffer.popFirst()
|
|
149
|
+
if (isPromise(value)) {
|
|
150
|
+
value = await value
|
|
151
|
+
}
|
|
152
|
+
return { value, done: false }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { value: undefined, done: true }
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const SerialMappingAsyncIterator = (asyncIterator, mapper) => {
|
|
162
|
+
const buffer = new LinkedList()
|
|
163
|
+
|
|
164
|
+
let index = -1
|
|
165
|
+
let consumingAsyncIterator = false
|
|
166
|
+
let isAsyncIteratorDone = false
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
[symbolAsyncIterator]() {
|
|
170
|
+
return this
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
// _consumeAsyncIterator() -> Promise<>
|
|
174
|
+
async _consumeAsyncIterator() {
|
|
175
|
+
for await (const item of asyncIterator) {
|
|
176
|
+
index += 1
|
|
177
|
+
let mappedItem = mapper(item)
|
|
178
|
+
if (isPromise(mappedItem)) {
|
|
179
|
+
mappedItem = await mappedItem
|
|
180
|
+
}
|
|
181
|
+
buffer.append(mappedItem)
|
|
182
|
+
}
|
|
183
|
+
isAsyncIteratorDone = true
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
async next() {
|
|
188
|
+
if (!consumingAsyncIterator) {
|
|
189
|
+
this._consumeAsyncIterator()
|
|
190
|
+
consumingAsyncIterator = true
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
while (!isAsyncIteratorDone) {
|
|
194
|
+
if (buffer.length > 0) {
|
|
195
|
+
return { value: buffer.popFirst(), done: false }
|
|
196
|
+
}
|
|
197
|
+
await sleep(10)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (buffer.length > 0) {
|
|
201
|
+
return { value: buffer.popFirst(), done: false }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return { value: undefined, done: true }
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
69
210
|
// argument resolver for curry3
|
|
70
211
|
const curry3ResolveArg0 = (
|
|
71
212
|
baseFunc, arg1, arg2,
|
|
@@ -432,8 +573,6 @@ const tapSync = func => function tapping(...args) {
|
|
|
432
573
|
return args[0]
|
|
433
574
|
}
|
|
434
575
|
|
|
435
|
-
const promiseRace = Promise.race.bind(Promise)
|
|
436
|
-
|
|
437
576
|
const arrayMapPoolAsync = async function (
|
|
438
577
|
array, f, concurrencyLimit, result, index, promises,
|
|
439
578
|
) {
|
|
@@ -661,7 +800,7 @@ const _curryArity = (arity, func, context, args) => function curried(...curriedA
|
|
|
661
800
|
curriedArgsIndex = -1,
|
|
662
801
|
numCurriedPlaceholders = 0
|
|
663
802
|
|
|
664
|
-
while (
|
|
803
|
+
while ((argsIndex += 1) < argsLength) {
|
|
665
804
|
const arg = args[argsIndex]
|
|
666
805
|
if (arg == __ && (curriedArgsIndex += 1) < curriedArgsLength) {
|
|
667
806
|
const curriedArg = curriedArgs[curriedArgsIndex]
|
|
@@ -685,7 +824,7 @@ const _curryArity = (arity, func, context, args) => function curried(...curriedA
|
|
|
685
824
|
}
|
|
686
825
|
}
|
|
687
826
|
|
|
688
|
-
while (
|
|
827
|
+
while ((curriedArgsIndex += 1) < curriedArgsLength) {
|
|
689
828
|
const curriedArg = curriedArgs[curriedArgsIndex]
|
|
690
829
|
if (curriedArg == __) {
|
|
691
830
|
numCurriedPlaceholders += 1
|
|
@@ -715,7 +854,7 @@ const curryArity = function (arity, func, context, args) {
|
|
|
715
854
|
return _curryArity(arity, func, context, args)
|
|
716
855
|
}
|
|
717
856
|
let argsIndex = -1
|
|
718
|
-
while (
|
|
857
|
+
while ((argsIndex += 1) < argsLength) {
|
|
719
858
|
const arg = args[argsIndex]
|
|
720
859
|
if (arg == __) {
|
|
721
860
|
return _curryArity(arity, func, context, args)
|
|
@@ -778,9 +917,6 @@ const _map = function (value, f) {
|
|
|
778
917
|
if (typeof value.then == 'function') {
|
|
779
918
|
return value.then(f)
|
|
780
919
|
}
|
|
781
|
-
if (typeof value.map == 'function') {
|
|
782
|
-
return value.map(f)
|
|
783
|
-
}
|
|
784
920
|
if (typeof value == 'string' || value.constructor == String) {
|
|
785
921
|
return stringMap(value, f)
|
|
786
922
|
}
|
|
@@ -796,6 +932,9 @@ const _map = function (value, f) {
|
|
|
796
932
|
if (typeof value[symbolAsyncIterator] == 'function') {
|
|
797
933
|
return MappingAsyncIterator(value[symbolAsyncIterator](), f)
|
|
798
934
|
}
|
|
935
|
+
if (typeof value.map == 'function') {
|
|
936
|
+
return value.map(f)
|
|
937
|
+
}
|
|
799
938
|
if (value.constructor == Object) {
|
|
800
939
|
return objectMap(value, f)
|
|
801
940
|
}
|
|
@@ -834,27 +973,36 @@ map.entries = function mapEntries(arg0, arg1) {
|
|
|
834
973
|
: _mapEntries(arg0, arg1)
|
|
835
974
|
}
|
|
836
975
|
|
|
837
|
-
const _mapSeries = function (
|
|
838
|
-
if (isArray(
|
|
839
|
-
return arrayMapSeries(
|
|
976
|
+
const _mapSeries = function (functor, f) {
|
|
977
|
+
if (isArray(functor)) {
|
|
978
|
+
return arrayMapSeries(functor, f)
|
|
840
979
|
}
|
|
841
|
-
if (
|
|
842
|
-
throw new TypeError(`invalid
|
|
980
|
+
if (functor == null) {
|
|
981
|
+
throw new TypeError(`invalid functor ${functor}`)
|
|
843
982
|
}
|
|
844
983
|
|
|
845
|
-
if (typeof
|
|
846
|
-
return stringMapSeries(
|
|
984
|
+
if (typeof functor == 'string' || functor.constructor == String) {
|
|
985
|
+
return stringMapSeries(functor, f)
|
|
986
|
+
}
|
|
987
|
+
if (functor.constructor == Set) {
|
|
988
|
+
return setMapSeries(functor, f)
|
|
989
|
+
}
|
|
990
|
+
if (functor.constructor == Map) {
|
|
991
|
+
return mapMapSeries(functor, f)
|
|
992
|
+
}
|
|
993
|
+
if (typeof functor[symbolIterator] == 'function') {
|
|
994
|
+
return MappingIterator(functor[symbolIterator](), f)
|
|
847
995
|
}
|
|
848
|
-
if (
|
|
849
|
-
return
|
|
996
|
+
if (typeof functor[symbolAsyncIterator] == 'function') {
|
|
997
|
+
return SerialMappingAsyncIterator(functor[symbolAsyncIterator](), f)
|
|
850
998
|
}
|
|
851
|
-
if (
|
|
852
|
-
return
|
|
999
|
+
if (typeof functor.map == 'function') {
|
|
1000
|
+
return functor.map(f)
|
|
853
1001
|
}
|
|
854
|
-
if (
|
|
855
|
-
return objectMapSeries(
|
|
1002
|
+
if (functor.constructor == Object) {
|
|
1003
|
+
return objectMapSeries(functor, f)
|
|
856
1004
|
}
|
|
857
|
-
throw new TypeError(`invalid
|
|
1005
|
+
throw new TypeError(`invalid functor ${functor}`)
|
|
858
1006
|
}
|
|
859
1007
|
|
|
860
1008
|
map.series = function mapSeries(arg0, arg1) {
|
package/dist/map.es.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Rubico v2.
|
|
2
|
+
* Rubico v2.10.0
|
|
3
3
|
* https://rubico.land/
|
|
4
4
|
*
|
|
5
5
|
* © Richard Yufei Tong, King of Software
|
|
6
6
|
* Rubico may be freely distributed under the CFOSS license.
|
|
7
7
|
*/
|
|
8
|
-
const isPromise=r=>null!=r&&"function"==typeof r.then,symbolIterator=Symbol.iterator,MappingIterator=(r,e)=>({toString:()=>"[object MappingIterator]",[symbolIterator](){return this},next(){const t=r.next();return t.done?t:{value:e(t.value),done:!1}}}),NextIteration=r=>({value:r,done:!1}),symbolAsyncIterator=Symbol.asyncIterator,MappingAsyncIterator=(r,e)=>({[symbolAsyncIterator](){return this},async next(){const t=await r.next();if(t.done)return t;const n=e(t.value);return isPromise(n)?n.then(NextIteration):{value:n,done:!1}}}),__=Symbol.for("placeholder"),curry2ResolveArg0=(r,e)=>function(t){return r(t,e)},curry2ResolveArg1=(r,e)=>function(t){return r(e,t)},curry2=function(r,e,t){return e==__?curry2ResolveArg0(r,t):curry2ResolveArg1(r,e)},curry3ResolveArg0=(r,e,t)=>function(n){return r(n,e,t)},curry3ResolveArg1=(r,e,t)=>function(n){return r(e,n,t)},curry3ResolveArg2=(r,e,t)=>function(n){return r(e,t,n)},curry3=function(r,e,t,n){return e==__?curry3ResolveArg0(r,t,n):t==__?curry3ResolveArg1(r,e,n):curry3ResolveArg2(r,e,t)},isArray=Array.isArray,isObject=r=>{if(null==r)return!1;const e=typeof r;return"object"==e||"function"==e},promiseAll=Promise.all.bind(Promise),arrayMap=function(r,e){const t=r.length,n=Array(t);let o=-1,s=!1;for(;++o<t;){const t=e(r[o],o,r);isPromise(t)&&(s=!0),n[o]=t}return s?promiseAll(n):n},callPropUnary=(r,e,t)=>r[e](t),stringMap=function(r,e){const t=arrayMap(r,e);return isPromise(t)?t.then(curry3(callPropUnary,__,"join","")):t.join("")},always=r=>function(){return r},setMap=function(r,e){const t=new Set,n=[];for(const o of r){const s=e(o,o,r);isPromise(s)?n.push(s.then(curry3(callPropUnary,t,"add",__))):t.add(s)}return 0==n.length?t:promiseAll(n).then(always(t))},curry4ResolveArg0=(r,e,t,n)=>function(o){return r(o,e,t,n)},curry4ResolveArg1=(r,e,t,n)=>function(o){return r(e,o,t,n)},curry4ResolveArg2=(r,e,t,n)=>function(o){return r(e,t,o,n)},curry4ResolveArg3=(r,e,t,n)=>function(o){return r(e,t,n,o)},curry4=function(r,e,t,n,o){return e==__?curry4ResolveArg0(r,t,n,o):t==__?curry4ResolveArg1(r,e,n,o):n==__?curry4ResolveArg2(r,e,t,o):curry4ResolveArg3(r,e,t,n)},callPropBinary=(r,e,t,n)=>r[e](t,n),mapMap=function(r,e){const t=new Map,n=[];for(const[o,s]of r){const i=e(s,o,r);isPromise(i)?n.push(i.then(curry4(callPropBinary,t,"set",o,__))):t.set(o,i)}return 0==n.length?t:promiseAll(n).then(always(t))},promiseObjectAllExecutor=r=>function(e){const t={};let n=0;for(const o in r){const s=r[o];isPromise(s)?(n+=1,s.then((r=>function(o){t[r]=o,n-=1,0==n&&e(t)})(o))):t[o]=s}0==n&&e(t)},promiseObjectAll=r=>new Promise(promiseObjectAllExecutor(r)),objectMap=function(r,e){const t={};let n=!1;for(const o in r){const s=e(r[o],o,r);isPromise(s)&&(n=!0),t[o]=s}return n?promiseObjectAll(t):t},funcConcat=(r,e)=>function(...t){const n=r(...t);return isPromise(n)?n.then(e):e(n)},objectSet=function(r,e,t){return r[e]=t,r},arrayMapSeriesAsync=async function(r,e,t,n){const o=r.length;for(;++n<o;){const o=e(r[n],n);t[n]=isPromise(o)?await o:o}return t},arrayMapSeries=function(r,e){const t=r.length,n=Array(t);let o=-1;for(;++o<t;){const t=e(r[o],o);if(isPromise(t))return t.then(funcConcat(curry3(objectSet,n,o,__),curry4(arrayMapSeriesAsync,r,e,__,o)));n[o]=t}return n},stringMapSeries=function(r,e){const t=arrayMapSeries(r,e);return isPromise(t)?t.then(curry3(callPropUnary,__,"join","")):t.join("")},thunkify4=(r,e,t,n,o)=>function(){return r(e,t,n,o)},_objectMapSeriesAsync=async function(r,e,t,n){for(const o in r){if(o in n)continue;let s=e(r[o]);isPromise(s)&&(s=await s),t[o]=s}return t},objectMapSeries=function(r,e){const t={},n={};for(const o in r){n[o]=!0;const s=e(r[o],o,r);if(isPromise(s))return s.then(funcConcat(curry3(objectSet,t,o,__),thunkify4(_objectMapSeriesAsync,r,e,t,n)));t[o]=s}return t},thunkify3=(r,e,t,n)=>function(){return r(e,t,n)},setAdd=function(r,e){return r.add(e),r},_setMapSeriesAsync=async function(r,e,t){let n=r.next();for(;!n.done;){let o=e(n.value);isPromise(o)&&(o=await o),t.add(o),n=r.next()}return t},setMapSeries=function(r,e){const t=new Set,n=r[symbolIterator]();let o=n.next();for(;!o.done;){const r=e(o.value);if(isPromise(r))return r.then(funcConcat(curry2(setAdd,t,__),thunkify3(_setMapSeriesAsync,n,e,t)));t.add(r),o=n.next()}return t},mapSet=function(r,e,t){return r.set(e,t)},_mapMapSeriesAsync=async function(r,e,t){let n=r.next();for(;!n.done;){let o=e(n.value[1]);isPromise(o)&&(o=await o),t.set(n.value[0],o),n=r.next()}return t},mapMapSeries=function(r,e){const t=new Map,n=r[symbolIterator]();let o=n.next();for(;!o.done;){const r=o.value[0],s=e(o.value[1]);if(isPromise(s))return s.then(funcConcat(curry3(mapSet,t,r,__),thunkify3(_mapMapSeriesAsync,n,e,t)));t.set(r,s),o=n.next()}return t},tapSync=r=>function(...e){return r(...e),e[0]},promiseRace=Promise.race.bind(Promise),arrayMapPoolAsync=async function(r,e,t,n,o,s){const i=r.length;for(;++o<i;){s.size>=t&&await promiseRace(s);const i=e(r[o]);if(isPromise(i)){const r=i.then(tapSync((()=>s.delete(r))));s.add(r),n[o]=r}else n[o]=i}return promiseAll(n)},arrayMapPool=function(r,e,t){const n=r.length,o=Array(n);let s=-1;for(;++s<n;){const n=t(r[s]);if(isPromise(n)){const i=new Set,c=n.then(tapSync((()=>i.delete(c))));return i.add(c),o[s]=c,arrayMapPoolAsync(r,t,e,o,s,i)}o[s]=n}return o},stringMapPool=function(r,e,t){const n=arrayMapPool(r,e,t);return isPromise(n)?n.then(curry3(callPropUnary,__,"join","")):n.join("")},_setMapPoolAsync=async function(r,e,t,n,o,s){let i=e.next();for(;!i.done;){s.size>=t&&await promiseRace(s);const c=n(i.value,i.value,r);if(isPromise(c)){const r=c.then((e=>{s.delete(r),o.add(e)}));s.add(r)}else o.add(c);i=e.next()}return s.size>0&&await promiseAll(s),o},setMapPool=function(r,e,t){const n=new Set,o=r[symbolIterator]();let s=o.next();for(;!s.done;){const i=t(s.value,s.value,r);if(isPromise(i)){const s=new Set,c=i.then((r=>{s.delete(c),n.add(r)}));return s.add(c),_setMapPoolAsync(r,o,e,t,n,s)}n.add(i),s=o.next()}return n},_mapMapPoolAsync=async function(r,e,t,n,o,s){let i=e.next();for(;!i.done;){s.size>=t&&await promiseRace(s);const c=i.value[0],a=n(i.value[1],c,r);if(isPromise(a)){o.set(c,a);const r=a.then((e=>{s.delete(r),o.set(c,e)}));s.add(r)}else o.set(c,a);i=e.next()}return s.size>0&&await promiseAll(s),o},mapMapPool=function(r,e,t){const n=new Map,o=r[symbolIterator]();let s=o.next();for(;!s.done;){const i=s.value[0],c=t(s.value[1],i,r);if(isPromise(c)){const s=new Set;n.set(i,c);const a=c.then((r=>{s.delete(a),n.set(i,r)}));return s.add(a),_mapMapPoolAsync(r,o,e,t,n,s)}n.set(i,c),s=o.next()}return n},_objectMapPoolAsync=async function(r,e,t,n,o,s){for(const i in r){if(i in o)continue;s.size>=e&&await promiseRace(s);const c=t(r[i],i,r);if(isPromise(c)){n[i]=c;const r=c.then((e=>{s.delete(r),n[i]=e}));s.add(r)}else n[i]=c}return s.size>0&&await promiseAll(s),n},objectMapPool=function(r,e,t){const n={},o={};for(const s in r){o[s]=!0;const i=t(r[s],s,r);if(isPromise(i)){const c=new Set;n[s]=i;const a=i.then((r=>{c.delete(a),n[s]=r}));return c.add(a),_objectMapPoolAsync(r,e,t,n,o,c)}n[s]=i}return n},areAnyValuesPromises=function(r){if(isArray(r)){const e=r.length;let t=-1;for(;++t<e;){const e=r[t];if(isPromise(e))return!0}return!1}for(const e in r){const t=r[e];if(isPromise(t))return!0}return!1},funcApply2=(r,e,t)=>r.apply(e,t),_curryArity=(r,e,t,n)=>function(...o){const s=n.length,i=o.length,c=[];let a=-1,u=-1,l=0;for(;++a<s;){const s=n[a];if(s==__&&(u+=1)<i){const r=o[u];r==__&&(l+=1),c.push(r)}else c.push(s);if(c.length==r)return areAnyValuesPromises(c)?0==l?promiseAll(c).then(curry3(funcApply2,e,t,__)):promiseAll(c).then(curry4(curryArity,r,e,t,__)):0==l?e.apply(t,c):curryArity(r,e,t,c)}for(;++u<i;){const n=o[u];if(n==__&&(l+=1),c.push(n),c.length==r)return areAnyValuesPromises(c)?0==l?promiseAll(c).then(curry3(funcApply2,e,t,__)):promiseAll(c).then(curry4(curryArity,r,e,t,__)):0==l?e.apply(t,c):curryArity(r,e,t,c)}return areAnyValuesPromises(c)?promiseAll(c).then(curry4(curryArity,r,e,t,__)):curryArity(r,e,t,c)},curryArity=function(r,e,t,n){const o=n.length;if(o<r)return _curryArity(r,e,t,n);let s=-1;for(;++s<o;){if(n[s]==__)return _curryArity(r,e,t,n)}return e.apply(t,n)},spread2=r=>function([e,t]){return r(e,t)},objectMapEntries=function(r,e){const t={},n=[];for(const o in r){const s=e([o,r[o]]);isPromise(s)?n.push(s.then(spread2(curryArity(3,objectSet,this,[t])))):t[s[0]]=s[1]}return 0==n.length?t:promiseAll(n).then(always(t))},mapMapEntriesForEachCallback=(r,e,t)=>function(n,o){const s=r([o,n]);isPromise(s)?t.push(s.then(spread2(curryArity(3,mapSet,this,[e])))):e.set(s[0],s[1])},mapMapEntries=function(r,e){const t=new Map,n=[];return r.forEach(mapMapEntriesForEachCallback(e,t,n)),0==n.length?t:promiseAll(n).then(always(t))},_map=function(r,e){return isArray(r)?arrayMap(r,e):null==r?r:"function"==typeof r.then?r.then(e):"function"==typeof r.map?r.map(e):"string"==typeof r||r.constructor==String?stringMap(r,e):r.constructor==Set?setMap(r,e):r.constructor==Map?mapMap(r,e):"function"==typeof r[symbolIterator]?MappingIterator(r[symbolIterator](),e):"function"==typeof r[symbolAsyncIterator]?MappingAsyncIterator(r[symbolAsyncIterator](),e):r.constructor==Object?objectMap(r,e):e(r)},map=function(r,e){return null==e?curry2(_map,__,r):isPromise(r)?r.then(curry2(_map,__,e)):_map(r,e)},_mapEntries=(r,e)=>{if(null==r)throw new TypeError("value is not an Object or Map");if(r.constructor==Object)return objectMapEntries(r,e);if(r.constructor==Map)return mapMapEntries(r,e);throw new TypeError("value is not an Object or Map")};map.entries=function(r,e){return null==e?curry2(_mapEntries,__,r):isPromise(r)?r.then(curry2(_mapEntries,__,e)):_mapEntries(r,e)};const _mapSeries=function(r,e){if(isArray(r))return arrayMapSeries(r,e);if(null==r)throw new TypeError(`invalid collection ${r}`);if("string"==typeof r||r.constructor==String)return stringMapSeries(r,e);if(r.constructor==Set)return setMapSeries(r,e);if(r.constructor==Map)return mapMapSeries(r,e);if(r.constructor==Object)return objectMapSeries(r,e);throw new TypeError(`invalid collection ${r}`)};map.series=function(r,e){return null==e?curry2(_mapSeries,__,r):isPromise(r)?r.then(curry2(_mapSeries,__,e)):_mapSeries(r,e)};const _mapPool=function(r,e,t){if(isArray(r))return arrayMapPool(r,e,t);if(null==r)throw new TypeError(`invalid functor ${r}`);if("string"==typeof r||r.constructor==String)return stringMapPool(r,e,t);if(r.constructor==Set)return setMapPool(r,e,t);if(r.constructor==Map)return mapMapPool(r,e,t);if(r.constructor==Object)return objectMapPool(r,e,t);throw new TypeError(`invalid functor ${r}`)};map.pool=function(r,e,t){return null==t?curry3(_mapPool,__,r,e):isPromise(r)?r.then(curry3(_mapPool,__,e,t)):_mapPool(r,e,t)};export default map;
|
|
8
|
+
const isPromise=r=>null!=r&&"function"==typeof r.then,symbolIterator=Symbol.iterator,MappingIterator=(r,t)=>({toString:()=>"[object MappingIterator]",[symbolIterator](){return this},next(){const e=r.next();return e.done?e:{value:t(e.value),done:!1}}}),promiseRace=Promise.race.bind(Promise),__=Symbol.for("placeholder"),curry2ResolveArg0=(r,t)=>function(e){return r(e,t)},curry2ResolveArg1=(r,t)=>function(e){return r(t,e)},curry2=function(r,t,e){return t==__?curry2ResolveArg0(r,e):curry2ResolveArg1(r,t)};class LinkedList{constructor(){this.first=null,this.last=null,this.length=0}popFirst(){const r=this.first;if(null!=r)return r.next?this.first=r.next:this.first=null,this.length-=1,r.value}append(r){const t={value:r};null==this.first&&(this.first=t),null==this.last||(this.last.next=t),this.last=t,this.length+=1}}const symbolAsyncIterator=Symbol.asyncIterator,arrayPush=function(r,t){return r.push(t),r},sleep=r=>new Promise((t=>{setTimeout(t,r)})),MappingAsyncIterator=(r,t)=>{const e=new LinkedList;let n=-1,o=!1,s=!1;return{[symbolAsyncIterator](){return this},async _consumeAsyncIterator(){for await(const o of r){n+=1;const r=t(o);e.append(r)}s=!0},async next(){for(o||(this._consumeAsyncIterator(),o=!0);!s;){if(e.length>0){let r=e.popFirst();return isPromise(r)&&(r=await r),{value:r,done:!1}}await sleep(10)}if(e.length>0){let r=e.popFirst();return isPromise(r)&&(r=await r),{value:r,done:!1}}return{value:void 0,done:!0}}}},SerialMappingAsyncIterator=(r,t)=>{const e=new LinkedList;let n=-1,o=!1,s=!1;return{[symbolAsyncIterator](){return this},async _consumeAsyncIterator(){for await(const o of r){n+=1;let r=t(o);isPromise(r)&&(r=await r),e.append(r)}s=!0},async next(){for(o||(this._consumeAsyncIterator(),o=!0);!s;){if(e.length>0)return{value:e.popFirst(),done:!1};await sleep(10)}return e.length>0?{value:e.popFirst(),done:!1}:{value:void 0,done:!0}}}},curry3ResolveArg0=(r,t,e)=>function(n){return r(n,t,e)},curry3ResolveArg1=(r,t,e)=>function(n){return r(t,n,e)},curry3ResolveArg2=(r,t,e)=>function(n){return r(t,e,n)},curry3=function(r,t,e,n){return t==__?curry3ResolveArg0(r,e,n):e==__?curry3ResolveArg1(r,t,n):curry3ResolveArg2(r,t,e)},isArray=Array.isArray,isObject=r=>{if(null==r)return!1;const t=typeof r;return"object"==t||"function"==t},promiseAll=Promise.all.bind(Promise),arrayMap=function(r,t){const e=r.length,n=Array(e);let o=-1,s=!1;for(;++o<e;){const e=t(r[o],o,r);isPromise(e)&&(s=!0),n[o]=e}return s?promiseAll(n):n},callPropUnary=(r,t,e)=>r[t](e),stringMap=function(r,t){const e=arrayMap(r,t);return isPromise(e)?e.then(curry3(callPropUnary,__,"join","")):e.join("")},always=r=>function(){return r},setMap=function(r,t){const e=new Set,n=[];for(const o of r){const s=t(o,o,r);isPromise(s)?n.push(s.then(curry3(callPropUnary,e,"add",__))):e.add(s)}return 0==n.length?e:promiseAll(n).then(always(e))},curry4ResolveArg0=(r,t,e,n)=>function(o){return r(o,t,e,n)},curry4ResolveArg1=(r,t,e,n)=>function(o){return r(t,o,e,n)},curry4ResolveArg2=(r,t,e,n)=>function(o){return r(t,e,o,n)},curry4ResolveArg3=(r,t,e,n)=>function(o){return r(t,e,n,o)},curry4=function(r,t,e,n,o){return t==__?curry4ResolveArg0(r,e,n,o):e==__?curry4ResolveArg1(r,t,n,o):n==__?curry4ResolveArg2(r,t,e,o):curry4ResolveArg3(r,t,e,n)},callPropBinary=(r,t,e,n)=>r[t](e,n),mapMap=function(r,t){const e=new Map,n=[];for(const[o,s]of r){const i=t(s,o,r);isPromise(i)?n.push(i.then(curry4(callPropBinary,e,"set",o,__))):e.set(o,i)}return 0==n.length?e:promiseAll(n).then(always(e))},promiseObjectAllExecutor=r=>function(t){const e={};let n=0;for(const o in r){const s=r[o];isPromise(s)?(n+=1,s.then((r=>function(o){e[r]=o,n-=1,0==n&&t(e)})(o))):e[o]=s}0==n&&t(e)},promiseObjectAll=r=>new Promise(promiseObjectAllExecutor(r)),objectMap=function(r,t){const e={};let n=!1;for(const o in r){const s=t(r[o],o,r);isPromise(s)&&(n=!0),e[o]=s}return n?promiseObjectAll(e):e},funcConcat=(r,t)=>function(...e){const n=r(...e);return isPromise(n)?n.then(t):t(n)},objectSet=function(r,t,e){return r[t]=e,r},arrayMapSeriesAsync=async function(r,t,e,n){const o=r.length;for(;++n<o;){const o=t(r[n],n);e[n]=isPromise(o)?await o:o}return e},arrayMapSeries=function(r,t){const e=r.length,n=Array(e);let o=-1;for(;++o<e;){const e=t(r[o],o);if(isPromise(e))return e.then(funcConcat(curry3(objectSet,n,o,__),curry4(arrayMapSeriesAsync,r,t,__,o)));n[o]=e}return n},stringMapSeries=function(r,t){const e=arrayMapSeries(r,t);return isPromise(e)?e.then(curry3(callPropUnary,__,"join","")):e.join("")},thunkify4=(r,t,e,n,o)=>function(){return r(t,e,n,o)},_objectMapSeriesAsync=async function(r,t,e,n){for(const o in r){if(o in n)continue;let s=t(r[o]);isPromise(s)&&(s=await s),e[o]=s}return e},objectMapSeries=function(r,t){const e={},n={};for(const o in r){n[o]=!0;const s=t(r[o],o,r);if(isPromise(s))return s.then(funcConcat(curry3(objectSet,e,o,__),thunkify4(_objectMapSeriesAsync,r,t,e,n)));e[o]=s}return e},thunkify3=(r,t,e,n)=>function(){return r(t,e,n)},setAdd=function(r,t){return r.add(t),r},_setMapSeriesAsync=async function(r,t,e){let n=r.next();for(;!n.done;){let o=t(n.value);isPromise(o)&&(o=await o),e.add(o),n=r.next()}return e},setMapSeries=function(r,t){const e=new Set,n=r[symbolIterator]();let o=n.next();for(;!o.done;){const r=t(o.value);if(isPromise(r))return r.then(funcConcat(curry2(setAdd,e,__),thunkify3(_setMapSeriesAsync,n,t,e)));e.add(r),o=n.next()}return e},mapSet=function(r,t,e){return r.set(t,e)},_mapMapSeriesAsync=async function(r,t,e){let n=r.next();for(;!n.done;){let o=t(n.value[1]);isPromise(o)&&(o=await o),e.set(n.value[0],o),n=r.next()}return e},mapMapSeries=function(r,t){const e=new Map,n=r[symbolIterator]();let o=n.next();for(;!o.done;){const r=o.value[0],s=t(o.value[1]);if(isPromise(s))return s.then(funcConcat(curry3(mapSet,e,r,__),thunkify3(_mapMapSeriesAsync,n,t,e)));e.set(r,s),o=n.next()}return e},tapSync=r=>function(...t){return r(...t),t[0]},arrayMapPoolAsync=async function(r,t,e,n,o,s){const i=r.length;for(;++o<i;){s.size>=e&&await promiseRace(s);const i=t(r[o]);if(isPromise(i)){const r=i.then(tapSync((()=>s.delete(r))));s.add(r),n[o]=r}else n[o]=i}return promiseAll(n)},arrayMapPool=function(r,t,e){const n=r.length,o=Array(n);let s=-1;for(;++s<n;){const n=e(r[s]);if(isPromise(n)){const i=new Set,c=n.then(tapSync((()=>i.delete(c))));return i.add(c),o[s]=c,arrayMapPoolAsync(r,e,t,o,s,i)}o[s]=n}return o},stringMapPool=function(r,t,e){const n=arrayMapPool(r,t,e);return isPromise(n)?n.then(curry3(callPropUnary,__,"join","")):n.join("")},_setMapPoolAsync=async function(r,t,e,n,o,s){let i=t.next();for(;!i.done;){s.size>=e&&await promiseRace(s);const c=n(i.value,i.value,r);if(isPromise(c)){const r=c.then((t=>{s.delete(r),o.add(t)}));s.add(r)}else o.add(c);i=t.next()}return s.size>0&&await promiseAll(s),o},setMapPool=function(r,t,e){const n=new Set,o=r[symbolIterator]();let s=o.next();for(;!s.done;){const i=e(s.value,s.value,r);if(isPromise(i)){const s=new Set,c=i.then((r=>{s.delete(c),n.add(r)}));return s.add(c),_setMapPoolAsync(r,o,t,e,n,s)}n.add(i),s=o.next()}return n},_mapMapPoolAsync=async function(r,t,e,n,o,s){let i=t.next();for(;!i.done;){s.size>=e&&await promiseRace(s);const c=i.value[0],a=n(i.value[1],c,r);if(isPromise(a)){o.set(c,a);const r=a.then((t=>{s.delete(r),o.set(c,t)}));s.add(r)}else o.set(c,a);i=t.next()}return s.size>0&&await promiseAll(s),o},mapMapPool=function(r,t,e){const n=new Map,o=r[symbolIterator]();let s=o.next();for(;!s.done;){const i=s.value[0],c=e(s.value[1],i,r);if(isPromise(c)){const s=new Set;n.set(i,c);const a=c.then((r=>{s.delete(a),n.set(i,r)}));return s.add(a),_mapMapPoolAsync(r,o,t,e,n,s)}n.set(i,c),s=o.next()}return n},_objectMapPoolAsync=async function(r,t,e,n,o,s){for(const i in r){if(i in o)continue;s.size>=t&&await promiseRace(s);const c=e(r[i],i,r);if(isPromise(c)){n[i]=c;const r=c.then((t=>{s.delete(r),n[i]=t}));s.add(r)}else n[i]=c}return s.size>0&&await promiseAll(s),n},objectMapPool=function(r,t,e){const n={},o={};for(const s in r){o[s]=!0;const i=e(r[s],s,r);if(isPromise(i)){const c=new Set;n[s]=i;const a=i.then((r=>{c.delete(a),n[s]=r}));return c.add(a),_objectMapPoolAsync(r,t,e,n,o,c)}n[s]=i}return n},areAnyValuesPromises=function(r){if(isArray(r)){const t=r.length;let e=-1;for(;++e<t;){const t=r[e];if(isPromise(t))return!0}return!1}for(const t in r){const e=r[t];if(isPromise(e))return!0}return!1},funcApply2=(r,t,e)=>r.apply(t,e),_curryArity=(r,t,e,n)=>function(...o){const s=n.length,i=o.length,c=[];let a=-1,u=-1,l=0;for(;(a+=1)<s;){const s=n[a];if(s==__&&(u+=1)<i){const r=o[u];r==__&&(l+=1),c.push(r)}else c.push(s);if(c.length==r)return areAnyValuesPromises(c)?0==l?promiseAll(c).then(curry3(funcApply2,t,e,__)):promiseAll(c).then(curry4(curryArity,r,t,e,__)):0==l?t.apply(e,c):curryArity(r,t,e,c)}for(;(u+=1)<i;){const n=o[u];if(n==__&&(l+=1),c.push(n),c.length==r)return areAnyValuesPromises(c)?0==l?promiseAll(c).then(curry3(funcApply2,t,e,__)):promiseAll(c).then(curry4(curryArity,r,t,e,__)):0==l?t.apply(e,c):curryArity(r,t,e,c)}return areAnyValuesPromises(c)?promiseAll(c).then(curry4(curryArity,r,t,e,__)):curryArity(r,t,e,c)},curryArity=function(r,t,e,n){const o=n.length;if(o<r)return _curryArity(r,t,e,n);let s=-1;for(;(s+=1)<o;){if(n[s]==__)return _curryArity(r,t,e,n)}return t.apply(e,n)},spread2=r=>function([t,e]){return r(t,e)},objectMapEntries=function(r,t){const e={},n=[];for(const o in r){const s=t([o,r[o]]);isPromise(s)?n.push(s.then(spread2(curryArity(3,objectSet,this,[e])))):e[s[0]]=s[1]}return 0==n.length?e:promiseAll(n).then(always(e))},mapMapEntriesForEachCallback=(r,t,e)=>function(n,o){const s=r([o,n]);isPromise(s)?e.push(s.then(spread2(curryArity(3,mapSet,this,[t])))):t.set(s[0],s[1])},mapMapEntries=function(r,t){const e=new Map,n=[];return r.forEach(mapMapEntriesForEachCallback(t,e,n)),0==n.length?e:promiseAll(n).then(always(e))},_map=function(r,t){return isArray(r)?arrayMap(r,t):null==r?r:"function"==typeof r.then?r.then(t):"string"==typeof r||r.constructor==String?stringMap(r,t):r.constructor==Set?setMap(r,t):r.constructor==Map?mapMap(r,t):"function"==typeof r[symbolIterator]?MappingIterator(r[symbolIterator](),t):"function"==typeof r[symbolAsyncIterator]?MappingAsyncIterator(r[symbolAsyncIterator](),t):"function"==typeof r.map?r.map(t):r.constructor==Object?objectMap(r,t):t(r)},map=function(r,t){return null==t?curry2(_map,__,r):isPromise(r)?r.then(curry2(_map,__,t)):_map(r,t)},_mapEntries=(r,t)=>{if(null==r)throw new TypeError("value is not an Object or Map");if(r.constructor==Object)return objectMapEntries(r,t);if(r.constructor==Map)return mapMapEntries(r,t);throw new TypeError("value is not an Object or Map")};map.entries=function(r,t){return null==t?curry2(_mapEntries,__,r):isPromise(r)?r.then(curry2(_mapEntries,__,t)):_mapEntries(r,t)};const _mapSeries=function(r,t){if(isArray(r))return arrayMapSeries(r,t);if(null==r)throw new TypeError(`invalid functor ${r}`);if("string"==typeof r||r.constructor==String)return stringMapSeries(r,t);if(r.constructor==Set)return setMapSeries(r,t);if(r.constructor==Map)return mapMapSeries(r,t);if("function"==typeof r[symbolIterator])return MappingIterator(r[symbolIterator](),t);if("function"==typeof r[symbolAsyncIterator])return SerialMappingAsyncIterator(r[symbolAsyncIterator](),t);if("function"==typeof r.map)return r.map(t);if(r.constructor==Object)return objectMapSeries(r,t);throw new TypeError(`invalid functor ${r}`)};map.series=function(r,t){return null==t?curry2(_mapSeries,__,r):isPromise(r)?r.then(curry2(_mapSeries,__,t)):_mapSeries(r,t)};const _mapPool=function(r,t,e){if(isArray(r))return arrayMapPool(r,t,e);if(null==r)throw new TypeError(`invalid functor ${r}`);if("string"==typeof r||r.constructor==String)return stringMapPool(r,t,e);if(r.constructor==Set)return setMapPool(r,t,e);if(r.constructor==Map)return mapMapPool(r,t,e);if(r.constructor==Object)return objectMapPool(r,t,e);throw new TypeError(`invalid functor ${r}`)};map.pool=function(r,t,e){return null==e?curry3(_mapPool,__,r,t):isPromise(r)?r.then(curry3(_mapPool,__,t,e)):_mapPool(r,t,e)};export default map;
|
package/dist/map.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Rubico v2.
|
|
2
|
+
* Rubico v2.10.0
|
|
3
3
|
* https://rubico.land/
|
|
4
4
|
*
|
|
5
5
|
* © Richard Yufei Tong, King of Software
|
|
@@ -30,25 +30,7 @@ const MappingIterator = (iterator, mapper) => ({
|
|
|
30
30
|
},
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const symbolAsyncIterator = Symbol.asyncIterator
|
|
36
|
-
|
|
37
|
-
const MappingAsyncIterator = (asyncIterator, mapper) => ({
|
|
38
|
-
[symbolAsyncIterator]() {
|
|
39
|
-
return this
|
|
40
|
-
},
|
|
41
|
-
async next() {
|
|
42
|
-
const iteration = await asyncIterator.next()
|
|
43
|
-
if (iteration.done) {
|
|
44
|
-
return iteration
|
|
45
|
-
}
|
|
46
|
-
const mapped = mapper(iteration.value)
|
|
47
|
-
return isPromise(mapped)
|
|
48
|
-
? mapped.then(NextIteration)
|
|
49
|
-
: { value: mapped, done: false }
|
|
50
|
-
}
|
|
51
|
-
})
|
|
33
|
+
const promiseRace = Promise.race.bind(Promise)
|
|
52
34
|
|
|
53
35
|
const __ = Symbol.for('placeholder')
|
|
54
36
|
|
|
@@ -72,6 +54,165 @@ const curry2 = function (baseFunc, arg0, arg1) {
|
|
|
72
54
|
: curry2ResolveArg1(baseFunc, arg0)
|
|
73
55
|
}
|
|
74
56
|
|
|
57
|
+
class LinkedList {
|
|
58
|
+
constructor() {
|
|
59
|
+
this.first = null
|
|
60
|
+
this.last = null
|
|
61
|
+
this.length = 0
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// popFirst() -> firstValue any
|
|
65
|
+
popFirst() {
|
|
66
|
+
const first = this.first
|
|
67
|
+
|
|
68
|
+
if (first == null) {
|
|
69
|
+
return undefined
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (first.next) {
|
|
73
|
+
this.first = first.next
|
|
74
|
+
} else {
|
|
75
|
+
this.first = null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.length -= 1
|
|
79
|
+
|
|
80
|
+
return first.value
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// append(value any) -> undefined
|
|
84
|
+
append(value) {
|
|
85
|
+
const node = { value }
|
|
86
|
+
if (this.first == null) {
|
|
87
|
+
this.first = node
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (this.last == null) {
|
|
91
|
+
this.last = node
|
|
92
|
+
} else {
|
|
93
|
+
this.last.next = node
|
|
94
|
+
this.last = node
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.length += 1
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const symbolAsyncIterator = Symbol.asyncIterator
|
|
103
|
+
|
|
104
|
+
const arrayPush = function (array, value) {
|
|
105
|
+
array.push(value)
|
|
106
|
+
return array
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const sleep = time => new Promise(resolve => {
|
|
110
|
+
setTimeout(resolve, time)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const MappingAsyncIterator = (asyncIterator, mapper) => {
|
|
114
|
+
const buffer = new LinkedList()
|
|
115
|
+
|
|
116
|
+
let index = -1
|
|
117
|
+
let consumingAsyncIterator = false
|
|
118
|
+
let isAsyncIteratorDone = false
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
[symbolAsyncIterator]() {
|
|
122
|
+
return this
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
// _consumeAsyncIterator() -> Promise<>
|
|
126
|
+
async _consumeAsyncIterator() {
|
|
127
|
+
for await (const item of asyncIterator) {
|
|
128
|
+
index += 1
|
|
129
|
+
const mappedItem = mapper(item)
|
|
130
|
+
buffer.append(mappedItem)
|
|
131
|
+
}
|
|
132
|
+
isAsyncIteratorDone = true
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
async next() {
|
|
137
|
+
if (!consumingAsyncIterator) {
|
|
138
|
+
this._consumeAsyncIterator()
|
|
139
|
+
consumingAsyncIterator = true
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
while (!isAsyncIteratorDone) {
|
|
143
|
+
if (buffer.length > 0) {
|
|
144
|
+
let value = buffer.popFirst()
|
|
145
|
+
if (isPromise(value)) {
|
|
146
|
+
value = await value
|
|
147
|
+
}
|
|
148
|
+
return { value, done: false }
|
|
149
|
+
}
|
|
150
|
+
await sleep(10)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (buffer.length > 0) {
|
|
154
|
+
let value = buffer.popFirst()
|
|
155
|
+
if (isPromise(value)) {
|
|
156
|
+
value = await value
|
|
157
|
+
}
|
|
158
|
+
return { value, done: false }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return { value: undefined, done: true }
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const SerialMappingAsyncIterator = (asyncIterator, mapper) => {
|
|
168
|
+
const buffer = new LinkedList()
|
|
169
|
+
|
|
170
|
+
let index = -1
|
|
171
|
+
let consumingAsyncIterator = false
|
|
172
|
+
let isAsyncIteratorDone = false
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
[symbolAsyncIterator]() {
|
|
176
|
+
return this
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
// _consumeAsyncIterator() -> Promise<>
|
|
180
|
+
async _consumeAsyncIterator() {
|
|
181
|
+
for await (const item of asyncIterator) {
|
|
182
|
+
index += 1
|
|
183
|
+
let mappedItem = mapper(item)
|
|
184
|
+
if (isPromise(mappedItem)) {
|
|
185
|
+
mappedItem = await mappedItem
|
|
186
|
+
}
|
|
187
|
+
buffer.append(mappedItem)
|
|
188
|
+
}
|
|
189
|
+
isAsyncIteratorDone = true
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
async next() {
|
|
194
|
+
if (!consumingAsyncIterator) {
|
|
195
|
+
this._consumeAsyncIterator()
|
|
196
|
+
consumingAsyncIterator = true
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
while (!isAsyncIteratorDone) {
|
|
200
|
+
if (buffer.length > 0) {
|
|
201
|
+
return { value: buffer.popFirst(), done: false }
|
|
202
|
+
}
|
|
203
|
+
await sleep(10)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (buffer.length > 0) {
|
|
207
|
+
return { value: buffer.popFirst(), done: false }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { value: undefined, done: true }
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
75
216
|
// argument resolver for curry3
|
|
76
217
|
const curry3ResolveArg0 = (
|
|
77
218
|
baseFunc, arg1, arg2,
|
|
@@ -438,8 +579,6 @@ const tapSync = func => function tapping(...args) {
|
|
|
438
579
|
return args[0]
|
|
439
580
|
}
|
|
440
581
|
|
|
441
|
-
const promiseRace = Promise.race.bind(Promise)
|
|
442
|
-
|
|
443
582
|
const arrayMapPoolAsync = async function (
|
|
444
583
|
array, f, concurrencyLimit, result, index, promises,
|
|
445
584
|
) {
|
|
@@ -667,7 +806,7 @@ const _curryArity = (arity, func, context, args) => function curried(...curriedA
|
|
|
667
806
|
curriedArgsIndex = -1,
|
|
668
807
|
numCurriedPlaceholders = 0
|
|
669
808
|
|
|
670
|
-
while (
|
|
809
|
+
while ((argsIndex += 1) < argsLength) {
|
|
671
810
|
const arg = args[argsIndex]
|
|
672
811
|
if (arg == __ && (curriedArgsIndex += 1) < curriedArgsLength) {
|
|
673
812
|
const curriedArg = curriedArgs[curriedArgsIndex]
|
|
@@ -691,7 +830,7 @@ const _curryArity = (arity, func, context, args) => function curried(...curriedA
|
|
|
691
830
|
}
|
|
692
831
|
}
|
|
693
832
|
|
|
694
|
-
while (
|
|
833
|
+
while ((curriedArgsIndex += 1) < curriedArgsLength) {
|
|
695
834
|
const curriedArg = curriedArgs[curriedArgsIndex]
|
|
696
835
|
if (curriedArg == __) {
|
|
697
836
|
numCurriedPlaceholders += 1
|
|
@@ -721,7 +860,7 @@ const curryArity = function (arity, func, context, args) {
|
|
|
721
860
|
return _curryArity(arity, func, context, args)
|
|
722
861
|
}
|
|
723
862
|
let argsIndex = -1
|
|
724
|
-
while (
|
|
863
|
+
while ((argsIndex += 1) < argsLength) {
|
|
725
864
|
const arg = args[argsIndex]
|
|
726
865
|
if (arg == __) {
|
|
727
866
|
return _curryArity(arity, func, context, args)
|
|
@@ -784,9 +923,6 @@ const _map = function (value, f) {
|
|
|
784
923
|
if (typeof value.then == 'function') {
|
|
785
924
|
return value.then(f)
|
|
786
925
|
}
|
|
787
|
-
if (typeof value.map == 'function') {
|
|
788
|
-
return value.map(f)
|
|
789
|
-
}
|
|
790
926
|
if (typeof value == 'string' || value.constructor == String) {
|
|
791
927
|
return stringMap(value, f)
|
|
792
928
|
}
|
|
@@ -802,6 +938,9 @@ const _map = function (value, f) {
|
|
|
802
938
|
if (typeof value[symbolAsyncIterator] == 'function') {
|
|
803
939
|
return MappingAsyncIterator(value[symbolAsyncIterator](), f)
|
|
804
940
|
}
|
|
941
|
+
if (typeof value.map == 'function') {
|
|
942
|
+
return value.map(f)
|
|
943
|
+
}
|
|
805
944
|
if (value.constructor == Object) {
|
|
806
945
|
return objectMap(value, f)
|
|
807
946
|
}
|
|
@@ -840,27 +979,36 @@ map.entries = function mapEntries(arg0, arg1) {
|
|
|
840
979
|
: _mapEntries(arg0, arg1)
|
|
841
980
|
}
|
|
842
981
|
|
|
843
|
-
const _mapSeries = function (
|
|
844
|
-
if (isArray(
|
|
845
|
-
return arrayMapSeries(
|
|
982
|
+
const _mapSeries = function (functor, f) {
|
|
983
|
+
if (isArray(functor)) {
|
|
984
|
+
return arrayMapSeries(functor, f)
|
|
846
985
|
}
|
|
847
|
-
if (
|
|
848
|
-
throw new TypeError(`invalid
|
|
986
|
+
if (functor == null) {
|
|
987
|
+
throw new TypeError(`invalid functor ${functor}`)
|
|
849
988
|
}
|
|
850
989
|
|
|
851
|
-
if (typeof
|
|
852
|
-
return stringMapSeries(
|
|
990
|
+
if (typeof functor == 'string' || functor.constructor == String) {
|
|
991
|
+
return stringMapSeries(functor, f)
|
|
992
|
+
}
|
|
993
|
+
if (functor.constructor == Set) {
|
|
994
|
+
return setMapSeries(functor, f)
|
|
995
|
+
}
|
|
996
|
+
if (functor.constructor == Map) {
|
|
997
|
+
return mapMapSeries(functor, f)
|
|
998
|
+
}
|
|
999
|
+
if (typeof functor[symbolIterator] == 'function') {
|
|
1000
|
+
return MappingIterator(functor[symbolIterator](), f)
|
|
853
1001
|
}
|
|
854
|
-
if (
|
|
855
|
-
return
|
|
1002
|
+
if (typeof functor[symbolAsyncIterator] == 'function') {
|
|
1003
|
+
return SerialMappingAsyncIterator(functor[symbolAsyncIterator](), f)
|
|
856
1004
|
}
|
|
857
|
-
if (
|
|
858
|
-
return
|
|
1005
|
+
if (typeof functor.map == 'function') {
|
|
1006
|
+
return functor.map(f)
|
|
859
1007
|
}
|
|
860
|
-
if (
|
|
861
|
-
return objectMapSeries(
|
|
1008
|
+
if (functor.constructor == Object) {
|
|
1009
|
+
return objectMapSeries(functor, f)
|
|
862
1010
|
}
|
|
863
|
-
throw new TypeError(`invalid
|
|
1011
|
+
throw new TypeError(`invalid functor ${functor}`)
|
|
864
1012
|
}
|
|
865
1013
|
|
|
866
1014
|
map.series = function mapSeries(arg0, arg1) {
|