rubico 2.8.6 → 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 +1 -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/iteratorFind.js +0 -2
- package/_internal/iteratorForEachSeries.js +1 -1
- package/_internal/objectFlatten.js +4 -1
- package/all.js +7 -8
- package/and.js +1 -1
- package/assign.js +1 -1
- package/compose.js +1 -1
- 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 +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 +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 +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 +187 -39
- package/dist/map.es.min.js +2 -2
- package/dist/map.js +187 -39
- package/dist/map.min.js +2 -2
- package/dist/map.mjs +187 -39
- 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 +233 -78
- package/dist/rubico.es.min.js +2 -2
- package/dist/rubico.global.js +233 -78
- package/dist/rubico.global.min.js +2 -2
- package/dist/rubico.js +233 -78
- package/dist/rubico.min.js +2 -2
- package/dist/rubico.mjs +233 -78
- 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 +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 +187 -39
- package/dist/x/pluck.es.min.js +2 -2
- package/dist/x/pluck.js +187 -39
- package/dist/x/pluck.min.js +2 -2
- package/dist/x/pluck.mjs +187 -39
- 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 +233 -78
- package/every.js +2 -2
- package/filter.js +4 -4
- package/flatMap.js +61 -54
- package/forEach.js +33 -56
- package/get.js +5 -3
- package/gt.js +2 -2
- package/gte.js +2 -2
- package/index.js +233 -78
- package/lt.js +2 -2
- package/lte.js +2 -2
- package/map.js +115 -151
- package/monad/README.md +1 -1
- 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 +1 -1
- package/reduce.js +1 -1
- package/set.js +17 -18
- package/some.js +2 -2
- package/switchCase.js +12 -4
- package/tap.js +6 -4
- package/transform.js +1 -1
- package/tryCatch.js +1 -1
- 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/lte.js
CHANGED
|
@@ -58,7 +58,7 @@ const lessThanOrEqual = require('./_internal/lessThanOrEqual')
|
|
|
58
58
|
* asyncIsLessThanOrEqualTo3(5).then(console.log) // false
|
|
59
59
|
* ```
|
|
60
60
|
*
|
|
61
|
-
* `lte` supports a lazy
|
|
61
|
+
* `lte` supports a lazy interface for composability.
|
|
62
62
|
*
|
|
63
63
|
* ```javascript [playground]
|
|
64
64
|
* pipe({ value: 1 }, [
|
|
@@ -67,7 +67,7 @@ const lessThanOrEqual = require('./_internal/lessThanOrEqual')
|
|
|
67
67
|
* ])
|
|
68
68
|
* ```
|
|
69
69
|
*
|
|
70
|
-
* Any promises passed in argument position are resolved for their values before further execution.
|
|
70
|
+
* Any promises passed in data argument position are resolved for their values before further execution.
|
|
71
71
|
*
|
|
72
72
|
* ```javascript [playground]
|
|
73
73
|
* lte(Promise.resolve({ a: 1, b: 1 }), get('a'), get('b')).then(console.log) // true
|
package/map.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const isPromise = require('./_internal/isPromise')
|
|
2
2
|
const MappingIterator = require('./_internal/MappingIterator')
|
|
3
3
|
const MappingAsyncIterator = require('./_internal/MappingAsyncIterator')
|
|
4
|
+
const SerialMappingAsyncIterator = require('./_internal/SerialMappingAsyncIterator')
|
|
4
5
|
const __ = require('./_internal/placeholder')
|
|
5
6
|
const curry2 = require('./_internal/curry2')
|
|
6
7
|
const curry3 = require('./_internal/curry3')
|
|
@@ -64,9 +65,6 @@ const _map = function (value, f) {
|
|
|
64
65
|
if (typeof value.then == 'function') {
|
|
65
66
|
return value.then(f)
|
|
66
67
|
}
|
|
67
|
-
if (typeof value.map == 'function') {
|
|
68
|
-
return value.map(f)
|
|
69
|
-
}
|
|
70
68
|
if (typeof value == 'string' || value.constructor == String) {
|
|
71
69
|
return stringMap(value, f)
|
|
72
70
|
}
|
|
@@ -82,6 +80,9 @@ const _map = function (value, f) {
|
|
|
82
80
|
if (typeof value[symbolAsyncIterator] == 'function') {
|
|
83
81
|
return MappingAsyncIterator(value[symbolAsyncIterator](), f)
|
|
84
82
|
}
|
|
83
|
+
if (typeof value.map == 'function') {
|
|
84
|
+
return value.map(f)
|
|
85
|
+
}
|
|
85
86
|
if (value.constructor == Object) {
|
|
86
87
|
return objectMap(value, f)
|
|
87
88
|
}
|
|
@@ -96,17 +97,17 @@ const _map = function (value, f) {
|
|
|
96
97
|
* type Functor = Array|Set|Map|Generator|AsyncGenerator|{ map: function }|Object
|
|
97
98
|
*
|
|
98
99
|
* type SyncOrAsyncMapper = (
|
|
99
|
-
*
|
|
100
|
+
* item any,
|
|
100
101
|
* indexOrKey number|string|any,
|
|
101
102
|
* functor Functor
|
|
102
|
-
* )=>(
|
|
103
|
+
* )=>(mappedItem Promise|any)
|
|
103
104
|
*
|
|
104
|
-
* map(functor Promise|Functor, mapper SyncOrAsyncMapper) ->
|
|
105
|
-
* map(mapper SyncOrAsyncMapper)(functor Functor) ->
|
|
105
|
+
* map(functor Promise|Functor, mapper SyncOrAsyncMapper) -> mappedFunctor Promise|Functor
|
|
106
|
+
* map(mapper SyncOrAsyncMapper)(functor Functor) -> mappedFunctor Promise|Functor
|
|
106
107
|
* ```
|
|
107
108
|
*
|
|
108
109
|
* @description
|
|
109
|
-
* Applies a mapper function to each
|
|
110
|
+
* Applies a mapper function to each item of a functor, returning a mapped functor of the same type with the mapped items. The order of the elements is maintained.
|
|
110
111
|
*
|
|
111
112
|
* The following data types are considered to be functors:
|
|
112
113
|
* * `array`
|
|
@@ -117,12 +118,13 @@ const _map = function (value, f) {
|
|
|
117
118
|
* * `object with .map method`
|
|
118
119
|
* * `object`
|
|
119
120
|
*
|
|
120
|
-
* The mapper function defines a mapping between a given
|
|
121
|
+
* The mapper function defines a mapping between a given item and an item in the returned functor.
|
|
121
122
|
*
|
|
122
123
|
* ```javascript
|
|
123
|
-
* const mapper = function (
|
|
124
|
-
* //
|
|
125
|
-
*
|
|
124
|
+
* const mapper = function (item) {
|
|
125
|
+
* // ...
|
|
126
|
+
* // mappedItem is mapped from item
|
|
127
|
+
* return mappedItem
|
|
126
128
|
* }
|
|
127
129
|
* ```
|
|
128
130
|
*
|
|
@@ -130,48 +132,52 @@ const _map = function (value, f) {
|
|
|
130
132
|
*
|
|
131
133
|
* If the functor is an array:
|
|
132
134
|
* ```coffeescript [specscript]
|
|
133
|
-
* mapper(
|
|
135
|
+
* mapper(item any, index number, functor Array) -> mappedItem Promise|any
|
|
134
136
|
* ```
|
|
135
137
|
*
|
|
136
138
|
* If the functor is a set:
|
|
137
139
|
* ```coffeescript [specscript]
|
|
138
|
-
* mapper(
|
|
140
|
+
* mapper(item any, item any, functor Set) -> mappedItem Promise|any
|
|
139
141
|
* ```
|
|
140
142
|
*
|
|
141
143
|
* If the functor is a map:
|
|
142
144
|
* ```coffeescript [specscript]
|
|
143
|
-
* mapper(
|
|
145
|
+
* mapper(item any, key any, functor Map) -> mappedItem Promise|any
|
|
144
146
|
* ```
|
|
145
147
|
*
|
|
146
148
|
* If the functor is a generator:
|
|
147
149
|
* ```coffeescript [specscript]
|
|
148
|
-
* mapper(
|
|
150
|
+
* mapper(item any) -> mappedItem any
|
|
149
151
|
* ```
|
|
150
152
|
*
|
|
151
153
|
* If the functor is an async generator:
|
|
152
154
|
* ```coffeescript [specscript]
|
|
153
|
-
* mapper(
|
|
155
|
+
* mapper(item any) -> mappedItem Promise|any
|
|
154
156
|
* ```
|
|
155
157
|
*
|
|
156
|
-
* If the functor is an object with a `.map` method, the mapper function signature is defined externally.
|
|
157
|
-
*
|
|
158
158
|
* If the functor is a plain object:
|
|
159
159
|
* ```coffeescript [specscript]
|
|
160
|
-
* mapper(
|
|
160
|
+
* mapper(item any, key string, functor Object) -> mappedItem Promise|any
|
|
161
161
|
* ```
|
|
162
162
|
*
|
|
163
|
-
* `map` works for arrays.
|
|
164
|
-
*
|
|
165
163
|
* ```javascript [playground]
|
|
166
164
|
* const square = number => number ** 2
|
|
167
165
|
*
|
|
168
166
|
* const array = [1, 2, 3, 4, 5]
|
|
167
|
+
* const object = { a: 1, b: 2, c: 3 }
|
|
168
|
+
*
|
|
169
|
+
* const mappedArray = map(array, square)
|
|
170
|
+
* const mappedObject = map(object, square)
|
|
169
171
|
*
|
|
170
|
-
*
|
|
171
|
-
* console.log(
|
|
172
|
+
* console.log(mappedArray)
|
|
173
|
+
* console.log(mappedObject)
|
|
172
174
|
* ```
|
|
173
175
|
*
|
|
174
|
-
*
|
|
176
|
+
* If the functor is an object with a `.map` method, the mapper function signature is defined externally.
|
|
177
|
+
*
|
|
178
|
+
* If the mapper function is asynchronous, it is executed concurrently.
|
|
179
|
+
*
|
|
180
|
+
* If the functor is a generator, the mapper function must be synchronous.
|
|
175
181
|
*
|
|
176
182
|
* ```javascript [playground]
|
|
177
183
|
* const asyncSquare = async number => number ** 2
|
|
@@ -179,84 +185,56 @@ const _map = function (value, f) {
|
|
|
179
185
|
* const array = [1, 2, 3, 4, 5]
|
|
180
186
|
*
|
|
181
187
|
* const promise = map(array, asyncSquare)
|
|
182
|
-
* promise.then(console.log) // [1, 4, 9, 16, 25]
|
|
183
|
-
* ```
|
|
184
|
-
*
|
|
185
|
-
* `map` applies the mapper function to just the values of an object.
|
|
186
188
|
*
|
|
187
|
-
*
|
|
188
|
-
* const square = number => number ** 2
|
|
189
|
-
*
|
|
190
|
-
* const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
191
|
-
*
|
|
192
|
-
* const result = map(obj, square)
|
|
193
|
-
* console.log(result) // { a: 1, b: 4, c: 9, d: 16, e: 25 }
|
|
189
|
+
* promise.then(console.log)
|
|
194
190
|
* ```
|
|
195
191
|
*
|
|
196
|
-
* `map` applies the mapper function to the values of
|
|
192
|
+
* `map` applies the mapper function to just the values of objects and maps.
|
|
197
193
|
*
|
|
198
194
|
* ```javascript [playground]
|
|
199
195
|
* const square = number => number ** 2
|
|
200
196
|
*
|
|
197
|
+
* const object = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
201
198
|
* const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
|
|
202
199
|
*
|
|
203
|
-
* const
|
|
204
|
-
*
|
|
205
|
-
* ```
|
|
206
|
-
*
|
|
207
|
-
* `map` applies the mapper function lazily to each value of a generator, creating a new generator with mapped elements.
|
|
200
|
+
* const mappedObject = map(object, square)
|
|
201
|
+
* const mappedMap = map(m, square)
|
|
208
202
|
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* const abcGeneratorFunc = function* () {
|
|
213
|
-
* yield 'a'; yield 'b'; yield 'c'
|
|
214
|
-
* }
|
|
215
|
-
*
|
|
216
|
-
* const abcGenerator = abcGeneratorFunc()
|
|
217
|
-
* const ABCGenerator = map(abcGeneratorFunc(), capitalize)
|
|
218
|
-
*
|
|
219
|
-
* console.log([...abcGenerator]) // ['a', 'b', 'c']
|
|
220
|
-
*
|
|
221
|
-
* console.log([...ABCGenerator]) // ['A', 'B', 'C']
|
|
203
|
+
* console.log(mappedObject)
|
|
204
|
+
* console.log(mappedMap)
|
|
222
205
|
* ```
|
|
223
206
|
*
|
|
224
|
-
* `map`
|
|
207
|
+
* `map` maps each value of a generator, creating a new generator with mapped elements.
|
|
225
208
|
*
|
|
226
209
|
* ```javascript [playground]
|
|
227
210
|
* const capitalize = string => string.toUpperCase()
|
|
228
211
|
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
212
|
+
* async function* generateAlphabet() {
|
|
213
|
+
* for (let i = 0; i < 26; i++) {
|
|
214
|
+
* yield String.fromCharCode(97 + i)
|
|
215
|
+
* }
|
|
231
216
|
* }
|
|
232
217
|
*
|
|
233
|
-
* const
|
|
234
|
-
* const
|
|
218
|
+
* const alphabet = generateAlphabet()
|
|
219
|
+
* const uppercaseAlphabet = map(generateAlphabet(), capitalize)
|
|
235
220
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* // b
|
|
241
|
-
* // c
|
|
242
|
-
* }
|
|
221
|
+
* console.log('alphabet')
|
|
222
|
+
* for await (const letter of alphabet) {
|
|
223
|
+
* console.log(letter)
|
|
224
|
+
* }
|
|
243
225
|
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* // C
|
|
249
|
-
* }
|
|
250
|
-
* })()
|
|
226
|
+
* console.log('uppercase alphabet')
|
|
227
|
+
* for await (const letter of uppercaseAlphabet) {
|
|
228
|
+
* console.log(letter)
|
|
229
|
+
* }
|
|
251
230
|
* ```
|
|
252
231
|
*
|
|
253
|
-
*
|
|
232
|
+
* If the functor is a promise, it is resolved for its value before further execution for the eager interface only.
|
|
254
233
|
*
|
|
255
234
|
* ```javascript [playground]
|
|
256
235
|
* const asyncSquare = async n => n ** 2
|
|
257
236
|
*
|
|
258
237
|
* map(Promise.resolve([1, 2, 3, 4, 5]), asyncSquare).then(console.log)
|
|
259
|
-
* // [1, 4, 9, 16, 25]
|
|
260
238
|
* ```
|
|
261
239
|
*
|
|
262
240
|
* See also:
|
|
@@ -302,23 +280,23 @@ const _mapEntries = (value, f) => {
|
|
|
302
280
|
*
|
|
303
281
|
* @synopsis
|
|
304
282
|
* ```coffeescript [specscript]
|
|
305
|
-
* type
|
|
283
|
+
* type FunctorOfEntries = Map|Object
|
|
306
284
|
*
|
|
307
285
|
* type EntryMapper = (
|
|
308
|
-
* entry [key
|
|
309
|
-
* )=>(
|
|
286
|
+
* entry [key any, value any],
|
|
287
|
+
* )=>(mappedEntry Promise|[mappedKey any, mappedValue any])
|
|
310
288
|
*
|
|
311
289
|
* map.entries(
|
|
312
|
-
*
|
|
290
|
+
* functorOfEntries Promise|FunctorOfEntries,
|
|
313
291
|
* mapper EntryMapper
|
|
314
|
-
* ) -> Promise|
|
|
292
|
+
* ) -> mappedFunctorWithEntries Promise|FunctorOfEntries
|
|
315
293
|
*
|
|
316
|
-
* map.entries(mapper EntryMapper)(
|
|
317
|
-
* -> Promise|
|
|
294
|
+
* map.entries(mapper EntryMapper)(functorOfEntries FunctorOfEntries)
|
|
295
|
+
* -> mappedFunctorWithEntries Promise|FunctorOfEntries
|
|
318
296
|
* ```
|
|
319
297
|
*
|
|
320
298
|
* @description
|
|
321
|
-
*
|
|
299
|
+
* [map](/docs/map) that applies the mapper function to the entries of a functor as opposed to the values.
|
|
322
300
|
*
|
|
323
301
|
* The following data types are considered to be functors with entries:
|
|
324
302
|
* * `map`
|
|
@@ -327,46 +305,39 @@ const _mapEntries = (value, f) => {
|
|
|
327
305
|
* The signature of the mapper function changes depending on the provided functor:
|
|
328
306
|
*
|
|
329
307
|
* If the functor is a map:
|
|
330
|
-
*
|
|
331
308
|
* ```coffeescript [specscript]
|
|
332
|
-
* mapper(entry [key any, value any]) ->
|
|
333
|
-
*
|
|
334
|
-
* resultValue any,
|
|
335
|
-
* ]
|
|
309
|
+
* mapper(entry [key any, value any]) ->
|
|
310
|
+
* mappedEntry Promise|[mappedKey any, mappedValue any]
|
|
336
311
|
* ```
|
|
337
312
|
*
|
|
338
313
|
* If the functor is an object:
|
|
339
|
-
*
|
|
340
314
|
* ```coffeescript [specscript]
|
|
341
|
-
* mapper(entry [key string, value any]) ->
|
|
342
|
-
*
|
|
343
|
-
* resultValue any,
|
|
344
|
-
* ]
|
|
315
|
+
* mapper(entry [key string, value any]) ->
|
|
316
|
+
* mappedEntry Promise|[mappedKey string, mappedValue any]
|
|
345
317
|
* ```
|
|
346
318
|
*
|
|
347
|
-
* `map.entries` works for objects and maps.
|
|
348
|
-
*
|
|
349
319
|
* ```javascript [playground]
|
|
350
320
|
* const upperCaseKeysAndSquareValues =
|
|
351
321
|
* map.entries(([key, value]) => [key.toUpperCase(), value ** 2])
|
|
352
322
|
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
323
|
+
* const object = { a: 1, b: 2, c: 3 }
|
|
324
|
+
*
|
|
325
|
+
* console.log(upperCaseKeysAndSquareValues(object))
|
|
355
326
|
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
327
|
+
* const m = new Map([['a', 1], ['b', 2], ['c', 3]])
|
|
328
|
+
*
|
|
329
|
+
* console.log(upperCaseKeysAndSquareValues(m))
|
|
358
330
|
* ```
|
|
359
331
|
*
|
|
360
|
-
*
|
|
332
|
+
* If the functor with entries is a promise, it is resolved for its value before further execution for the eager interface only.
|
|
361
333
|
*
|
|
362
334
|
* ```javascript [playground]
|
|
363
335
|
* const asyncSquareEntries = async ([k, v]) => [k, v ** 2]
|
|
364
336
|
*
|
|
365
337
|
* map.entries(
|
|
366
338
|
* Promise.resolve({ a: 1, b: 2, c: 3 }),
|
|
367
|
-
* asyncSquareEntries
|
|
339
|
+
* asyncSquareEntries
|
|
368
340
|
* ).then(console.log)
|
|
369
|
-
* // { a: 1, b: 4, c: 9 }
|
|
370
341
|
* ```
|
|
371
342
|
*
|
|
372
343
|
* See also:
|
|
@@ -407,27 +378,36 @@ map.entries = function mapEntries(arg0, arg1) {
|
|
|
407
378
|
* _mapSeries(f Functor, f SyncOrAsyncMapper) -> result Promise|Functor
|
|
408
379
|
* ```
|
|
409
380
|
*/
|
|
410
|
-
const _mapSeries = function (
|
|
411
|
-
if (isArray(
|
|
412
|
-
return arrayMapSeries(
|
|
381
|
+
const _mapSeries = function (functor, f) {
|
|
382
|
+
if (isArray(functor)) {
|
|
383
|
+
return arrayMapSeries(functor, f)
|
|
413
384
|
}
|
|
414
|
-
if (
|
|
415
|
-
throw new TypeError(`invalid
|
|
385
|
+
if (functor == null) {
|
|
386
|
+
throw new TypeError(`invalid functor ${functor}`)
|
|
416
387
|
}
|
|
417
388
|
|
|
418
|
-
if (typeof
|
|
419
|
-
return stringMapSeries(
|
|
389
|
+
if (typeof functor == 'string' || functor.constructor == String) {
|
|
390
|
+
return stringMapSeries(functor, f)
|
|
391
|
+
}
|
|
392
|
+
if (functor.constructor == Set) {
|
|
393
|
+
return setMapSeries(functor, f)
|
|
394
|
+
}
|
|
395
|
+
if (functor.constructor == Map) {
|
|
396
|
+
return mapMapSeries(functor, f)
|
|
397
|
+
}
|
|
398
|
+
if (typeof functor[symbolIterator] == 'function') {
|
|
399
|
+
return MappingIterator(functor[symbolIterator](), f)
|
|
420
400
|
}
|
|
421
|
-
if (
|
|
422
|
-
return
|
|
401
|
+
if (typeof functor[symbolAsyncIterator] == 'function') {
|
|
402
|
+
return SerialMappingAsyncIterator(functor[symbolAsyncIterator](), f)
|
|
423
403
|
}
|
|
424
|
-
if (
|
|
425
|
-
return
|
|
404
|
+
if (typeof functor.map == 'function') {
|
|
405
|
+
return functor.map(f)
|
|
426
406
|
}
|
|
427
|
-
if (
|
|
428
|
-
return objectMapSeries(
|
|
407
|
+
if (functor.constructor == Object) {
|
|
408
|
+
return objectMapSeries(functor, f)
|
|
429
409
|
}
|
|
430
|
-
throw new TypeError(`invalid
|
|
410
|
+
throw new TypeError(`invalid functor ${functor}`)
|
|
431
411
|
}
|
|
432
412
|
|
|
433
413
|
/**
|
|
@@ -435,21 +415,22 @@ const _mapSeries = function (collection, f) {
|
|
|
435
415
|
*
|
|
436
416
|
* @synopsis
|
|
437
417
|
* ```coffeescript [specscript]
|
|
438
|
-
* type
|
|
418
|
+
* type Functor = Array|Set|Map|Generator|AsyncGenerator|{ map: function }|Object
|
|
439
419
|
*
|
|
440
420
|
* type SyncOrAsyncMapper = (
|
|
441
421
|
* value any,
|
|
442
422
|
* indexOrKey number|string|any,
|
|
443
|
-
*
|
|
423
|
+
* functor Functor,
|
|
444
424
|
* )=>(mappedElement Promise|any)
|
|
445
425
|
*
|
|
446
426
|
* map.series(
|
|
447
|
-
*
|
|
427
|
+
* functor Promise|Functor,
|
|
448
428
|
* mapper SyncOrAsyncMapper
|
|
449
|
-
* ) ->
|
|
429
|
+
* ) -> mappedFunctor Promise|Functor
|
|
450
430
|
*
|
|
451
|
-
* map.series(
|
|
452
|
-
*
|
|
431
|
+
* map.series(
|
|
432
|
+
* mapper SyncOrAsyncMapper
|
|
433
|
+
* )(functor Functor) -> mappedFunctor Promise|Functor
|
|
453
434
|
* ```
|
|
454
435
|
*
|
|
455
436
|
* @description
|
|
@@ -467,13 +448,16 @@ const _mapSeries = function (collection, f) {
|
|
|
467
448
|
* map.series([1, 2, 3, 4, 5], delayedLog)
|
|
468
449
|
* ```
|
|
469
450
|
*
|
|
470
|
-
*
|
|
451
|
+
* If the functor is an object with a `.map` method, the mapper function signature is defined externally. Serial execution is not guaranteed in this case.
|
|
452
|
+
*
|
|
453
|
+
* If the functor is a generator, the mapper function must be synchronous.
|
|
454
|
+
*
|
|
455
|
+
* If the functor is a promise, it is resolved for its value before further execution for the eager interface only.
|
|
471
456
|
*
|
|
472
457
|
* ```javascript [playground]
|
|
473
458
|
* const asyncSquare = async n => n ** 2
|
|
474
459
|
*
|
|
475
460
|
* map.series(Promise.resolve([1, 2, 3, 4, 5]), asyncSquare).then(console.log)
|
|
476
|
-
* // [1, 4, 9, 16, 25]
|
|
477
461
|
* ```
|
|
478
462
|
*
|
|
479
463
|
* See also:
|
|
@@ -538,13 +522,13 @@ const _mapPool = function (f, concurrency, mapper) {
|
|
|
538
522
|
* type MapPoolFunctor = Array|Object|Set|Map
|
|
539
523
|
*
|
|
540
524
|
* type SyncOrAsyncMapper = (
|
|
541
|
-
*
|
|
525
|
+
* item any,
|
|
542
526
|
* indexOrKey number|string|any,
|
|
543
|
-
*
|
|
544
|
-
* )=>(
|
|
527
|
+
* functor Functor
|
|
528
|
+
* )=>(mappedItem Promise|any)
|
|
545
529
|
*
|
|
546
530
|
* map.pool(
|
|
547
|
-
*
|
|
531
|
+
* functor MapPoolFunctor,
|
|
548
532
|
* concurrency number,
|
|
549
533
|
* mapper SyncOrAsyncMapper
|
|
550
534
|
* ) -> result Promise|Array
|
|
@@ -552,7 +536,7 @@ const _mapPool = function (f, concurrency, mapper) {
|
|
|
552
536
|
* map.pool(
|
|
553
537
|
* concurrency number,
|
|
554
538
|
* mapper SyncOrAsyncMapper
|
|
555
|
-
* )(
|
|
539
|
+
* )(functor MapPoolFunctor) -> result Promise|Array
|
|
556
540
|
* ```
|
|
557
541
|
*
|
|
558
542
|
* @description
|
|
@@ -574,7 +558,7 @@ const _mapPool = function (f, concurrency, mapper) {
|
|
|
574
558
|
* ]))(ids)
|
|
575
559
|
* ```
|
|
576
560
|
*
|
|
577
|
-
* Any promises passed in argument position are resolved for their values before further execution.
|
|
561
|
+
* Any promises passed in data argument position are resolved for their values before further execution.
|
|
578
562
|
*
|
|
579
563
|
* ```javascript [playground]
|
|
580
564
|
* const asyncSquare = async n => n ** 2
|
|
@@ -607,24 +591,4 @@ map.pool = function mapPool(arg0, arg1, arg2) {
|
|
|
607
591
|
: _mapPool(arg0, arg1, arg2)
|
|
608
592
|
}
|
|
609
593
|
|
|
610
|
-
/**
|
|
611
|
-
* @name map.rate
|
|
612
|
-
*
|
|
613
|
-
* @synopsis
|
|
614
|
-
* ```coffeescript [specscript]
|
|
615
|
-
* type Functor = Array|Object|Set|Map
|
|
616
|
-
*
|
|
617
|
-
* map.rate(
|
|
618
|
-
* rate number,
|
|
619
|
-
* f (value any)=>Promise|any,
|
|
620
|
-
* )(f Functor) -> result Promise|Array
|
|
621
|
-
*
|
|
622
|
-
* map.rate(
|
|
623
|
-
* f Functor,
|
|
624
|
-
* rate number,
|
|
625
|
-
* f (value any)=>Promise|any,
|
|
626
|
-
* ) -> result Promise|Array
|
|
627
|
-
* ```
|
|
628
|
-
*/
|
|
629
|
-
|
|
630
594
|
module.exports = map
|
package/monad/README.md
CHANGED
package/not.js
CHANGED
|
@@ -59,7 +59,7 @@ const _not = function (args, predicate) {
|
|
|
59
59
|
* not(promise).then(console.log) // true
|
|
60
60
|
* ```
|
|
61
61
|
*
|
|
62
|
-
* Any promises passed in argument position are resolved for their values before further execution.
|
|
62
|
+
* Any promises passed in data argument position are resolved for their values before further execution.
|
|
63
63
|
*
|
|
64
64
|
* ```javascript [playground]
|
|
65
65
|
* const isOdd = number => number % 2 == 1
|
package/omit.js
CHANGED
|
@@ -20,17 +20,21 @@ const _omit = function (source, paths) {
|
|
|
20
20
|
*
|
|
21
21
|
* @synopsis
|
|
22
22
|
* ```coffeescript [specscript]
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* paths Array<string>
|
|
24
|
+
*
|
|
25
|
+
* omit(Promise|Object, paths) -> Object
|
|
26
|
+
* omit(paths)(Object) -> Object
|
|
25
27
|
* ```
|
|
26
28
|
*
|
|
27
29
|
* @description
|
|
28
|
-
*
|
|
30
|
+
* Object constructor. Creates a new object by excluding provided paths on an argument object.
|
|
29
31
|
*
|
|
30
32
|
* ```javascript [playground]
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
33
|
+
* const argumentObject = { _id: '1', name: 'John' }
|
|
34
|
+
*
|
|
35
|
+
* const newObject = omit(argumentObject, ['_id'])
|
|
36
|
+
*
|
|
37
|
+
* console.log(newObject)
|
|
34
38
|
* ```
|
|
35
39
|
*
|
|
36
40
|
* `omit` supports three types of path patterns for nested property access
|
|
@@ -40,33 +44,32 @@ const _omit = function (source, paths) {
|
|
|
40
44
|
* * an array of keys or indices - `['a', 0, 'value']`
|
|
41
45
|
*
|
|
42
46
|
* ```javascript [playground]
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* d: 'goodbye',
|
|
49
|
-
* },
|
|
47
|
+
* const omittedABD = omit(['a.b.d'])({
|
|
48
|
+
* a: {
|
|
49
|
+
* b: {
|
|
50
|
+
* c: 'hello',
|
|
51
|
+
* d: 'goodbye',
|
|
50
52
|
* },
|
|
51
|
-
* }
|
|
52
|
-
* )
|
|
53
|
+
* },
|
|
54
|
+
* })
|
|
55
|
+
*
|
|
56
|
+
* console.log(omittedABD)
|
|
53
57
|
* ```
|
|
54
58
|
*
|
|
55
|
-
*
|
|
59
|
+
* `omit` supports a lazy interface for composability.
|
|
56
60
|
*
|
|
57
61
|
* ```javascript [playground]
|
|
58
62
|
* pipe({ a: 1, b: 2, c: 3 }, [
|
|
59
63
|
* map(number => number ** 2),
|
|
60
64
|
* omit(['a', 'b']),
|
|
61
|
-
* console.log,
|
|
65
|
+
* console.log,
|
|
62
66
|
* ])
|
|
63
67
|
* ```
|
|
64
68
|
*
|
|
65
|
-
*
|
|
69
|
+
* If the argument object is a promise, it is resolved for its value before further execution for the eager interface only.
|
|
66
70
|
*
|
|
67
71
|
* ```javascript [playground]
|
|
68
72
|
* omit(Promise.resolve({ a: 1, b: 2, c: 3 }), ['a', 'b']).then(console.log)
|
|
69
|
-
* // { c: 3 }
|
|
70
73
|
* ```
|
|
71
74
|
*
|
|
72
75
|
* See also:
|
package/or.js
CHANGED
|
@@ -145,7 +145,7 @@ const areAnyPredicatesTruthy = function (args, predicates) {
|
|
|
145
145
|
* console.log(condition) // false
|
|
146
146
|
* ```
|
|
147
147
|
*
|
|
148
|
-
* Any promises passed in argument position are resolved for their values before further execution.
|
|
148
|
+
* Any promises passed in data argument position are resolved for their values before further execution.
|
|
149
149
|
*
|
|
150
150
|
* ```javascript [playground]
|
|
151
151
|
* or(Promise.resolve('aaa'), [
|