rambda 6.8.1 → 7.0.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/CHANGELOG.md +93 -0
- package/README.md +4108 -5600
- package/dist/rambda.esm.js +340 -212
- package/dist/rambda.js +345 -212
- package/dist/rambda.mjs +340 -212
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +202 -275
- package/immutable.js +1 -0
- package/index.d.ts +202 -275
- package/package.json +111 -94
- package/src/F.js +1 -1
- package/src/T.js +1 -1
- package/src/_internals/_isInteger.js +1 -1
- package/src/_internals/_objectIs.js +2 -2
- package/src/_internals/baseSlice.js +6 -8
- package/src/_internals/cloneList.js +3 -0
- package/src/_internals/isFalsy.js +5 -5
- package/src/_internals/isObject.js +5 -0
- package/src/_internals/isTruthy.js +5 -5
- package/src/_internals/set.js +35 -0
- package/src/add.js +1 -1
- package/src/adjust.js +5 -6
- package/src/all.js +3 -3
- package/src/allPass.js +4 -4
- package/src/always.js +1 -1
- package/src/and.js +1 -1
- package/src/any.js +3 -3
- package/src/anyPass.js +4 -4
- package/src/append.js +4 -2
- package/src/apply.js +7 -0
- package/src/applySpec.js +33 -59
- package/src/assoc.js +3 -7
- package/src/assocPath.js +22 -25
- package/src/bind.js +9 -0
- package/src/both.js +1 -1
- package/src/chain.js +2 -2
- package/src/clamp.js +6 -6
- package/src/clone.js +10 -10
- package/src/complement.js +1 -1
- package/src/compose.js +6 -6
- package/src/concat.js +2 -2
- package/src/cond.js +3 -3
- package/src/converge.js +11 -11
- package/src/curry.js +2 -2
- package/src/curryN.js +61 -81
- package/src/defaultTo.js +5 -8
- package/src/difference.js +3 -3
- package/src/dissoc.js +4 -4
- package/src/divide.js +1 -1
- package/src/drop.js +1 -1
- package/src/dropLast.js +5 -5
- package/src/dropLastWhile.js +12 -12
- package/src/dropRepeats.js +6 -6
- package/src/dropRepeatsWith.js +7 -7
- package/src/dropWhile.js +9 -9
- package/src/either.js +2 -2
- package/src/endsWith.js +20 -3
- package/src/eqProps.js +5 -10
- package/src/equals.js +119 -38
- package/src/evolve.js +23 -21
- package/src/filter.js +17 -19
- package/src/find.js +4 -4
- package/src/findIndex.js +3 -3
- package/src/findLast.js +4 -4
- package/src/findLastIndex.js +3 -3
- package/src/flatten.js +6 -6
- package/src/flip.js +11 -15
- package/src/forEach.js +10 -12
- package/src/fromPairs.js +2 -2
- package/src/groupBy.js +6 -6
- package/src/groupWith.js +11 -12
- package/src/hasPath.js +5 -5
- package/src/head.js +3 -3
- package/src/identical.js +1 -1
- package/src/identity.js +2 -2
- package/src/ifElse.js +3 -5
- package/src/includes.js +11 -22
- package/src/indexBy.js +11 -11
- package/src/indexOf.js +5 -12
- package/src/init.js +2 -4
- package/src/intersection.js +3 -3
- package/src/intersperse.js +5 -5
- package/src/is.js +2 -2
- package/src/isEmpty.js +5 -5
- package/src/isFunction.js +3 -3
- package/src/isNil.js +1 -1
- package/src/isPromise.js +3 -3
- package/src/join.js +1 -1
- package/src/keys.js +1 -1
- package/src/last.js +4 -4
- package/src/lastIndexOf.js +5 -11
- package/src/length.js +6 -5
- package/src/lens.js +3 -3
- package/src/lensIndex.js +4 -4
- package/src/lensProp.js +4 -4
- package/src/map.js +19 -18
- package/src/match.js +1 -1
- package/src/mathMod.js +2 -2
- package/src/max.js +1 -1
- package/src/maxBy.js +2 -4
- package/src/maybe.js +2 -4
- package/src/mean.js +2 -2
- package/src/median.js +12 -10
- package/src/merge.js +2 -4
- package/src/mergeAll.js +3 -3
- package/src/mergeDeepRight.js +8 -8
- package/src/mergeLeft.js +2 -2
- package/src/min.js +1 -1
- package/src/minBy.js +2 -4
- package/src/modulo.js +1 -1
- package/src/move.js +7 -8
- package/src/multiply.js +1 -1
- package/src/negate.js +1 -1
- package/src/none.js +3 -3
- package/src/not.js +1 -1
- package/src/nth.js +4 -4
- package/src/objOf.js +3 -3
- package/src/of.js +2 -2
- package/src/omit.js +5 -5
- package/src/once.js +6 -6
- package/src/or.js +1 -1
- package/src/over.js +3 -5
- package/src/partial.js +3 -3
- package/src/partition.js +17 -15
- package/src/path.js +6 -6
- package/src/pathEq.js +4 -6
- package/src/pathOr.js +5 -7
- package/src/paths.js +3 -3
- package/src/pick.js +5 -5
- package/src/pickAll.js +6 -6
- package/src/pipe.js +3 -3
- package/src/pluck.js +4 -4
- package/src/prepend.js +3 -3
- package/src/product.js +2 -2
- package/src/prop.js +2 -2
- package/src/propEq.js +3 -5
- package/src/propIs.js +4 -6
- package/src/propOr.js +4 -6
- package/src/props.js +6 -6
- package/src/range.js +4 -4
- package/src/reduce.js +7 -11
- package/src/reject.js +2 -2
- package/src/repeat.js +2 -2
- package/src/replace.js +2 -4
- package/src/reverse.js +3 -4
- package/src/set.js +5 -9
- package/src/slice.js +2 -4
- package/src/sort.js +4 -4
- package/src/sortBy.js +4 -2
- package/src/split.js +1 -1
- package/src/splitAt.js +9 -9
- package/src/splitEvery.js +8 -6
- package/src/splitWhen.js +10 -10
- package/src/startsWith.js +20 -3
- package/src/subtract.js +1 -1
- package/src/sum.js +1 -1
- package/src/symmetricDifference.js +9 -7
- package/src/tail.js +2 -2
- package/src/take.js +2 -4
- package/src/takeLast.js +2 -4
- package/src/takeLastWhile.js +7 -7
- package/src/takeWhile.js +8 -8
- package/src/tap.js +1 -1
- package/src/test.js +5 -3
- package/src/times.js +4 -4
- package/src/toLower.js +1 -1
- package/src/toPairs.js +1 -1
- package/src/toString.js +1 -1
- package/src/toUpper.js +1 -1
- package/src/transpose.js +4 -3
- package/src/trim.js +1 -1
- package/src/tryCatch.js +5 -5
- package/src/type.js +7 -29
- package/src/unapply.js +5 -0
- package/src/union.js +4 -3
- package/src/uniq.js +7 -10
- package/src/uniqWith.js +18 -7
- package/src/unless.js +3 -3
- package/src/update.js +6 -8
- package/src/values.js +2 -2
- package/src/view.js +2 -2
- package/src/when.js +2 -4
- package/src/where.js +5 -5
- package/src/whereEq.js +9 -7
- package/src/without.js +5 -5
- package/src/xor.js +2 -2
- package/src/zip.js +3 -3
- package/src/zipObj.js +4 -6
- package/src/zipWith.js +6 -7
package/src/endsWith.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {equals} from './equals.js'
|
|
2
|
+
import {_isArray} from './_internals/_isArray.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export function endsWith(target, iterable) {
|
|
5
|
+
if (arguments.length === 1) return _iterable => endsWith(target, _iterable)
|
|
6
|
+
|
|
7
|
+
if (typeof iterable === 'string') {
|
|
8
|
+
return iterable.endsWith(target)
|
|
9
|
+
}
|
|
10
|
+
if (!_isArray(target)) return false
|
|
11
|
+
|
|
12
|
+
const diff = iterable.length - target.length
|
|
13
|
+
let correct = true
|
|
14
|
+
const filtered = target.filter((x, index) => {
|
|
15
|
+
if (!correct) return false
|
|
16
|
+
const result = equals(x, iterable[index + diff])
|
|
17
|
+
if (!result) correct = false
|
|
18
|
+
return result
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
return filtered.length === target.length
|
|
5
22
|
}
|
package/src/eqProps.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {curry} from './curry'
|
|
2
|
+
import {equals} from './equals'
|
|
3
|
+
import {prop} from './prop'
|
|
3
4
|
|
|
4
|
-
function eqPropsFn(
|
|
5
|
-
prop,
|
|
6
|
-
){
|
|
7
|
-
if (!obj1 || !obj2){
|
|
8
|
-
throw new Error('wrong object inputs are passed to R.eqProps')
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return equals(obj1[ prop ], obj2[ prop ])
|
|
5
|
+
function eqPropsFn(property, objA, objB) {
|
|
6
|
+
return equals(prop(property, objA), prop(property, objB))
|
|
12
7
|
}
|
|
13
8
|
|
|
14
9
|
export const eqProps = curry(eqPropsFn)
|
package/src/equals.js
CHANGED
|
@@ -1,60 +1,139 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {type} from './type'
|
|
2
|
+
import {_isArray} from './_internals/_isArray'
|
|
2
3
|
|
|
3
|
-
function
|
|
4
|
+
export function _lastIndexOf(valueToFind, list) {
|
|
5
|
+
if (!_isArray(list)) {
|
|
6
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`)
|
|
7
|
+
}
|
|
8
|
+
const typeOfValue = type(valueToFind)
|
|
9
|
+
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue))
|
|
10
|
+
return list.lastIndexOf(valueToFind)
|
|
11
|
+
|
|
12
|
+
const {length} = list
|
|
13
|
+
let index = length
|
|
14
|
+
let foundIndex = -1
|
|
15
|
+
|
|
16
|
+
while (--index > -1 && foundIndex === -1) {
|
|
17
|
+
if (equals(list[index], valueToFind)) {
|
|
18
|
+
foundIndex = index
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return foundIndex
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function _indexOf(valueToFind, list) {
|
|
26
|
+
if (!_isArray(list)) {
|
|
27
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`)
|
|
28
|
+
}
|
|
29
|
+
const typeOfValue = type(valueToFind)
|
|
30
|
+
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue))
|
|
31
|
+
return list.indexOf(valueToFind)
|
|
32
|
+
|
|
33
|
+
let index = -1
|
|
34
|
+
let foundIndex = -1
|
|
35
|
+
const {length} = list
|
|
36
|
+
|
|
37
|
+
while (++index < length && foundIndex === -1) {
|
|
38
|
+
if (equals(list[index], valueToFind)) {
|
|
39
|
+
foundIndex = index
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return foundIndex
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function _arrayFromIterator(iter) {
|
|
47
|
+
const list = []
|
|
48
|
+
let next
|
|
49
|
+
while (!(next = iter.next()).done) {
|
|
50
|
+
list.push(next.value)
|
|
51
|
+
}
|
|
52
|
+
return list
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _equalsSets(a, b) {
|
|
56
|
+
if (a.size !== b.size) {
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
const aList = _arrayFromIterator(a.values())
|
|
60
|
+
const bList = _arrayFromIterator(b.values())
|
|
61
|
+
|
|
62
|
+
const filtered = aList.filter(
|
|
63
|
+
aInstance => _indexOf(aInstance, bList) === -1
|
|
64
|
+
)
|
|
65
|
+
return filtered.length === 0
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function parseError(maybeError) {
|
|
4
69
|
const typeofError = maybeError.__proto__.toString()
|
|
5
|
-
if (![
|
|
70
|
+
if (!['Error', 'TypeError'].includes(typeofError)) return []
|
|
6
71
|
|
|
7
|
-
return [
|
|
72
|
+
return [typeofError, maybeError.message]
|
|
8
73
|
}
|
|
9
74
|
|
|
10
|
-
function parseDate(maybeDate){
|
|
11
|
-
if (!maybeDate.toDateString) return [
|
|
75
|
+
function parseDate(maybeDate) {
|
|
76
|
+
if (!maybeDate.toDateString) return [false]
|
|
12
77
|
|
|
13
|
-
return [
|
|
78
|
+
return [true, maybeDate.getTime()]
|
|
14
79
|
}
|
|
15
80
|
|
|
16
|
-
function parseRegex(maybeRegex){
|
|
17
|
-
if (maybeRegex.constructor !== RegExp) return [
|
|
81
|
+
function parseRegex(maybeRegex) {
|
|
82
|
+
if (maybeRegex.constructor !== RegExp) return [false]
|
|
18
83
|
|
|
19
|
-
return [
|
|
84
|
+
return [true, maybeRegex.toString()]
|
|
20
85
|
}
|
|
21
86
|
|
|
22
|
-
|
|
87
|
+
function equalsSets(a, b) {
|
|
88
|
+
if (a.size !== b.size) {
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
const aList = _arrayFromIterator(a.values())
|
|
92
|
+
const bList = _arrayFromIterator(b.values())
|
|
93
|
+
|
|
94
|
+
const filtered = aList.filter(
|
|
95
|
+
aInstance => _indexOf(aInstance, bList) === -1
|
|
96
|
+
)
|
|
97
|
+
return filtered.length === 0
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function equals(a, b) {
|
|
23
101
|
if (arguments.length === 1) return _b => equals(a, _b)
|
|
24
102
|
|
|
25
103
|
const aType = type(a)
|
|
104
|
+
|
|
26
105
|
if (aType !== type(b)) return false
|
|
27
|
-
if (aType === 'Function'){
|
|
106
|
+
if (aType === 'Function') {
|
|
28
107
|
return a.name === undefined ? false : a.name === b.name
|
|
29
108
|
}
|
|
30
109
|
|
|
31
|
-
if ([
|
|
110
|
+
if (['NaN', 'Undefined', 'Null'].includes(aType)) return true
|
|
32
111
|
|
|
33
|
-
if (aType === 'Number'){
|
|
112
|
+
if (aType === 'Number') {
|
|
34
113
|
if (Object.is(-0, a) !== Object.is(-0, b)) return false
|
|
35
114
|
|
|
36
115
|
return a.toString() === b.toString()
|
|
37
116
|
}
|
|
38
117
|
|
|
39
|
-
if ([
|
|
118
|
+
if (['String', 'Boolean'].includes(aType)) {
|
|
40
119
|
return a.toString() === b.toString()
|
|
41
120
|
}
|
|
42
121
|
|
|
43
|
-
if (aType === 'Array'){
|
|
122
|
+
if (aType === 'Array') {
|
|
44
123
|
const aClone = Array.from(a)
|
|
45
124
|
const bClone = Array.from(b)
|
|
46
125
|
|
|
47
|
-
if (aClone.toString() !== bClone.toString()){
|
|
126
|
+
if (aClone.toString() !== bClone.toString()) {
|
|
48
127
|
return false
|
|
49
128
|
}
|
|
50
129
|
|
|
51
130
|
let loopArrayFlag = true
|
|
52
131
|
aClone.forEach((aCloneInstance, aCloneIndex) => {
|
|
53
|
-
if (loopArrayFlag){
|
|
132
|
+
if (loopArrayFlag) {
|
|
54
133
|
if (
|
|
55
|
-
aCloneInstance !== bClone[
|
|
56
|
-
!equals(aCloneInstance, bClone[
|
|
57
|
-
){
|
|
134
|
+
aCloneInstance !== bClone[aCloneIndex] &&
|
|
135
|
+
!equals(aCloneInstance, bClone[aCloneIndex])
|
|
136
|
+
) {
|
|
58
137
|
loopArrayFlag = false
|
|
59
138
|
}
|
|
60
139
|
}
|
|
@@ -66,40 +145,42 @@ export function equals(a, b){
|
|
|
66
145
|
const aRegex = parseRegex(a)
|
|
67
146
|
const bRegex = parseRegex(b)
|
|
68
147
|
|
|
69
|
-
if (aRegex[
|
|
70
|
-
return bRegex[
|
|
71
|
-
} else if (bRegex[
|
|
148
|
+
if (aRegex[0]) {
|
|
149
|
+
return bRegex[0] ? aRegex[1] === bRegex[1] : false
|
|
150
|
+
} else if (bRegex[0]) return false
|
|
72
151
|
|
|
73
152
|
const aDate = parseDate(a)
|
|
74
153
|
const bDate = parseDate(b)
|
|
75
154
|
|
|
76
|
-
if (aDate[
|
|
77
|
-
return bDate[
|
|
78
|
-
} else if (bDate[
|
|
155
|
+
if (aDate[0]) {
|
|
156
|
+
return bDate[0] ? aDate[1] === bDate[1] : false
|
|
157
|
+
} else if (bDate[0]) return false
|
|
79
158
|
|
|
80
159
|
const aError = parseError(a)
|
|
81
160
|
const bError = parseError(b)
|
|
82
161
|
|
|
83
|
-
if (aError[
|
|
84
|
-
return bError[
|
|
85
|
-
aError[
|
|
86
|
-
false
|
|
162
|
+
if (aError[0]) {
|
|
163
|
+
return bError[0]
|
|
164
|
+
? aError[0] === bError[0] && aError[1] === bError[1]
|
|
165
|
+
: false
|
|
87
166
|
}
|
|
88
|
-
|
|
89
|
-
|
|
167
|
+
if (aType === 'Set') {
|
|
168
|
+
return _equalsSets(a, b)
|
|
169
|
+
}
|
|
170
|
+
if (aType === 'Object') {
|
|
90
171
|
const aKeys = Object.keys(a)
|
|
91
172
|
|
|
92
|
-
if (aKeys.length !== Object.keys(b).length){
|
|
173
|
+
if (aKeys.length !== Object.keys(b).length) {
|
|
93
174
|
return false
|
|
94
175
|
}
|
|
95
176
|
|
|
96
177
|
let loopObjectFlag = true
|
|
97
178
|
aKeys.forEach(aKeyInstance => {
|
|
98
|
-
if (loopObjectFlag){
|
|
99
|
-
const aValue = a[
|
|
100
|
-
const bValue = b[
|
|
179
|
+
if (loopObjectFlag) {
|
|
180
|
+
const aValue = a[aKeyInstance]
|
|
181
|
+
const bValue = b[aKeyInstance]
|
|
101
182
|
|
|
102
|
-
if (aValue !== bValue && !equals(aValue, bValue)){
|
|
183
|
+
if (aValue !== bValue && !equals(aValue, bValue)) {
|
|
103
184
|
loopObjectFlag = false
|
|
104
185
|
}
|
|
105
186
|
}
|
package/src/evolve.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {_isArray} from './_internals/_isArray'
|
|
2
|
+
import {mapArray, mapObject} from './map'
|
|
3
|
+
import {type} from './type'
|
|
4
4
|
|
|
5
|
-
export function evolveArray(rules, list){
|
|
5
|
+
export function evolveArray(rules, list) {
|
|
6
6
|
return mapArray(
|
|
7
7
|
(x, i) => {
|
|
8
|
-
if (type(rules[
|
|
9
|
-
return rules[
|
|
8
|
+
if (type(rules[i]) === 'Function') {
|
|
9
|
+
return rules[i](x)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
return x
|
|
@@ -16,43 +16,45 @@ export function evolveArray(rules, list){
|
|
|
16
16
|
)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function evolveObject(rules, iterable){
|
|
19
|
+
export function evolveObject(rules, iterable) {
|
|
20
20
|
return mapObject((x, prop) => {
|
|
21
|
-
if (type(x) === 'Object'){
|
|
22
|
-
const typeRule = type(rules[
|
|
23
|
-
if (typeRule === 'Function'){
|
|
24
|
-
return rules[
|
|
21
|
+
if (type(x) === 'Object') {
|
|
22
|
+
const typeRule = type(rules[prop])
|
|
23
|
+
if (typeRule === 'Function') {
|
|
24
|
+
return rules[prop](x)
|
|
25
25
|
}
|
|
26
|
-
if (typeRule === 'Object'){
|
|
27
|
-
return evolve(rules[
|
|
26
|
+
if (typeRule === 'Object') {
|
|
27
|
+
return evolve(rules[prop], x)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return x
|
|
31
31
|
}
|
|
32
|
-
if (type(rules[
|
|
33
|
-
return rules[
|
|
32
|
+
if (type(rules[prop]) === 'Function') {
|
|
33
|
+
return rules[prop](x)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
return x
|
|
37
37
|
}, iterable)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function evolve(rules, iterable){
|
|
41
|
-
if (arguments.length === 1){
|
|
40
|
+
export function evolve(rules, iterable) {
|
|
41
|
+
if (arguments.length === 1) {
|
|
42
42
|
return _iterable => evolve(rules, _iterable)
|
|
43
43
|
}
|
|
44
44
|
const rulesType = type(rules)
|
|
45
45
|
const iterableType = type(iterable)
|
|
46
46
|
|
|
47
|
-
if (iterableType !== rulesType){
|
|
47
|
+
if (iterableType !== rulesType) {
|
|
48
48
|
throw new Error('iterableType !== rulesType')
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
if (![
|
|
52
|
-
throw new Error(
|
|
51
|
+
if (!['Object', 'Array'].includes(rulesType)) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`'iterable' and 'rules' are from wrong type ${rulesType}`
|
|
54
|
+
)
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
if (iterableType === 'Object'){
|
|
57
|
+
if (iterableType === 'Object') {
|
|
56
58
|
return evolveObject(rules, iterable)
|
|
57
59
|
}
|
|
58
60
|
|
package/src/filter.js
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {_isArray} from './_internals/_isArray'
|
|
2
2
|
|
|
3
|
-
export function filterObject(
|
|
3
|
+
export function filterObject(predicate, obj) {
|
|
4
4
|
const willReturn = {}
|
|
5
5
|
|
|
6
|
-
for (const prop in obj){
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
)){
|
|
10
|
-
willReturn[ prop ] = obj[ prop ]
|
|
6
|
+
for (const prop in obj) {
|
|
7
|
+
if (predicate(obj[prop], prop, obj)) {
|
|
8
|
+
willReturn[prop] = obj[prop]
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
return willReturn
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
export function filterArray(
|
|
18
|
-
predicate, list, indexed = false
|
|
19
|
-
){
|
|
15
|
+
export function filterArray(predicate, list, indexed = false) {
|
|
20
16
|
let index = 0
|
|
21
17
|
const len = list.length
|
|
22
18
|
const willReturn = []
|
|
23
19
|
|
|
24
|
-
while (index < len){
|
|
25
|
-
const predicateResult = indexed
|
|
26
|
-
predicate(list[
|
|
27
|
-
predicate(list[
|
|
28
|
-
if (predicateResult){
|
|
29
|
-
willReturn.push(list[
|
|
20
|
+
while (index < len) {
|
|
21
|
+
const predicateResult = indexed
|
|
22
|
+
? predicate(list[index], index)
|
|
23
|
+
: predicate(list[index])
|
|
24
|
+
if (predicateResult) {
|
|
25
|
+
willReturn.push(list[index])
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
index++
|
|
@@ -35,11 +31,13 @@ export function filterArray(
|
|
|
35
31
|
return willReturn
|
|
36
32
|
}
|
|
37
33
|
|
|
38
|
-
export function filter(predicate, iterable){
|
|
39
|
-
if (arguments.length === 1)
|
|
34
|
+
export function filter(predicate, iterable) {
|
|
35
|
+
if (arguments.length === 1)
|
|
40
36
|
return _iterable => filter(predicate, _iterable)
|
|
37
|
+
if (!iterable) {
|
|
38
|
+
throw new Error('Incorrect iterable input')
|
|
41
39
|
}
|
|
42
|
-
|
|
40
|
+
|
|
43
41
|
if (_isArray(iterable)) return filterArray(predicate, iterable)
|
|
44
42
|
|
|
45
43
|
return filterObject(predicate, iterable)
|
package/src/find.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export function find(predicate, list){
|
|
1
|
+
export function find(predicate, list) {
|
|
2
2
|
if (arguments.length === 1) return _list => find(predicate, _list)
|
|
3
3
|
|
|
4
4
|
let index = 0
|
|
5
5
|
const len = list.length
|
|
6
6
|
|
|
7
|
-
while (index < len){
|
|
8
|
-
const x = list[
|
|
9
|
-
if (predicate(x)){
|
|
7
|
+
while (index < len) {
|
|
8
|
+
const x = list[index]
|
|
9
|
+
if (predicate(x)) {
|
|
10
10
|
return x
|
|
11
11
|
}
|
|
12
12
|
|
package/src/findIndex.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export function findIndex(predicate, list){
|
|
1
|
+
export function findIndex(predicate, list) {
|
|
2
2
|
if (arguments.length === 1) return _list => findIndex(predicate, _list)
|
|
3
3
|
|
|
4
4
|
const len = list.length
|
|
5
5
|
let index = -1
|
|
6
6
|
|
|
7
|
-
while (++index < len){
|
|
8
|
-
if (predicate(list[
|
|
7
|
+
while (++index < len) {
|
|
8
|
+
if (predicate(list[index])) {
|
|
9
9
|
return index
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/findLast.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export function findLast(predicate, list){
|
|
1
|
+
export function findLast(predicate, list) {
|
|
2
2
|
if (arguments.length === 1) return _list => findLast(predicate, _list)
|
|
3
3
|
|
|
4
4
|
let index = list.length
|
|
5
5
|
|
|
6
|
-
while (--index >= 0){
|
|
7
|
-
if (predicate(list[
|
|
8
|
-
return list[
|
|
6
|
+
while (--index >= 0) {
|
|
7
|
+
if (predicate(list[index])) {
|
|
8
|
+
return list[index]
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
package/src/findLastIndex.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export function findLastIndex(fn, list){
|
|
1
|
+
export function findLastIndex(fn, list) {
|
|
2
2
|
if (arguments.length === 1) return _list => findLastIndex(fn, _list)
|
|
3
3
|
|
|
4
4
|
let index = list.length
|
|
5
5
|
|
|
6
|
-
while (--index >= 0){
|
|
7
|
-
if (fn(list[
|
|
6
|
+
while (--index >= 0) {
|
|
7
|
+
if (fn(list[index])) {
|
|
8
8
|
return index
|
|
9
9
|
}
|
|
10
10
|
}
|
package/src/flatten.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {_isArray} from './_internals/_isArray'
|
|
2
2
|
|
|
3
|
-
export function flatten(list, input){
|
|
3
|
+
export function flatten(list, input) {
|
|
4
4
|
const willReturn = input === undefined ? [] : input
|
|
5
5
|
|
|
6
|
-
for (let i = 0; i < list.length; i++){
|
|
7
|
-
if (_isArray(list[
|
|
8
|
-
flatten(list[
|
|
6
|
+
for (let i = 0; i < list.length; i++) {
|
|
7
|
+
if (_isArray(list[i])) {
|
|
8
|
+
flatten(list[i], willReturn)
|
|
9
9
|
} else {
|
|
10
|
-
willReturn.push(list[
|
|
10
|
+
willReturn.push(list[i])
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
package/src/flip.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
function flipFn(fn){
|
|
1
|
+
function flipFn(fn) {
|
|
2
2
|
return (...input) => {
|
|
3
|
-
if (input.length === 1){
|
|
4
|
-
return holder => fn(holder, input[
|
|
5
|
-
} else if (input.length === 2){
|
|
6
|
-
return fn(input[
|
|
7
|
-
} else if (input.length === 3){
|
|
8
|
-
return fn(
|
|
9
|
-
|
|
10
|
-
)
|
|
11
|
-
} else if (input.length === 4){
|
|
12
|
-
return fn(
|
|
13
|
-
input[ 1 ], input[ 0 ], input[ 2 ], input[ 3 ]
|
|
14
|
-
)
|
|
3
|
+
if (input.length === 1) {
|
|
4
|
+
return holder => fn(holder, input[0])
|
|
5
|
+
} else if (input.length === 2) {
|
|
6
|
+
return fn(input[1], input[0])
|
|
7
|
+
} else if (input.length === 3) {
|
|
8
|
+
return fn(input[1], input[0], input[2])
|
|
9
|
+
} else if (input.length === 4) {
|
|
10
|
+
return fn(input[1], input[0], input[2], input[3])
|
|
15
11
|
}
|
|
16
12
|
|
|
17
|
-
throw new Error(
|
|
13
|
+
throw new Error("R.flip doesn't work with arity > 4")
|
|
18
14
|
}
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
export function flip(fn){
|
|
17
|
+
export function flip(fn) {
|
|
22
18
|
return flipFn(fn)
|
|
23
19
|
}
|
package/src/forEach.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {_isArray} from './_internals/_isArray'
|
|
2
|
+
import {_keys} from './_internals/_keys'
|
|
3
3
|
|
|
4
|
-
export function forEach(fn, list){
|
|
4
|
+
export function forEach(fn, list) {
|
|
5
5
|
if (arguments.length === 1) return _list => forEach(fn, _list)
|
|
6
6
|
|
|
7
|
-
if (list === undefined){
|
|
7
|
+
if (list === undefined) {
|
|
8
8
|
return
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
if (_isArray(list)){
|
|
11
|
+
if (_isArray(list)) {
|
|
12
12
|
let index = 0
|
|
13
13
|
const len = list.length
|
|
14
14
|
|
|
15
|
-
while (index < len){
|
|
16
|
-
fn(list[
|
|
15
|
+
while (index < len) {
|
|
16
|
+
fn(list[index])
|
|
17
17
|
index++
|
|
18
18
|
}
|
|
19
19
|
} else {
|
|
@@ -21,11 +21,9 @@ export function forEach(fn, list){
|
|
|
21
21
|
const keys = _keys(list)
|
|
22
22
|
const len = keys.length
|
|
23
23
|
|
|
24
|
-
while (index < len){
|
|
25
|
-
const key = keys[
|
|
26
|
-
fn(
|
|
27
|
-
list[ key ], key, list
|
|
28
|
-
)
|
|
24
|
+
while (index < len) {
|
|
25
|
+
const key = keys[index]
|
|
26
|
+
fn(list[key], key, list)
|
|
29
27
|
index++
|
|
30
28
|
}
|
|
31
29
|
}
|
package/src/fromPairs.js
CHANGED
package/src/groupBy.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export function groupBy(groupFn, list){
|
|
1
|
+
export function groupBy(groupFn, list) {
|
|
2
2
|
if (arguments.length === 1) return _list => groupBy(groupFn, _list)
|
|
3
3
|
|
|
4
4
|
const result = {}
|
|
5
|
-
for (let i = 0; i < list.length; i++){
|
|
6
|
-
const item = list[
|
|
5
|
+
for (let i = 0; i < list.length; i++) {
|
|
6
|
+
const item = list[i]
|
|
7
7
|
const key = groupFn(item)
|
|
8
8
|
|
|
9
|
-
if (!result[
|
|
10
|
-
result[
|
|
9
|
+
if (!result[key]) {
|
|
10
|
+
result[key] = []
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
result[
|
|
13
|
+
result[key].push(item)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
return result
|
package/src/groupWith.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {_isArray} from './_internals/_isArray'
|
|
2
|
+
import {cloneList} from './_internals/cloneList'
|
|
2
3
|
|
|
3
|
-
export function groupWith(compareFn, list){
|
|
4
|
+
export function groupWith(compareFn, list) {
|
|
4
5
|
if (!_isArray(list)) throw new TypeError('list.reduce is not a function')
|
|
5
6
|
|
|
6
|
-
const clone = list
|
|
7
|
+
const clone = cloneList(list)
|
|
7
8
|
|
|
8
|
-
if (list.length === 1) return [
|
|
9
|
+
if (list.length === 1) return [clone]
|
|
9
10
|
|
|
10
11
|
const toReturn = []
|
|
11
12
|
let holder = []
|
|
12
13
|
|
|
13
|
-
clone.reduce((
|
|
14
|
-
prev, current, i
|
|
15
|
-
) => {
|
|
14
|
+
clone.reduce((prev, current, i) => {
|
|
16
15
|
if (i === 0) return current
|
|
17
16
|
|
|
18
17
|
const okCompare = compareFn(prev, current)
|
|
19
18
|
const holderIsEmpty = holder.length === 0
|
|
20
19
|
const lastCall = i === list.length - 1
|
|
21
20
|
|
|
22
|
-
if (okCompare){
|
|
21
|
+
if (okCompare) {
|
|
23
22
|
if (holderIsEmpty) holder.push(prev)
|
|
24
23
|
holder.push(current)
|
|
25
24
|
if (lastCall) toReturn.push(holder)
|
|
@@ -27,15 +26,15 @@ export function groupWith(compareFn, list){
|
|
|
27
26
|
return current
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
if (holderIsEmpty){
|
|
31
|
-
toReturn.push([
|
|
32
|
-
if (lastCall) toReturn.push([
|
|
29
|
+
if (holderIsEmpty) {
|
|
30
|
+
toReturn.push([prev])
|
|
31
|
+
if (lastCall) toReturn.push([current])
|
|
33
32
|
|
|
34
33
|
return current
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
toReturn.push(holder)
|
|
38
|
-
if (lastCall) toReturn.push([
|
|
37
|
+
if (lastCall) toReturn.push([current])
|
|
39
38
|
holder = []
|
|
40
39
|
|
|
41
40
|
return current
|
package/src/hasPath.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {path} from './path'
|
|
2
2
|
|
|
3
|
-
export function hasPath(
|
|
4
|
-
if (arguments.length === 1){
|
|
5
|
-
return objHolder => hasPath(
|
|
3
|
+
export function hasPath(pathInput, obj) {
|
|
4
|
+
if (arguments.length === 1) {
|
|
5
|
+
return objHolder => hasPath(pathInput, objHolder)
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
return path(
|
|
8
|
+
return path(pathInput, obj) !== undefined
|
|
9
9
|
}
|