rubico 2.6.5 → 2.6.6
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/dist/Transducer.es.js +2 -2
- package/dist/Transducer.es.min.js +2 -2
- package/dist/Transducer.js +2 -2
- package/dist/Transducer.min.js +2 -2
- package/dist/Transducer.mjs +2 -2
- package/dist/__.es.js +2 -2
- package/dist/__.es.min.js +2 -2
- package/dist/__.js +2 -2
- package/dist/__.min.js +2 -2
- package/dist/__.mjs +2 -2
- package/dist/all.es.js +2 -22
- package/dist/all.es.min.js +2 -2
- package/dist/all.js +2 -22
- package/dist/all.min.js +2 -2
- package/dist/all.mjs +2 -22
- package/dist/always.es.js +2 -2
- package/dist/always.es.min.js +2 -2
- package/dist/always.js +2 -2
- package/dist/always.min.js +2 -2
- package/dist/always.mjs +2 -2
- package/dist/and.es.js +2 -2
- package/dist/and.es.min.js +2 -2
- package/dist/and.js +2 -2
- package/dist/and.min.js +2 -2
- package/dist/and.mjs +2 -2
- package/dist/assign.es.js +2 -2
- package/dist/assign.es.min.js +2 -2
- package/dist/assign.js +2 -2
- package/dist/assign.min.js +2 -2
- package/dist/assign.mjs +2 -2
- package/dist/compose.es.js +2 -2
- package/dist/compose.es.min.js +2 -2
- package/dist/compose.js +2 -2
- package/dist/compose.min.js +2 -2
- package/dist/compose.mjs +2 -2
- package/dist/curry.es.js +2 -2
- package/dist/curry.es.min.js +2 -2
- package/dist/curry.js +2 -2
- package/dist/curry.min.js +2 -2
- package/dist/curry.mjs +2 -2
- package/dist/eq.es.js +2 -2
- package/dist/eq.es.min.js +2 -2
- package/dist/eq.js +2 -2
- package/dist/eq.min.js +2 -2
- package/dist/eq.mjs +2 -2
- package/dist/every.es.js +2 -2
- package/dist/every.es.min.js +2 -2
- package/dist/every.js +2 -2
- package/dist/every.min.js +2 -2
- package/dist/every.mjs +2 -2
- package/dist/filter.es.js +5 -3
- package/dist/filter.es.min.js +3 -3
- package/dist/filter.js +5 -3
- package/dist/filter.min.js +3 -3
- package/dist/filter.mjs +5 -3
- package/dist/flatMap.es.js +2 -2
- package/dist/flatMap.es.min.js +2 -2
- package/dist/flatMap.js +2 -2
- package/dist/flatMap.min.js +2 -2
- package/dist/flatMap.mjs +2 -2
- package/dist/forEach.es.js +2 -2
- package/dist/forEach.es.min.js +2 -2
- package/dist/forEach.js +2 -2
- package/dist/forEach.min.js +2 -2
- package/dist/forEach.mjs +2 -2
- package/dist/get.es.js +2 -2
- package/dist/get.es.min.js +2 -2
- package/dist/get.js +2 -2
- package/dist/get.min.js +2 -2
- package/dist/get.mjs +2 -2
- package/dist/gt.es.js +2 -2
- package/dist/gt.es.min.js +2 -2
- package/dist/gt.js +2 -2
- package/dist/gt.min.js +2 -2
- package/dist/gt.mjs +2 -2
- package/dist/gte.es.js +2 -2
- package/dist/gte.es.min.js +2 -2
- package/dist/gte.js +2 -2
- package/dist/gte.min.js +2 -2
- package/dist/gte.mjs +2 -2
- package/dist/lt.es.js +2 -2
- package/dist/lt.es.min.js +2 -2
- package/dist/lt.js +2 -2
- package/dist/lt.min.js +2 -2
- package/dist/lt.mjs +2 -2
- package/dist/lte.es.js +2 -2
- package/dist/lte.es.min.js +2 -2
- package/dist/lte.js +2 -2
- package/dist/lte.min.js +2 -2
- package/dist/lte.mjs +2 -2
- package/dist/map.es.js +31 -31
- package/dist/map.es.min.js +3 -3
- package/dist/map.js +31 -31
- package/dist/map.min.js +3 -3
- package/dist/map.mjs +31 -31
- package/dist/not.es.js +2 -2
- package/dist/not.es.min.js +2 -2
- package/dist/not.js +2 -2
- package/dist/not.min.js +2 -2
- package/dist/not.mjs +2 -2
- package/dist/omit.es.js +2 -2
- package/dist/omit.es.min.js +2 -2
- package/dist/omit.js +2 -2
- package/dist/omit.min.js +2 -2
- package/dist/omit.mjs +2 -2
- package/dist/or.es.js +2 -2
- package/dist/or.es.min.js +2 -2
- package/dist/or.js +2 -2
- package/dist/or.min.js +2 -2
- package/dist/or.mjs +2 -2
- package/dist/pick.es.js +2 -2
- package/dist/pick.es.min.js +2 -2
- package/dist/pick.js +2 -2
- package/dist/pick.min.js +2 -2
- package/dist/pick.mjs +2 -2
- package/dist/pipe.es.js +2 -2
- package/dist/pipe.es.min.js +2 -2
- package/dist/pipe.js +2 -2
- package/dist/pipe.min.js +2 -2
- package/dist/pipe.mjs +2 -2
- package/dist/reduce.es.js +2 -2
- package/dist/reduce.es.min.js +2 -2
- package/dist/reduce.js +2 -2
- package/dist/reduce.min.js +2 -2
- package/dist/reduce.mjs +2 -2
- package/dist/rubico.es.js +34 -52
- package/dist/rubico.es.min.js +3 -3
- package/dist/rubico.global.js +34 -52
- package/dist/rubico.global.min.js +3 -3
- package/dist/rubico.js +34 -52
- package/dist/rubico.min.js +3 -3
- package/dist/rubico.mjs +34 -52
- package/dist/set.es.js +2 -2
- package/dist/set.es.min.js +2 -2
- package/dist/set.js +2 -2
- package/dist/set.min.js +2 -2
- package/dist/set.mjs +2 -2
- package/dist/some.es.js +2 -2
- package/dist/some.es.min.js +2 -2
- package/dist/some.js +2 -2
- package/dist/some.min.js +2 -2
- package/dist/some.mjs +2 -2
- package/dist/switchCase.es.js +2 -2
- package/dist/switchCase.es.min.js +2 -2
- package/dist/switchCase.js +2 -2
- package/dist/switchCase.min.js +2 -2
- package/dist/switchCase.mjs +2 -2
- package/dist/tap.es.js +2 -2
- package/dist/tap.es.min.js +2 -2
- package/dist/tap.js +2 -2
- package/dist/tap.min.js +2 -2
- package/dist/tap.mjs +2 -2
- package/dist/thunkify.es.js +2 -2
- package/dist/thunkify.es.min.js +2 -2
- package/dist/thunkify.js +2 -2
- package/dist/thunkify.min.js +2 -2
- package/dist/thunkify.mjs +2 -2
- package/dist/transform.es.js +2 -2
- package/dist/transform.es.min.js +2 -2
- package/dist/transform.js +2 -2
- package/dist/transform.min.js +2 -2
- package/dist/transform.mjs +2 -2
- package/dist/tryCatch.es.js +2 -2
- package/dist/tryCatch.es.min.js +2 -2
- package/dist/tryCatch.js +2 -2
- package/dist/tryCatch.min.js +2 -2
- package/dist/tryCatch.mjs +2 -2
- package/dist/x/append.es.js +2 -2
- package/dist/x/append.es.min.js +2 -2
- package/dist/x/append.js +2 -2
- package/dist/x/append.min.js +2 -2
- package/dist/x/append.mjs +2 -2
- package/dist/x/callProp.es.js +2 -2
- package/dist/x/callProp.es.min.js +2 -2
- package/dist/x/callProp.js +2 -2
- package/dist/x/callProp.min.js +2 -2
- package/dist/x/callProp.mjs +2 -2
- package/dist/x/defaultsDeep.es.js +2 -2
- package/dist/x/defaultsDeep.es.min.js +2 -2
- package/dist/x/defaultsDeep.js +2 -2
- package/dist/x/defaultsDeep.min.js +2 -2
- package/dist/x/defaultsDeep.mjs +2 -2
- package/dist/x/differenceWith.es.js +2 -2
- package/dist/x/differenceWith.es.min.js +2 -2
- package/dist/x/differenceWith.js +2 -2
- package/dist/x/differenceWith.min.js +2 -2
- package/dist/x/differenceWith.mjs +2 -2
- package/dist/x/filterOut.es.js +5 -3
- package/dist/x/filterOut.es.min.js +3 -3
- package/dist/x/filterOut.js +5 -3
- package/dist/x/filterOut.min.js +3 -3
- package/dist/x/filterOut.mjs +5 -3
- package/dist/x/find.es.js +2 -2
- package/dist/x/find.es.min.js +2 -2
- package/dist/x/find.js +2 -2
- package/dist/x/find.min.js +2 -2
- package/dist/x/find.mjs +2 -2
- package/dist/x/findIndex.es.js +2 -2
- package/dist/x/findIndex.es.min.js +2 -2
- package/dist/x/findIndex.js +2 -2
- package/dist/x/findIndex.min.js +2 -2
- package/dist/x/findIndex.mjs +2 -2
- package/dist/x/first.es.js +2 -2
- package/dist/x/first.es.min.js +2 -2
- package/dist/x/first.js +2 -2
- package/dist/x/first.min.js +2 -2
- package/dist/x/first.mjs +2 -2
- package/dist/x/flatten.es.js +2 -2
- package/dist/x/flatten.es.min.js +2 -2
- package/dist/x/flatten.js +2 -2
- package/dist/x/flatten.min.js +2 -2
- package/dist/x/flatten.mjs +2 -2
- package/dist/x/groupBy.es.js +2 -2
- package/dist/x/groupBy.es.min.js +2 -2
- package/dist/x/groupBy.js +2 -2
- package/dist/x/groupBy.min.js +2 -2
- package/dist/x/groupBy.mjs +2 -2
- package/dist/x/has.es.js +2 -2
- package/dist/x/has.es.min.js +2 -2
- package/dist/x/has.js +2 -2
- package/dist/x/has.min.js +2 -2
- package/dist/x/has.mjs +2 -2
- package/dist/x/identity.es.js +2 -2
- package/dist/x/identity.es.min.js +2 -2
- package/dist/x/identity.js +2 -2
- package/dist/x/identity.min.js +2 -2
- package/dist/x/identity.mjs +2 -2
- package/dist/x/includes.es.js +2 -2
- package/dist/x/includes.es.min.js +2 -2
- package/dist/x/includes.js +2 -2
- package/dist/x/includes.min.js +2 -2
- package/dist/x/includes.mjs +2 -2
- package/dist/x/isDeepEqual.es.js +2 -2
- package/dist/x/isDeepEqual.es.min.js +2 -2
- package/dist/x/isDeepEqual.js +2 -2
- package/dist/x/isDeepEqual.min.js +2 -2
- package/dist/x/isDeepEqual.mjs +2 -2
- package/dist/x/isEmpty.es.js +2 -2
- package/dist/x/isEmpty.es.min.js +2 -2
- package/dist/x/isEmpty.js +2 -2
- package/dist/x/isEmpty.min.js +2 -2
- package/dist/x/isEmpty.mjs +2 -2
- package/dist/x/isEqual.es.js +2 -2
- package/dist/x/isEqual.es.min.js +2 -2
- package/dist/x/isEqual.js +2 -2
- package/dist/x/isEqual.min.js +2 -2
- package/dist/x/isEqual.mjs +2 -2
- package/dist/x/isFunction.es.js +2 -2
- package/dist/x/isFunction.es.min.js +2 -2
- package/dist/x/isFunction.js +2 -2
- package/dist/x/isFunction.min.js +2 -2
- package/dist/x/isFunction.mjs +2 -2
- package/dist/x/isIn.es.js +2 -2
- package/dist/x/isIn.es.min.js +2 -2
- package/dist/x/isIn.js +2 -2
- package/dist/x/isIn.min.js +2 -2
- package/dist/x/isIn.mjs +2 -2
- package/dist/x/isObject.es.js +2 -2
- package/dist/x/isObject.es.min.js +2 -2
- package/dist/x/isObject.js +2 -2
- package/dist/x/isObject.min.js +2 -2
- package/dist/x/isObject.mjs +2 -2
- package/dist/x/isString.es.js +2 -2
- package/dist/x/isString.es.min.js +2 -2
- package/dist/x/isString.js +2 -2
- package/dist/x/isString.min.js +2 -2
- package/dist/x/isString.mjs +2 -2
- package/dist/x/keys.es.js +2 -2
- package/dist/x/keys.es.min.js +2 -2
- package/dist/x/keys.js +2 -2
- package/dist/x/keys.min.js +2 -2
- package/dist/x/keys.mjs +2 -2
- package/dist/x/last.es.js +2 -2
- package/dist/x/last.es.min.js +2 -2
- package/dist/x/last.js +2 -2
- package/dist/x/last.min.js +2 -2
- package/dist/x/last.mjs +2 -2
- package/dist/x/maxBy.es.js +2 -2
- package/dist/x/maxBy.es.min.js +2 -2
- package/dist/x/maxBy.js +2 -2
- package/dist/x/maxBy.min.js +2 -2
- package/dist/x/maxBy.mjs +2 -2
- package/dist/x/noop.es.js +2 -2
- package/dist/x/noop.es.min.js +2 -2
- package/dist/x/noop.js +2 -2
- package/dist/x/noop.min.js +2 -2
- package/dist/x/noop.mjs +2 -2
- package/dist/x/pluck.es.js +31 -31
- package/dist/x/pluck.es.min.js +3 -3
- package/dist/x/pluck.js +31 -31
- package/dist/x/pluck.min.js +3 -3
- package/dist/x/pluck.mjs +31 -31
- package/dist/x/prepend.es.js +2 -2
- package/dist/x/prepend.es.min.js +2 -2
- package/dist/x/prepend.js +2 -2
- package/dist/x/prepend.min.js +2 -2
- package/dist/x/prepend.mjs +2 -2
- package/dist/x/size.es.js +2 -2
- package/dist/x/size.es.min.js +2 -2
- package/dist/x/size.js +2 -2
- package/dist/x/size.min.js +2 -2
- package/dist/x/size.mjs +2 -2
- package/dist/x/trace.es.js +2 -2
- package/dist/x/trace.es.min.js +2 -2
- package/dist/x/trace.js +2 -2
- package/dist/x/trace.min.js +2 -2
- package/dist/x/trace.mjs +2 -2
- package/dist/x/unionWith.es.js +2 -2
- package/dist/x/unionWith.es.min.js +2 -2
- package/dist/x/unionWith.js +2 -2
- package/dist/x/unionWith.min.js +2 -2
- package/dist/x/unionWith.mjs +2 -2
- package/dist/x/uniq.es.js +2 -2
- package/dist/x/uniq.es.min.js +2 -2
- package/dist/x/uniq.js +2 -2
- package/dist/x/uniq.min.js +2 -2
- package/dist/x/uniq.mjs +2 -2
- package/dist/x/unless.es.js +2 -2
- package/dist/x/unless.es.min.js +2 -2
- package/dist/x/unless.js +2 -2
- package/dist/x/unless.min.js +2 -2
- package/dist/x/unless.mjs +2 -2
- package/dist/x/values.es.js +2 -2
- package/dist/x/values.es.min.js +2 -2
- package/dist/x/values.js +2 -2
- package/dist/x/values.min.js +2 -2
- package/dist/x/values.mjs +2 -2
- package/dist/x/when.es.js +2 -2
- package/dist/x/when.es.min.js +2 -2
- package/dist/x/when.js +2 -2
- package/dist/x/when.min.js +2 -2
- package/dist/x/when.mjs +2 -2
- package/es.js +34 -52
- package/filter.js +41 -45
- package/flatMap.js +24 -27
- package/index.js +34 -52
- package/map.js +67 -89
- package/package.json +1 -3
- package/reduce.js +44 -82
- package/transform.js +24 -32
package/filter.js
CHANGED
|
@@ -3,6 +3,7 @@ const curry2 = require('./_internal/curry2')
|
|
|
3
3
|
const FilteringIterator = require('./_internal/FilteringIterator')
|
|
4
4
|
const FilteringAsyncIterator = require('./_internal/FilteringAsyncIterator')
|
|
5
5
|
const isArray = require('./_internal/isArray')
|
|
6
|
+
const isPromise = require('./_internal/isPromise')
|
|
6
7
|
const arrayFilter = require('./_internal/arrayFilter')
|
|
7
8
|
const stringFilter = require('./_internal/stringFilter')
|
|
8
9
|
const setFilter = require('./_internal/setFilter')
|
|
@@ -89,7 +90,7 @@ const _filter = function (value, predicate) {
|
|
|
89
90
|
*
|
|
90
91
|
* @synopsis
|
|
91
92
|
* ```coffeescript [specscript]
|
|
92
|
-
* type Filterable = Array|Object|Set|
|
|
93
|
+
* type Filterable = Array|Object|Set|Generator|AsyncGenerator
|
|
93
94
|
*
|
|
94
95
|
* type Predicate = (
|
|
95
96
|
* value any,
|
|
@@ -97,66 +98,74 @@ const _filter = function (value, predicate) {
|
|
|
97
98
|
* collection Filterable,
|
|
98
99
|
* )=>boolean
|
|
99
100
|
*
|
|
100
|
-
* filter(
|
|
101
|
-
* filter(predicate Predicate)(
|
|
101
|
+
* filter(f Map|Filterable, predicate Predicate) -> result Promise|Map|Filterable
|
|
102
|
+
* filter(predicate Predicate)(f Map|Filterable) -> result Promise|Map|Filterable
|
|
102
103
|
* ```
|
|
103
104
|
*
|
|
104
105
|
* @description
|
|
105
|
-
* Filter out items from a
|
|
106
|
+
* Filter out items from a filterable. Returns a filterable of the same type.
|
|
106
107
|
*
|
|
107
|
-
*
|
|
108
|
-
* * `
|
|
109
|
-
* * `
|
|
110
|
-
* * `
|
|
111
|
-
* * `
|
|
112
|
-
* * `
|
|
108
|
+
* The following data types are considered filterable:
|
|
109
|
+
* * `array`
|
|
110
|
+
* * `object`
|
|
111
|
+
* * `set`
|
|
112
|
+
* * `generator`
|
|
113
|
+
* * `async generator`
|
|
113
114
|
*
|
|
114
|
-
*
|
|
115
|
+
* The filtering operation is defined by a given predicate function. The predicate function dictates whether a given item from the filterable should be included in the returned filterable.
|
|
116
|
+
*
|
|
117
|
+
* ```javascript
|
|
118
|
+
* const predicate = function (item) {
|
|
119
|
+
* // condition is a boolean value involving item
|
|
120
|
+
* return condition
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* `filter` applies a provided predicate function to each item of a filterable, returning a filterable of the same type containing only the items with truthy conditions by the predicate. The order of the items is preserved.
|
|
115
125
|
*
|
|
116
126
|
* ```javascript [playground]
|
|
117
127
|
* const isOdd = number => number % 2 == 1
|
|
118
128
|
*
|
|
119
129
|
* const array = [1, 2, 3, 4, 5]
|
|
120
130
|
*
|
|
121
|
-
*
|
|
122
|
-
* console.log(
|
|
131
|
+
* const result = filter(array, isOdd)
|
|
132
|
+
* console.log(result) // [1, 3, 5]
|
|
123
133
|
* ```
|
|
124
134
|
*
|
|
125
|
-
*
|
|
135
|
+
* The predicate may be asynchronous, in which case the returned promise is concurrently resolved for its boolean condition before deciding whether to include the corresponding item in the result.
|
|
126
136
|
*
|
|
127
137
|
* ```javascript [playground]
|
|
128
|
-
* const
|
|
138
|
+
* const asyncIsOdd = async number => number % 2 == 1
|
|
129
139
|
*
|
|
130
|
-
* const
|
|
140
|
+
* const array = [1, 2, 3, 4, 5]
|
|
131
141
|
*
|
|
132
|
-
*
|
|
133
|
-
* console.log
|
|
142
|
+
* const promise = filter(array, asyncIsOdd)
|
|
143
|
+
* promise.then(console.log) // [1, 3, 5]
|
|
134
144
|
* ```
|
|
135
145
|
*
|
|
136
|
-
* For
|
|
146
|
+
* For objects, `filter` applies the predicate function to just the values.
|
|
137
147
|
*
|
|
138
148
|
* ```javascript [playground]
|
|
139
149
|
* const isOdd = number => number % 2 == 1
|
|
140
150
|
*
|
|
141
|
-
* const
|
|
151
|
+
* const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 }
|
|
142
152
|
*
|
|
143
|
-
*
|
|
144
|
-
* console.log(
|
|
153
|
+
* const result = filter(obj, isOdd)
|
|
154
|
+
* console.log(result) // { a: 1, c: 3, e: 5 }
|
|
145
155
|
* ```
|
|
146
156
|
*
|
|
147
|
-
* For maps
|
|
157
|
+
* For maps, `filter` applies the predicate to the values of the entries. The order of the entries is preserved.
|
|
148
158
|
*
|
|
149
159
|
* ```javascript [playground]
|
|
150
160
|
* const isOdd = number => number % 2 == 1
|
|
151
161
|
*
|
|
152
|
-
* const
|
|
153
|
-
* const m = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
|
|
162
|
+
* const myMap = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]])
|
|
154
163
|
*
|
|
155
|
-
*
|
|
156
|
-
* console.log(
|
|
164
|
+
* const result = filter(myMap, isOdd)
|
|
165
|
+
* console.log(result) // Map(3) { 'a' => 1, 'c' => 3, 'e' => 5 }
|
|
157
166
|
* ```
|
|
158
167
|
*
|
|
159
|
-
* For
|
|
168
|
+
* For generators, `filter` returns a lazily filtered generator. All values that are normally yielded by the generator that test falsy by the predicate are skipped.
|
|
160
169
|
*
|
|
161
170
|
* ```javascript [playground]
|
|
162
171
|
* const isOdd = number => number % 2 == 1
|
|
@@ -167,7 +176,6 @@ const _filter = function (value, predicate) {
|
|
|
167
176
|
*
|
|
168
177
|
* const numbersGenerator = numbersGeneratorFunction()
|
|
169
178
|
* const oddNumbersGenerator = filter(numbersGeneratorFunction(), isOdd)
|
|
170
|
-
* const oddNumbersGenerator2 = filter(isOdd)(numbersGeneratorFunction())
|
|
171
179
|
*
|
|
172
180
|
* for (const number of numbersGenerator) {
|
|
173
181
|
* console.log(number) // 1
|
|
@@ -182,15 +190,9 @@ const _filter = function (value, predicate) {
|
|
|
182
190
|
* // 3
|
|
183
191
|
* // 5
|
|
184
192
|
* }
|
|
185
|
-
*
|
|
186
|
-
* for (const number of oddNumbersGenerator2) {
|
|
187
|
-
* console.log(number) // 1
|
|
188
|
-
* // 3
|
|
189
|
-
* // 5
|
|
190
|
-
* }
|
|
191
193
|
* ```
|
|
192
194
|
*
|
|
193
|
-
*
|
|
195
|
+
* For async generators, `filter` returns a lazily filtered async generator. All values that are normally yielded by the async generator that test falsy by the predicate are skipped.
|
|
194
196
|
*
|
|
195
197
|
* ```javascript [playground]
|
|
196
198
|
* const asyncIsOdd = async number => number % 2 == 1
|
|
@@ -203,8 +205,6 @@ const _filter = function (value, predicate) {
|
|
|
203
205
|
*
|
|
204
206
|
* const asyncOddNumbersGenerator = filter(asyncNumbersGeneratorFunction(), asyncIsOdd)
|
|
205
207
|
*
|
|
206
|
-
* const asyncOddNumbersGenerator2 = filter(asyncIsOdd)(asyncNumbersGeneratorFunction())
|
|
207
|
-
*
|
|
208
208
|
* for await (const number of asyncNumbersGenerator) {
|
|
209
209
|
* console.log(number) // 1
|
|
210
210
|
* // 2
|
|
@@ -218,12 +218,6 @@ const _filter = function (value, predicate) {
|
|
|
218
218
|
* // 3
|
|
219
219
|
* // 5
|
|
220
220
|
* }
|
|
221
|
-
*
|
|
222
|
-
* for await (const number of asyncOddNumbersGenerator2) {
|
|
223
|
-
* console.log(number) // 1
|
|
224
|
-
* // 3
|
|
225
|
-
* // 5
|
|
226
|
-
* }
|
|
227
221
|
* ```
|
|
228
222
|
*
|
|
229
223
|
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
@@ -243,7 +237,9 @@ const filter = function (arg0, arg1) {
|
|
|
243
237
|
if (typeof arg0 == 'function') {
|
|
244
238
|
return curry2(_filter, __, arg0)
|
|
245
239
|
}
|
|
246
|
-
return
|
|
240
|
+
return isPromise(arg0)
|
|
241
|
+
? arg0.then(curry2(_filter, __, arg1))
|
|
242
|
+
: _filter(arg0, arg1)
|
|
247
243
|
}
|
|
248
244
|
|
|
249
245
|
module.exports = filter
|
package/flatMap.js
CHANGED
|
@@ -15,13 +15,13 @@ const __ = require('./_internal/placeholder')
|
|
|
15
15
|
*
|
|
16
16
|
* @synopsis
|
|
17
17
|
* ```coffeescript [specscript]
|
|
18
|
-
* type
|
|
18
|
+
* type Monad = Array|String|Set|Iterator|AsyncIterator
|
|
19
19
|
* type Iterable = Iterable|AsyncIterable|Object<value any>
|
|
20
20
|
*
|
|
21
21
|
* _flatMap(
|
|
22
|
-
*
|
|
22
|
+
* m Monad,
|
|
23
23
|
* flatMapper (item any)=>Promise|Iterable,
|
|
24
|
-
* ) -> result Promise|
|
|
24
|
+
* ) -> result Promise|Monad
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
const _flatMap = function (value, flatMapper) {
|
|
@@ -64,28 +64,35 @@ const _flatMap = function (value, flatMapper) {
|
|
|
64
64
|
*
|
|
65
65
|
* @synopsis
|
|
66
66
|
* ```coffeescript [specscript]
|
|
67
|
-
* type
|
|
68
|
-
*
|
|
69
|
-
* type Iterable = Iterable|AsyncIterable|Object<value any>
|
|
67
|
+
* type Monad = Array|String|Set|Iterator|AsyncIterator
|
|
68
|
+
* type Flattenable = Iterable|AsyncIterable|Object<value any>
|
|
70
69
|
*
|
|
71
70
|
* type FlatMapper = (
|
|
72
71
|
* item any,
|
|
73
72
|
* indexOrKey string,
|
|
74
|
-
*
|
|
75
|
-
* )=>Promise|
|
|
73
|
+
* m Monad
|
|
74
|
+
* )=>Promise|Flattenable|any
|
|
76
75
|
*
|
|
77
|
-
* flatMap(
|
|
78
|
-
* flatMap(flatMapper FlatMapper)(
|
|
76
|
+
* flatMap(m Monad, flatMapper FlatMapper) -> result Promise|Monad
|
|
77
|
+
* flatMap(flatMapper FlatMapper)(m Monad) -> result Promise|Monad
|
|
79
78
|
* ```
|
|
80
79
|
*
|
|
81
80
|
* @description
|
|
82
|
-
* Applies a flatMapper function concurrently to each item of a
|
|
81
|
+
* Applies a flatMapper function concurrently to each item of a monad, returning a monad of the same type. A flatMapping operation iterates through each item of a monad and applies the flatMapper function to each item, flattening the result of the execution into the returned monad. The result of an individual execution can be any iterable, async iterable, or object with enumerable values. The flatMapper function may be asynchronous.
|
|
82
|
+
*
|
|
83
|
+
* The following data types are considered monads:
|
|
84
|
+
* * `array`
|
|
85
|
+
* * `string`
|
|
86
|
+
* * `set`
|
|
87
|
+
* * `iterator`
|
|
88
|
+
* * `async iterator`
|
|
83
89
|
*
|
|
84
|
-
*
|
|
85
|
-
* * `
|
|
86
|
-
* * `
|
|
90
|
+
* The following data types are considered flattenable:
|
|
91
|
+
* * `iterable` - the execution result is iterated and each item is added to the result collection
|
|
92
|
+
* * `async iterable` - the execution result is asynchronously iterated and each item is added to the result collection
|
|
93
|
+
* * `object` - the execution result values are added to the result collection
|
|
87
94
|
*
|
|
88
|
-
*
|
|
95
|
+
* `flatMap` can flatten various data types.
|
|
89
96
|
*
|
|
90
97
|
* ```javascript [playground]
|
|
91
98
|
* const identity = value => value
|
|
@@ -101,7 +108,7 @@ const _flatMap = function (value, flatMapper) {
|
|
|
101
108
|
* // [1, 1, 2, 3, 3, 5, 5, 8, 7, 7]
|
|
102
109
|
* ```
|
|
103
110
|
*
|
|
104
|
-
*
|
|
111
|
+
* `flatMap` muxes asynchronous values. Muxing, or asynchronously "mixing", is the process of combining multiple asynchronous sources into one source, with order determined by the asynchronous resolution of the individual items.
|
|
105
112
|
*
|
|
106
113
|
* ```javascript [playground]
|
|
107
114
|
* const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
@@ -137,7 +144,7 @@ const _flatMap = function (value, flatMapper) {
|
|
|
137
144
|
* ) // [1, 1, 2, 2, 3, 3, 4, 4, 5, 5]
|
|
138
145
|
* ```
|
|
139
146
|
*
|
|
140
|
-
*
|
|
147
|
+
* `flatMap` acts on each character of a string.
|
|
141
148
|
*
|
|
142
149
|
* ```javascript [playground]
|
|
143
150
|
* const duplicate = value => [value, value]
|
|
@@ -147,16 +154,6 @@ const _flatMap = function (value, flatMapper) {
|
|
|
147
154
|
* ) // 1122334455
|
|
148
155
|
* ```
|
|
149
156
|
*
|
|
150
|
-
* For sets (type `Set`), `flatMap` applies the flatMapper function to each item, adding (`.add`) the items of each execution into a new set
|
|
151
|
-
*
|
|
152
|
-
* ```javascript [playground]
|
|
153
|
-
* const pairPlus100 = value => [value, value + 100]
|
|
154
|
-
*
|
|
155
|
-
* console.log(
|
|
156
|
-
* flatMap(new Set([1, 2, 3, 4, 5]), pairPlus100)
|
|
157
|
-
* ) // Set(10) { 1, 101, 2, 102, 3, 103, 4, 104, 5, 105 }
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
157
|
* Any promises passed in argument position are resolved for their values before further execution. This only applies to the eager version of the API.
|
|
161
158
|
*
|
|
162
159
|
* ```javascript [playground]
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* rubico v2.6.
|
|
2
|
+
* rubico v2.6.6
|
|
3
3
|
* https://github.com/a-synchronous/rubico
|
|
4
|
-
* (c) 2019-
|
|
4
|
+
* (c) 2019-2025 Richard Tong
|
|
5
5
|
* rubico may be freely distributed under the MIT license.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -429,26 +429,6 @@ const all = function (...args) {
|
|
|
429
429
|
return isArray(resolversOrValues)
|
|
430
430
|
? functionArrayAll(resolversOrValues, argValues)
|
|
431
431
|
: functionObjectAll(resolversOrValues, argValues)
|
|
432
|
-
|
|
433
|
-
/*
|
|
434
|
-
////////////////////////////////////////////////////////////////
|
|
435
|
-
const funcs = args.pop()
|
|
436
|
-
if (args.length == 0) {
|
|
437
|
-
return isArray(funcs)
|
|
438
|
-
? curryArgs2(functionArrayAll, funcs, __)
|
|
439
|
-
: curryArgs2(functionObjectAll, funcs, __)
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
if (areAnyValuesPromises(args)) {
|
|
443
|
-
return isArray(funcs)
|
|
444
|
-
? promiseAll(args).then(curry2(functionArrayAll, funcs, __))
|
|
445
|
-
: promiseAll(args).then(curry2(functionObjectAll, funcs, __))
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
return isArray(funcs)
|
|
449
|
-
? functionArrayAll(funcs, args)
|
|
450
|
-
: functionObjectAll(funcs, args)
|
|
451
|
-
*/
|
|
452
432
|
}
|
|
453
433
|
|
|
454
434
|
all.series = function allSeries(...args) {
|
|
@@ -1179,39 +1159,39 @@ const mapMapEntries = function (source, mapper) {
|
|
|
1179
1159
|
: promiseAll(promises).then(always(result))
|
|
1180
1160
|
}
|
|
1181
1161
|
|
|
1182
|
-
const _map = function (value,
|
|
1162
|
+
const _map = function (value, f) {
|
|
1183
1163
|
if (isArray(value)) {
|
|
1184
|
-
return arrayMap(value,
|
|
1164
|
+
return arrayMap(value, f)
|
|
1185
1165
|
}
|
|
1186
1166
|
if (value == null) {
|
|
1187
1167
|
return value
|
|
1188
1168
|
}
|
|
1189
1169
|
|
|
1190
1170
|
if (typeof value.then == 'function') {
|
|
1191
|
-
return value.then(
|
|
1171
|
+
return value.then(f)
|
|
1192
1172
|
}
|
|
1193
1173
|
if (typeof value.map == 'function') {
|
|
1194
|
-
return value.map(
|
|
1174
|
+
return value.map(f)
|
|
1195
1175
|
}
|
|
1196
1176
|
if (typeof value == 'string' || value.constructor == String) {
|
|
1197
|
-
return stringMap(value,
|
|
1177
|
+
return stringMap(value, f)
|
|
1198
1178
|
}
|
|
1199
1179
|
if (value.constructor == Set) {
|
|
1200
|
-
return setMap(value,
|
|
1180
|
+
return setMap(value, f)
|
|
1201
1181
|
}
|
|
1202
1182
|
if (value.constructor == Map) {
|
|
1203
|
-
return mapMap(value,
|
|
1183
|
+
return mapMap(value, f)
|
|
1204
1184
|
}
|
|
1205
1185
|
if (typeof value[symbolIterator] == 'function') {
|
|
1206
|
-
return MappingIterator(value[symbolIterator](),
|
|
1186
|
+
return MappingIterator(value[symbolIterator](), f)
|
|
1207
1187
|
}
|
|
1208
1188
|
if (typeof value[symbolAsyncIterator] == 'function') {
|
|
1209
|
-
return MappingAsyncIterator(value[symbolAsyncIterator](),
|
|
1189
|
+
return MappingAsyncIterator(value[symbolAsyncIterator](), f)
|
|
1210
1190
|
}
|
|
1211
1191
|
if (value.constructor == Object) {
|
|
1212
|
-
return objectMap(value,
|
|
1192
|
+
return objectMap(value, f)
|
|
1213
1193
|
}
|
|
1214
|
-
return
|
|
1194
|
+
return f(value)
|
|
1215
1195
|
}
|
|
1216
1196
|
|
|
1217
1197
|
const map = function (arg0, arg1) {
|
|
@@ -1223,16 +1203,16 @@ const map = function (arg0, arg1) {
|
|
|
1223
1203
|
: _map(arg0, arg1)
|
|
1224
1204
|
}
|
|
1225
1205
|
|
|
1226
|
-
// _mapEntries(value Object|Map,
|
|
1227
|
-
const _mapEntries = (value,
|
|
1206
|
+
// _mapEntries(value Object|Map, f function) -> Object|Map
|
|
1207
|
+
const _mapEntries = (value, f) => {
|
|
1228
1208
|
if (value == null) {
|
|
1229
1209
|
throw new TypeError('value is not an Object or Map')
|
|
1230
1210
|
}
|
|
1231
1211
|
if (value.constructor == Object) {
|
|
1232
|
-
return objectMapEntries(value,
|
|
1212
|
+
return objectMapEntries(value, f)
|
|
1233
1213
|
}
|
|
1234
1214
|
if (value.constructor == Map) {
|
|
1235
|
-
return mapMapEntries(value,
|
|
1215
|
+
return mapMapEntries(value, f)
|
|
1236
1216
|
}
|
|
1237
1217
|
throw new TypeError('value is not an Object or Map')
|
|
1238
1218
|
}
|
|
@@ -1278,26 +1258,26 @@ map.series = function mapSeries(arg0, arg1) {
|
|
|
1278
1258
|
: _mapSeries(arg0, arg1)
|
|
1279
1259
|
}
|
|
1280
1260
|
|
|
1281
|
-
const _mapPool = function (
|
|
1282
|
-
if (isArray(
|
|
1283
|
-
return arrayMapPool(
|
|
1261
|
+
const _mapPool = function (f, concurrency, mapper) {
|
|
1262
|
+
if (isArray(f)) {
|
|
1263
|
+
return arrayMapPool(f, concurrency, mapper)
|
|
1284
1264
|
}
|
|
1285
|
-
if (
|
|
1286
|
-
throw new TypeError(`invalid
|
|
1265
|
+
if (f == null) {
|
|
1266
|
+
throw new TypeError(`invalid functor ${f}`)
|
|
1287
1267
|
}
|
|
1288
|
-
if (typeof
|
|
1289
|
-
return stringMapPool(
|
|
1268
|
+
if (typeof f == 'string' || f.constructor == String) {
|
|
1269
|
+
return stringMapPool(f, concurrency, mapper)
|
|
1290
1270
|
}
|
|
1291
|
-
if (
|
|
1292
|
-
return setMapPool(
|
|
1271
|
+
if (f.constructor == Set) {
|
|
1272
|
+
return setMapPool(f, concurrency, mapper)
|
|
1293
1273
|
}
|
|
1294
|
-
if (
|
|
1295
|
-
return mapMapPool(
|
|
1274
|
+
if (f.constructor == Map) {
|
|
1275
|
+
return mapMapPool(f, concurrency, mapper)
|
|
1296
1276
|
}
|
|
1297
|
-
if (
|
|
1298
|
-
return objectMapPool(
|
|
1277
|
+
if (f.constructor == Object) {
|
|
1278
|
+
return objectMapPool(f, concurrency, mapper)
|
|
1299
1279
|
}
|
|
1300
|
-
throw new TypeError(`invalid
|
|
1280
|
+
throw new TypeError(`invalid functor ${f}`)
|
|
1301
1281
|
}
|
|
1302
1282
|
|
|
1303
1283
|
map.pool = function mapPool(arg0, arg1, arg2) {
|
|
@@ -1502,7 +1482,9 @@ const filter = function (arg0, arg1) {
|
|
|
1502
1482
|
if (typeof arg0 == 'function') {
|
|
1503
1483
|
return curry2(_filter, __, arg0)
|
|
1504
1484
|
}
|
|
1505
|
-
return
|
|
1485
|
+
return isPromise(arg0)
|
|
1486
|
+
? arg0.then(curry2(_filter, __, arg1))
|
|
1487
|
+
: _filter(arg0, arg1)
|
|
1506
1488
|
}
|
|
1507
1489
|
|
|
1508
1490
|
const objectValues = Object.values
|