rubico 2.3.7 → 2.4.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/_internal/arrayForEachSeries.js +48 -0
- package/_internal/asyncIteratorForEachSeries.js +28 -0
- package/_internal/iteratorForEachSeries.js +46 -0
- package/_internal/objectForEachSeries.js +44 -0
- package/_internal/series.js +4 -0
- 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 +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 +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 +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 +140 -9
- package/dist/forEach.es.min.js +2 -2
- package/dist/forEach.js +140 -9
- package/dist/forEach.min.js +2 -2
- package/dist/forEach.mjs +140 -9
- 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 +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 +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 +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 +132 -9
- package/dist/rubico.es.min.js +2 -2
- package/dist/rubico.global.js +132 -9
- package/dist/rubico.global.min.js +2 -2
- package/dist/rubico.js +132 -9
- package/dist/rubico.min.js +2 -2
- package/dist/rubico.mjs +132 -9
- 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 +1 -1
- package/dist/x/filterOut.es.min.js +1 -1
- package/dist/x/filterOut.js +1 -1
- package/dist/x/filterOut.min.js +1 -1
- package/dist/x/filterOut.mjs +1 -1
- 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 +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/es.js +132 -9
- package/forEach.js +73 -12
- package/index.js +132 -9
- package/package.json +1 -1
- package/tap.js +1 -1
package/dist/x/values.mjs
CHANGED
package/dist/x/when.es.js
CHANGED
package/dist/x/when.es.min.js
CHANGED
package/dist/x/when.js
CHANGED
package/dist/x/when.min.js
CHANGED
package/dist/x/when.mjs
CHANGED
package/es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* rubico v2.
|
|
2
|
+
* rubico v2.4.0
|
|
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.
|
|
@@ -1902,6 +1902,103 @@ const iteratorForEach = function (iterator, callback) {
|
|
|
1902
1902
|
return promises.length == 0 ? iterator : promiseAll(promises).then(always(iterator))
|
|
1903
1903
|
}
|
|
1904
1904
|
|
|
1905
|
+
// _arrayForEachSeriesAsync(
|
|
1906
|
+
// array Array,
|
|
1907
|
+
// callback function,
|
|
1908
|
+
// index number
|
|
1909
|
+
// ) -> Promise<array>
|
|
1910
|
+
const _arrayForEachSeriesAsync = async function (array, callback, index) {
|
|
1911
|
+
const length = array.length
|
|
1912
|
+
while (++index < length) {
|
|
1913
|
+
const operation = callback(array[index])
|
|
1914
|
+
if (isPromise(operation)) {
|
|
1915
|
+
await operation
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
return array
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
const arrayForEachSeries = function (array, callback) {
|
|
1922
|
+
const length = array.length
|
|
1923
|
+
let index = -1
|
|
1924
|
+
while (++index < length) {
|
|
1925
|
+
const operation = callback(array[index])
|
|
1926
|
+
if (isPromise(operation)) {
|
|
1927
|
+
return operation
|
|
1928
|
+
.then(thunkify3(_arrayForEachSeriesAsync, array, callback, index))
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
return array
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
// _objectForEachSeriesAsync(
|
|
1935
|
+
// object Object,
|
|
1936
|
+
// callback function,
|
|
1937
|
+
// firstKey string
|
|
1938
|
+
// ) -> Promise<object>
|
|
1939
|
+
const _objectForEachSeriesAsync = async function (object, callback, firstKey) {
|
|
1940
|
+
for (const key in object) {
|
|
1941
|
+
if (key == firstKey) {
|
|
1942
|
+
continue
|
|
1943
|
+
}
|
|
1944
|
+
const operation = callback(object[key])
|
|
1945
|
+
if (isPromise(operation)) {
|
|
1946
|
+
await operation
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
return object
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
const objectForEachSeries = function (object, callback) {
|
|
1953
|
+
for (const key in object) {
|
|
1954
|
+
const operation = callback(object[key])
|
|
1955
|
+
if (isPromise(operation)) {
|
|
1956
|
+
return operation
|
|
1957
|
+
.then(thunkify3(_objectForEachSeriesAsync, object, callback, key))
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
return object
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
// _iteratorForEachSeriesAsync(
|
|
1964
|
+
// iterator Iterator,
|
|
1965
|
+
// callback function,
|
|
1966
|
+
// ) -> Promise<iterator>
|
|
1967
|
+
const _iteratorForEachSeriesAsync = async function (iterator, callback) {
|
|
1968
|
+
let iteration = iterator.next()
|
|
1969
|
+
while (!iteration.done) {
|
|
1970
|
+
const operation = callback(iteration.value)
|
|
1971
|
+
if (isPromise(operation)) {
|
|
1972
|
+
await operation
|
|
1973
|
+
}
|
|
1974
|
+
iteration = iterator.next()
|
|
1975
|
+
}
|
|
1976
|
+
return iterator
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
const iteratorForEachSeries = function (iterator, callback) {
|
|
1980
|
+
let iteration = iterator.next()
|
|
1981
|
+
while (!iterator.done) {
|
|
1982
|
+
const operation = callback(iteration.value)
|
|
1983
|
+
if (isPromise(operation)) {
|
|
1984
|
+
return operation
|
|
1985
|
+
.then(thunkify2(_iteratorForEachSeriesAsync, iterator, callback))
|
|
1986
|
+
}
|
|
1987
|
+
iteration = iterator.next()
|
|
1988
|
+
}
|
|
1989
|
+
return iterator
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
const asyncIteratorForEachSeries = async function (asyncIterator, callback) {
|
|
1993
|
+
for await (const item of asyncIterator) {
|
|
1994
|
+
const operation = callback(item)
|
|
1995
|
+
if (isPromise(operation)) {
|
|
1996
|
+
await operation
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
return asyncIterator
|
|
2000
|
+
}
|
|
2001
|
+
|
|
1905
2002
|
// type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
|
|
1906
2003
|
// _forEach(collection Collection, callback function) -> collection Collection
|
|
1907
2004
|
const _forEach = function (collection, callback) {
|
|
@@ -1926,15 +2023,41 @@ const _forEach = function (collection, callback) {
|
|
|
1926
2023
|
return collection
|
|
1927
2024
|
}
|
|
1928
2025
|
|
|
1929
|
-
const forEach = function (
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
return curry2(_forEach, __, callback)
|
|
2026
|
+
const forEach = function (arg0, arg1) {
|
|
2027
|
+
if (typeof arg0 == 'function') {
|
|
2028
|
+
return curry2(_forEach, __, arg0)
|
|
1933
2029
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
2030
|
+
return isPromise(arg0)
|
|
2031
|
+
? arg0.then(curry2(_forEach, __, arg1))
|
|
2032
|
+
: _forEach(arg0, arg1)
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
const _forEachSeries = function (collection, callback) {
|
|
2036
|
+
if (isArray(collection)) {
|
|
2037
|
+
return arrayForEachSeries(collection, callback)
|
|
2038
|
+
}
|
|
2039
|
+
if (collection == null) {
|
|
2040
|
+
throw new Error(`invalid collection ${collection}`)
|
|
2041
|
+
}
|
|
2042
|
+
if (typeof collection[symbolIterator] == 'function') {
|
|
2043
|
+
return iteratorForEachSeries(collection[symbolIterator](), callback)
|
|
2044
|
+
}
|
|
2045
|
+
if (typeof collection[symbolAsyncIterator] == 'function') {
|
|
2046
|
+
return asyncIteratorForEachSeries(collection[symbolAsyncIterator](), callback)
|
|
2047
|
+
}
|
|
2048
|
+
if (collection.constructor == Object) {
|
|
2049
|
+
return objectForEachSeries(collection, callback)
|
|
2050
|
+
}
|
|
2051
|
+
throw new Error(`invalid collection ${collection}`)
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
forEach.series = function forEachSeries(arg0, arg1) {
|
|
2055
|
+
if (typeof arg0 == 'function') {
|
|
2056
|
+
return curry2(_forEachSeries, __, arg0)
|
|
2057
|
+
}
|
|
2058
|
+
return isPromise(arg0)
|
|
2059
|
+
? arg0.then(curry2(_forEachSeries, __, arg1))
|
|
2060
|
+
: _forEachSeries(arg0, arg1)
|
|
1938
2061
|
}
|
|
1939
2062
|
|
|
1940
2063
|
const SelfReferencingPromise = function (basePromise) {
|
package/forEach.js
CHANGED
|
@@ -10,6 +10,10 @@ const iteratorForEach = require('./_internal/iteratorForEach')
|
|
|
10
10
|
const asyncIteratorForEach = require('./_internal/asyncIteratorForEach')
|
|
11
11
|
const symbolIterator = require('./_internal/symbolIterator')
|
|
12
12
|
const symbolAsyncIterator = require('./_internal/symbolAsyncIterator')
|
|
13
|
+
const arrayForEachSeries = require('./_internal/arrayForEachSeries')
|
|
14
|
+
const objectForEachSeries = require('./_internal/objectForEachSeries')
|
|
15
|
+
const iteratorForEachSeries = require('./_internal/iteratorForEachSeries')
|
|
16
|
+
const asyncIteratorForEachSeries = require('./_internal/asyncIteratorForEachSeries')
|
|
13
17
|
|
|
14
18
|
// type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
|
|
15
19
|
// _forEach(collection Collection, callback function) -> collection Collection
|
|
@@ -42,16 +46,16 @@ const _forEach = function (collection, callback) {
|
|
|
42
46
|
* ```coffeescript [specscript]
|
|
43
47
|
* type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
|
|
44
48
|
*
|
|
45
|
-
* forEach(collection Collection, callback function) -> collection Collection
|
|
49
|
+
* forEach(collection Collection, callback function) -> collection Promise|Collection
|
|
46
50
|
*
|
|
47
|
-
* forEach(callback function)(collection Collection) -> collection Collection
|
|
51
|
+
* forEach(callback function)(collection Collection) -> collection Promise|Collection
|
|
48
52
|
* ```
|
|
49
53
|
*
|
|
50
54
|
* @description
|
|
51
|
-
* Execute a callback for each item of a collection, returning a Promise if the execution is asynchronous.
|
|
55
|
+
* Execute a callback for each item of a collection, returning a Promise if the execution is asynchronous. Asynchronous execution happens concurrently.
|
|
52
56
|
*
|
|
53
57
|
* ```javascript [playground]
|
|
54
|
-
* forEach([1, 2, 3, 4,
|
|
58
|
+
* forEach([1, 2, 3, 4, 5], console.log) // 1 2 3 4 5
|
|
55
59
|
*
|
|
56
60
|
* forEach({ a: 1, b: 2, c: 3 }, console.log) // 1 2 3
|
|
57
61
|
* ```
|
|
@@ -68,15 +72,72 @@ const _forEach = function (collection, callback) {
|
|
|
68
72
|
* ])
|
|
69
73
|
* ```
|
|
70
74
|
*/
|
|
71
|
-
const forEach = function (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return curry2(_forEach, __, callback)
|
|
75
|
+
const forEach = function (arg0, arg1) {
|
|
76
|
+
if (typeof arg0 == 'function') {
|
|
77
|
+
return curry2(_forEach, __, arg0)
|
|
75
78
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
return isPromise(arg0)
|
|
80
|
+
? arg0.then(curry2(_forEach, __, arg1))
|
|
81
|
+
: _forEach(arg0, arg1)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @name _forEachSeries
|
|
86
|
+
*
|
|
87
|
+
* @synopsis
|
|
88
|
+
* ```coffeescript [specscript]
|
|
89
|
+
* type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
|
|
90
|
+
*
|
|
91
|
+
* _forEachSeries(collection Collection, callback function) -> collection Promise|Collection
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
const _forEachSeries = function (collection, callback) {
|
|
95
|
+
if (isArray(collection)) {
|
|
96
|
+
return arrayForEachSeries(collection, callback)
|
|
97
|
+
}
|
|
98
|
+
if (collection == null) {
|
|
99
|
+
throw new Error(`invalid collection ${collection}`)
|
|
100
|
+
}
|
|
101
|
+
if (typeof collection[symbolIterator] == 'function') {
|
|
102
|
+
return iteratorForEachSeries(collection[symbolIterator](), callback)
|
|
103
|
+
}
|
|
104
|
+
if (typeof collection[symbolAsyncIterator] == 'function') {
|
|
105
|
+
return asyncIteratorForEachSeries(collection[symbolAsyncIterator](), callback)
|
|
106
|
+
}
|
|
107
|
+
if (collection.constructor == Object) {
|
|
108
|
+
return objectForEachSeries(collection, callback)
|
|
109
|
+
}
|
|
110
|
+
throw new Error(`invalid collection ${collection}`)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @name forEach.series
|
|
115
|
+
*
|
|
116
|
+
* @synopsis
|
|
117
|
+
* ```coffeescript [specscript]
|
|
118
|
+
* type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
|
|
119
|
+
*
|
|
120
|
+
* forEach.series(collection Collection, callback function) -> collection Promise|Collection
|
|
121
|
+
*
|
|
122
|
+
* forEach.series(callback function)(collection Collection) -> collection Promise|Collection
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @description
|
|
126
|
+
* Execute a callback for each item of a collection, returning a Promise if the execution is asynchronous. Asynchronous execution happens in series.
|
|
127
|
+
*
|
|
128
|
+
* ```javascript [playground]
|
|
129
|
+
* forEach.series([1, 2, 3, 4, 5], console.log) // 1 2 3 4 5
|
|
130
|
+
*
|
|
131
|
+
* forEach.series({ a: 1, b: 2, c: 3 }, console.log) // 1 2 3
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
forEach.series = function forEachSeries(arg0, arg1) {
|
|
135
|
+
if (typeof arg0 == 'function') {
|
|
136
|
+
return curry2(_forEachSeries, __, arg0)
|
|
137
|
+
}
|
|
138
|
+
return isPromise(arg0)
|
|
139
|
+
? arg0.then(curry2(_forEachSeries, __, arg1))
|
|
140
|
+
: _forEachSeries(arg0, arg1)
|
|
80
141
|
}
|
|
81
142
|
|
|
82
143
|
module.exports = forEach
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* rubico v2.
|
|
2
|
+
* rubico v2.4.0
|
|
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.
|
|
@@ -1908,6 +1908,103 @@ const iteratorForEach = function (iterator, callback) {
|
|
|
1908
1908
|
return promises.length == 0 ? iterator : promiseAll(promises).then(always(iterator))
|
|
1909
1909
|
}
|
|
1910
1910
|
|
|
1911
|
+
// _arrayForEachSeriesAsync(
|
|
1912
|
+
// array Array,
|
|
1913
|
+
// callback function,
|
|
1914
|
+
// index number
|
|
1915
|
+
// ) -> Promise<array>
|
|
1916
|
+
const _arrayForEachSeriesAsync = async function (array, callback, index) {
|
|
1917
|
+
const length = array.length
|
|
1918
|
+
while (++index < length) {
|
|
1919
|
+
const operation = callback(array[index])
|
|
1920
|
+
if (isPromise(operation)) {
|
|
1921
|
+
await operation
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
return array
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
const arrayForEachSeries = function (array, callback) {
|
|
1928
|
+
const length = array.length
|
|
1929
|
+
let index = -1
|
|
1930
|
+
while (++index < length) {
|
|
1931
|
+
const operation = callback(array[index])
|
|
1932
|
+
if (isPromise(operation)) {
|
|
1933
|
+
return operation
|
|
1934
|
+
.then(thunkify3(_arrayForEachSeriesAsync, array, callback, index))
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return array
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
// _objectForEachSeriesAsync(
|
|
1941
|
+
// object Object,
|
|
1942
|
+
// callback function,
|
|
1943
|
+
// firstKey string
|
|
1944
|
+
// ) -> Promise<object>
|
|
1945
|
+
const _objectForEachSeriesAsync = async function (object, callback, firstKey) {
|
|
1946
|
+
for (const key in object) {
|
|
1947
|
+
if (key == firstKey) {
|
|
1948
|
+
continue
|
|
1949
|
+
}
|
|
1950
|
+
const operation = callback(object[key])
|
|
1951
|
+
if (isPromise(operation)) {
|
|
1952
|
+
await operation
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
return object
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
const objectForEachSeries = function (object, callback) {
|
|
1959
|
+
for (const key in object) {
|
|
1960
|
+
const operation = callback(object[key])
|
|
1961
|
+
if (isPromise(operation)) {
|
|
1962
|
+
return operation
|
|
1963
|
+
.then(thunkify3(_objectForEachSeriesAsync, object, callback, key))
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
return object
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
// _iteratorForEachSeriesAsync(
|
|
1970
|
+
// iterator Iterator,
|
|
1971
|
+
// callback function,
|
|
1972
|
+
// ) -> Promise<iterator>
|
|
1973
|
+
const _iteratorForEachSeriesAsync = async function (iterator, callback) {
|
|
1974
|
+
let iteration = iterator.next()
|
|
1975
|
+
while (!iteration.done) {
|
|
1976
|
+
const operation = callback(iteration.value)
|
|
1977
|
+
if (isPromise(operation)) {
|
|
1978
|
+
await operation
|
|
1979
|
+
}
|
|
1980
|
+
iteration = iterator.next()
|
|
1981
|
+
}
|
|
1982
|
+
return iterator
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
const iteratorForEachSeries = function (iterator, callback) {
|
|
1986
|
+
let iteration = iterator.next()
|
|
1987
|
+
while (!iterator.done) {
|
|
1988
|
+
const operation = callback(iteration.value)
|
|
1989
|
+
if (isPromise(operation)) {
|
|
1990
|
+
return operation
|
|
1991
|
+
.then(thunkify2(_iteratorForEachSeriesAsync, iterator, callback))
|
|
1992
|
+
}
|
|
1993
|
+
iteration = iterator.next()
|
|
1994
|
+
}
|
|
1995
|
+
return iterator
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
const asyncIteratorForEachSeries = async function (asyncIterator, callback) {
|
|
1999
|
+
for await (const item of asyncIterator) {
|
|
2000
|
+
const operation = callback(item)
|
|
2001
|
+
if (isPromise(operation)) {
|
|
2002
|
+
await operation
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
return asyncIterator
|
|
2006
|
+
}
|
|
2007
|
+
|
|
1911
2008
|
// type Collection = Array|Iterable|AsyncIterable|{ forEach: function }|Object
|
|
1912
2009
|
// _forEach(collection Collection, callback function) -> collection Collection
|
|
1913
2010
|
const _forEach = function (collection, callback) {
|
|
@@ -1932,15 +2029,41 @@ const _forEach = function (collection, callback) {
|
|
|
1932
2029
|
return collection
|
|
1933
2030
|
}
|
|
1934
2031
|
|
|
1935
|
-
const forEach = function (
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
return curry2(_forEach, __, callback)
|
|
2032
|
+
const forEach = function (arg0, arg1) {
|
|
2033
|
+
if (typeof arg0 == 'function') {
|
|
2034
|
+
return curry2(_forEach, __, arg0)
|
|
1939
2035
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
2036
|
+
return isPromise(arg0)
|
|
2037
|
+
? arg0.then(curry2(_forEach, __, arg1))
|
|
2038
|
+
: _forEach(arg0, arg1)
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
const _forEachSeries = function (collection, callback) {
|
|
2042
|
+
if (isArray(collection)) {
|
|
2043
|
+
return arrayForEachSeries(collection, callback)
|
|
2044
|
+
}
|
|
2045
|
+
if (collection == null) {
|
|
2046
|
+
throw new Error(`invalid collection ${collection}`)
|
|
2047
|
+
}
|
|
2048
|
+
if (typeof collection[symbolIterator] == 'function') {
|
|
2049
|
+
return iteratorForEachSeries(collection[symbolIterator](), callback)
|
|
2050
|
+
}
|
|
2051
|
+
if (typeof collection[symbolAsyncIterator] == 'function') {
|
|
2052
|
+
return asyncIteratorForEachSeries(collection[symbolAsyncIterator](), callback)
|
|
2053
|
+
}
|
|
2054
|
+
if (collection.constructor == Object) {
|
|
2055
|
+
return objectForEachSeries(collection, callback)
|
|
2056
|
+
}
|
|
2057
|
+
throw new Error(`invalid collection ${collection}`)
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
forEach.series = function forEachSeries(arg0, arg1) {
|
|
2061
|
+
if (typeof arg0 == 'function') {
|
|
2062
|
+
return curry2(_forEachSeries, __, arg0)
|
|
2063
|
+
}
|
|
2064
|
+
return isPromise(arg0)
|
|
2065
|
+
? arg0.then(curry2(_forEachSeries, __, arg1))
|
|
2066
|
+
: _forEachSeries(arg0, arg1)
|
|
1944
2067
|
}
|
|
1945
2068
|
|
|
1946
2069
|
const SelfReferencingPromise = function (basePromise) {
|
package/package.json
CHANGED
package/tap.js
CHANGED
|
@@ -23,7 +23,7 @@ const _tap = function (args, func) {
|
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
25
25
|
* @description
|
|
26
|
-
* Call a function with
|
|
26
|
+
* Call a function with provided arguments, returning the first argument. The return value of the function call is discarded.
|
|
27
27
|
*
|
|
28
28
|
* ```javascript [playground]
|
|
29
29
|
* const pipeline = pipe([
|