rambda 7.0.2 → 7.1.1
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 +28 -2
- package/README.md +3703 -3294
- package/dist/rambda.js +284 -78
- package/dist/rambda.mjs +270 -78
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +95 -13
- package/index.d.ts +95 -13
- package/package.json +119 -119
- package/src/F.js +1 -1
- package/src/T.js +1 -1
- package/src/_internals/_isInteger.js +1 -1
- package/src/_internals/_keys.js +0 -1
- package/src/_internals/_objectIs.js +2 -7
- package/src/_internals/baseSlice.js +8 -6
- package/src/_internals/cloneList.js +1 -3
- package/src/_internals/createPath.js +3 -0
- package/src/_internals/isFalsy.js +5 -5
- package/src/_internals/isObject.js +2 -2
- package/src/_internals/isTruthy.js +5 -5
- package/src/_internals/set.js +19 -13
- package/src/add.js +1 -1
- package/src/adjust.js +6 -4
- package/src/all.js +3 -3
- package/src/allPass.js +3 -3
- package/src/always.js +2 -2
- package/src/and.js +1 -1
- package/src/any.js +3 -3
- package/src/anyPass.js +3 -3
- package/src/append.js +2 -2
- package/src/apply.js +2 -2
- package/src/applySpec.js +59 -33
- package/src/assoc.js +7 -3
- package/src/assocPath.js +25 -21
- package/src/bind.js +3 -3
- 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 +5 -14
- package/src/concat.js +2 -2
- package/src/cond.js +3 -3
- package/src/converge.js +11 -11
- package/src/count.js +10 -0
- package/src/countBy.js +17 -0
- package/src/curry.js +2 -2
- package/src/curryN.js +81 -61
- package/src/defaultTo.js +3 -3
- 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 +6 -5
- package/src/eqProps.js +6 -4
- package/src/equals.js +64 -65
- package/src/evolve.js +21 -23
- package/src/filter.js +21 -15
- 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 +15 -11
- package/src/forEach.js +12 -10
- package/src/fromPairs.js +2 -2
- package/src/groupBy.js +6 -6
- package/src/groupWith.js +12 -10
- package/src/has.js +1 -1
- package/src/hasPath.js +3 -3
- package/src/head.js +3 -3
- package/src/identical.js +2 -2
- package/src/identity.js +1 -1
- package/src/ifElse.js +5 -3
- package/src/includes.js +6 -6
- package/src/indexBy.js +11 -11
- package/src/indexOf.js +3 -3
- package/src/init.js +7 -3
- 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/isNil.js +1 -1
- package/src/isPromise.js +3 -3
- package/src/join.js +1 -1
- package/src/juxt.js +3 -0
- package/src/keys.js +1 -1
- package/src/last.js +4 -4
- package/src/lastIndexOf.js +3 -3
- package/src/length.js +2 -2
- package/src/lens.js +3 -3
- package/src/lensIndex.js +4 -4
- package/src/lensPath.js +4 -4
- package/src/lensProp.js +4 -4
- package/src/map.js +15 -11
- package/src/match.js +1 -1
- package/src/mathMod.js +3 -3
- package/src/max.js +1 -1
- package/src/maxBy.js +4 -2
- package/src/maybe.js +4 -2
- package/src/mean.js +2 -2
- package/src/median.js +10 -12
- package/src/merge.js +1 -5
- package/src/mergeAll.js +4 -4
- package/src/mergeDeepRight.js +8 -8
- package/src/mergeLeft.js +3 -3
- package/src/mergeRight.js +7 -0
- package/src/mergeWith.js +29 -0
- package/src/min.js +1 -1
- package/src/minBy.js +4 -2
- package/src/modulo.js +1 -1
- package/src/move.js +8 -6
- package/src/multiply.js +1 -1
- package/src/negate.js +1 -1
- package/src/none.js +4 -4
- package/src/not.js +1 -1
- package/src/nth.js +6 -6
- package/src/objOf.js +3 -5
- package/src/of.js +2 -2
- package/src/omit.js +8 -8
- package/src/on.js +16 -0
- package/src/once.js +6 -6
- package/src/or.js +1 -1
- package/src/over.js +5 -3
- package/src/partial.js +3 -3
- package/src/partialObject.js +15 -0
- package/src/partition.js +18 -16
- package/src/path.js +9 -8
- package/src/pathEq.js +6 -4
- package/src/pathOr.js +6 -4
- package/src/paths.js +3 -3
- package/src/pick.js +8 -8
- package/src/pickAll.js +9 -9
- package/src/pipe.js +85 -13
- 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 +5 -3
- package/src/propIs.js +6 -4
- package/src/propOr.js +6 -4
- package/src/propSatisfies.js +10 -0
- package/src/props.js +6 -6
- package/src/range.js +4 -4
- package/src/reduce.js +11 -7
- package/src/reject.js +2 -2
- package/src/repeat.js +2 -2
- package/src/replace.js +4 -2
- package/src/reverse.js +4 -3
- package/src/set.js +9 -5
- package/src/slice.js +4 -2
- package/src/sort.js +2 -2
- package/src/sortBy.js +2 -2
- package/src/split.js +1 -1
- package/src/splitAt.js +9 -9
- package/src/splitEvery.js +6 -8
- package/src/splitWhen.js +10 -10
- package/src/startsWith.js +6 -5
- package/src/subtract.js +1 -1
- package/src/sum.js +1 -1
- package/src/symmetricDifference.js +7 -9
- package/src/tail.js +2 -2
- package/src/take.js +5 -3
- package/src/takeLast.js +5 -3
- package/src/takeLastWhile.js +7 -7
- package/src/takeWhile.js +8 -8
- package/src/tap.js +1 -1
- package/src/test.js +3 -5
- 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 +3 -4
- package/src/trim.js +1 -1
- package/src/tryCatch.js +7 -5
- package/src/type.js +5 -5
- package/src/unapply.js +2 -2
- package/src/union.js +3 -3
- package/src/uniq.js +3 -3
- package/src/uniqWith.js +12 -8
- package/src/unless.js +3 -3
- package/src/unwind.js +15 -0
- package/src/update.js +8 -4
- package/src/values.js +2 -2
- package/src/view.js +2 -2
- package/src/when.js +4 -2
- package/src/where.js +5 -5
- package/src/whereAny.js +12 -0
- package/src/whereEq.js +7 -9
- package/src/without.js +4 -4
- package/src/xor.js +2 -2
- package/src/zip.js +3 -3
- package/src/zipObj.js +6 -4
- package/src/zipWith.js +6 -6
- package/src/isFunction.js +0 -5
package/src/applySpec.js
CHANGED
|
@@ -1,71 +1,93 @@
|
|
|
1
|
-
import {_isArray} from './_internals/_isArray'
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
2
|
|
|
3
3
|
// recursively traverse the given spec object to find the highest arity function
|
|
4
|
-
function __findHighestArity(spec, max = 0)
|
|
5
|
-
for (const key in spec)
|
|
4
|
+
export function __findHighestArity(spec, max = 0){
|
|
5
|
+
for (const key in spec){
|
|
6
6
|
if (spec.hasOwnProperty(key) === false || key === 'constructor') continue
|
|
7
7
|
|
|
8
|
-
if (typeof spec[key] === 'object')
|
|
9
|
-
max = Math.max(max, __findHighestArity(spec[key]))
|
|
8
|
+
if (typeof spec[ key ] === 'object'){
|
|
9
|
+
max = Math.max(max, __findHighestArity(spec[ key ]))
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
if (typeof spec[key] === 'function')
|
|
13
|
-
max = Math.max(max, spec[key].length)
|
|
12
|
+
if (typeof spec[ key ] === 'function'){
|
|
13
|
+
max = Math.max(max, spec[ key ].length)
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
return max
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function __filterUndefined()
|
|
20
|
+
function __filterUndefined(){
|
|
21
21
|
const defined = []
|
|
22
22
|
let i = 0
|
|
23
23
|
const l = arguments.length
|
|
24
|
-
while (i < l)
|
|
25
|
-
if (typeof arguments[i] === 'undefined') break
|
|
26
|
-
defined[i] = arguments[i]
|
|
24
|
+
while (i < l){
|
|
25
|
+
if (typeof arguments[ i ] === 'undefined') break
|
|
26
|
+
defined[ i ] = arguments[ i ]
|
|
27
27
|
i++
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return defined
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function __applySpecWithArity(
|
|
33
|
+
function __applySpecWithArity(
|
|
34
|
+
spec, arity, cache
|
|
35
|
+
){
|
|
34
36
|
const remaining = arity - cache.length
|
|
35
37
|
|
|
36
38
|
if (remaining === 1)
|
|
37
39
|
return x =>
|
|
38
|
-
__applySpecWithArity(
|
|
40
|
+
__applySpecWithArity(
|
|
41
|
+
spec, arity, __filterUndefined(...cache, x)
|
|
42
|
+
)
|
|
39
43
|
if (remaining === 2)
|
|
40
44
|
return (x, y) =>
|
|
41
|
-
__applySpecWithArity(
|
|
45
|
+
__applySpecWithArity(
|
|
46
|
+
spec, arity, __filterUndefined(
|
|
47
|
+
...cache, x, y
|
|
48
|
+
)
|
|
49
|
+
)
|
|
42
50
|
if (remaining === 3)
|
|
43
|
-
return (
|
|
44
|
-
|
|
51
|
+
return (
|
|
52
|
+
x, y, z
|
|
53
|
+
) =>
|
|
54
|
+
__applySpecWithArity(
|
|
55
|
+
spec, arity, __filterUndefined(
|
|
56
|
+
...cache, x, y, z
|
|
57
|
+
)
|
|
58
|
+
)
|
|
45
59
|
if (remaining === 4)
|
|
46
|
-
return (
|
|
60
|
+
return (
|
|
61
|
+
x, y, z, a
|
|
62
|
+
) =>
|
|
47
63
|
__applySpecWithArity(
|
|
48
64
|
spec,
|
|
49
65
|
arity,
|
|
50
|
-
__filterUndefined(
|
|
66
|
+
__filterUndefined(
|
|
67
|
+
...cache, x, y, z, a
|
|
68
|
+
)
|
|
51
69
|
)
|
|
52
70
|
if (remaining > 4)
|
|
53
71
|
return (...args) =>
|
|
54
|
-
__applySpecWithArity(
|
|
72
|
+
__applySpecWithArity(
|
|
73
|
+
spec, arity, __filterUndefined(...cache, ...args)
|
|
74
|
+
)
|
|
55
75
|
|
|
56
76
|
// handle spec as Array
|
|
57
|
-
if (_isArray(spec))
|
|
77
|
+
if (_isArray(spec)){
|
|
58
78
|
const ret = []
|
|
59
79
|
let i = 0
|
|
60
80
|
const l = spec.length
|
|
61
|
-
for (; i < l; i++)
|
|
81
|
+
for (; i < l; i++){
|
|
62
82
|
// handle recursive spec inside array
|
|
63
|
-
if (typeof spec[i] === 'object' || _isArray(spec[i]))
|
|
64
|
-
ret[i] = __applySpecWithArity(
|
|
83
|
+
if (typeof spec[ i ] === 'object' || _isArray(spec[ i ])){
|
|
84
|
+
ret[ i ] = __applySpecWithArity(
|
|
85
|
+
spec[ i ], arity, cache
|
|
86
|
+
)
|
|
65
87
|
}
|
|
66
88
|
// apply spec to the key
|
|
67
|
-
if (typeof spec[i] === 'function')
|
|
68
|
-
ret[i] = spec[i](...cache)
|
|
89
|
+
if (typeof spec[ i ] === 'function'){
|
|
90
|
+
ret[ i ] = spec[ i ](...cache)
|
|
69
91
|
}
|
|
70
92
|
}
|
|
71
93
|
|
|
@@ -75,32 +97,36 @@ function __applySpecWithArity(spec, arity, cache) {
|
|
|
75
97
|
// handle spec as Object
|
|
76
98
|
const ret = {}
|
|
77
99
|
// apply callbacks to each property in the spec object
|
|
78
|
-
for (const key in spec)
|
|
100
|
+
for (const key in spec){
|
|
79
101
|
if (spec.hasOwnProperty(key) === false || key === 'constructor') continue
|
|
80
102
|
|
|
81
103
|
// apply the spec recursively
|
|
82
|
-
if (typeof spec[key] === 'object')
|
|
83
|
-
ret[key] = __applySpecWithArity(
|
|
104
|
+
if (typeof spec[ key ] === 'object'){
|
|
105
|
+
ret[ key ] = __applySpecWithArity(
|
|
106
|
+
spec[ key ], arity, cache
|
|
107
|
+
)
|
|
84
108
|
continue
|
|
85
109
|
}
|
|
86
110
|
|
|
87
111
|
// apply spec to the key
|
|
88
|
-
if (typeof spec[key] === 'function')
|
|
89
|
-
ret[key] = spec[key](...cache)
|
|
112
|
+
if (typeof spec[ key ] === 'function'){
|
|
113
|
+
ret[ key ] = spec[ key ](...cache)
|
|
90
114
|
}
|
|
91
115
|
}
|
|
92
116
|
|
|
93
117
|
return ret
|
|
94
118
|
}
|
|
95
119
|
|
|
96
|
-
export function applySpec(spec, ...args)
|
|
120
|
+
export function applySpec(spec, ...args){
|
|
97
121
|
// get the highest arity spec function, cache the result and pass to __applySpecWithArity
|
|
98
122
|
const arity = __findHighestArity(spec)
|
|
99
123
|
|
|
100
|
-
if (arity === 0)
|
|
124
|
+
if (arity === 0){
|
|
101
125
|
return () => ({})
|
|
102
126
|
}
|
|
103
|
-
const toReturn = __applySpecWithArity(
|
|
127
|
+
const toReturn = __applySpecWithArity(
|
|
128
|
+
spec, arity, args
|
|
129
|
+
)
|
|
104
130
|
|
|
105
131
|
return toReturn
|
|
106
132
|
}
|
package/src/assoc.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {curry} from './curry'
|
|
1
|
+
import { curry } from './curry.js'
|
|
2
2
|
|
|
3
|
-
function assocFn(
|
|
4
|
-
|
|
3
|
+
function assocFn(
|
|
4
|
+
prop, newValue, obj
|
|
5
|
+
){
|
|
6
|
+
return Object.assign(
|
|
7
|
+
{}, obj, { [ prop ] : newValue }
|
|
8
|
+
)
|
|
5
9
|
}
|
|
6
10
|
|
|
7
11
|
export const assoc = curry(assocFn)
|
package/src/assocPath.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import {_isArray} from './_internals/_isArray'
|
|
2
|
-
import {_isInteger} from './_internals/_isInteger'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
function assocPathFn(
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
|
+
import { _isInteger } from './_internals/_isInteger.js'
|
|
3
|
+
import { cloneList } from './_internals/cloneList.js'
|
|
4
|
+
import { assoc } from './assoc.js'
|
|
5
|
+
import { curry } from './curry.js'
|
|
6
|
+
|
|
7
|
+
function assocPathFn(
|
|
8
|
+
path, newValue, input
|
|
9
|
+
){
|
|
8
10
|
const pathArrValue =
|
|
9
|
-
typeof path === 'string'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (pathArrValue.length === 0)
|
|
11
|
+
typeof path === 'string' ?
|
|
12
|
+
path.split('.').map(x => _isInteger(Number(x)) ? Number(x) : x) :
|
|
13
|
+
path
|
|
14
|
+
if (pathArrValue.length === 0){
|
|
13
15
|
return newValue
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
const index = pathArrValue[0]
|
|
17
|
-
if (pathArrValue.length > 1)
|
|
18
|
+
const index = pathArrValue[ 0 ]
|
|
19
|
+
if (pathArrValue.length > 1){
|
|
18
20
|
const condition =
|
|
19
21
|
typeof input !== 'object' ||
|
|
20
22
|
input === null ||
|
|
21
23
|
!input.hasOwnProperty(index)
|
|
22
24
|
|
|
23
|
-
const nextinput = condition
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const nextinput = condition ?
|
|
26
|
+
_isInteger(pathArrValue[ 1 ]) ?
|
|
27
|
+
[] :
|
|
28
|
+
{} :
|
|
29
|
+
input[ index ]
|
|
28
30
|
|
|
29
31
|
newValue = assocPathFn(
|
|
30
32
|
Array.prototype.slice.call(pathArrValue, 1),
|
|
@@ -33,14 +35,16 @@ function assocPathFn(path, newValue, input) {
|
|
|
33
35
|
)
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
if (_isInteger(index) && _isArray(input))
|
|
38
|
+
if (_isInteger(index) && _isArray(input)){
|
|
37
39
|
const arr = cloneList(input)
|
|
38
|
-
arr[index] = newValue
|
|
40
|
+
arr[ index ] = newValue
|
|
39
41
|
|
|
40
42
|
return arr
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
return assoc(
|
|
45
|
+
return assoc(
|
|
46
|
+
index, newValue, input
|
|
47
|
+
)
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
export const assocPath = curry(assocPathFn)
|
package/src/bind.js
CHANGED
package/src/both.js
CHANGED
package/src/chain.js
CHANGED
package/src/clamp.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {curry} from './curry'
|
|
1
|
+
import { curry } from './curry.js'
|
|
2
2
|
|
|
3
|
-
function clampFn(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
)
|
|
3
|
+
function clampFn(
|
|
4
|
+
min, max, input
|
|
5
|
+
){
|
|
6
|
+
if (min > max){
|
|
7
|
+
throw new Error('min must not be greater than max in clamp(min, max, value)')
|
|
8
8
|
}
|
|
9
9
|
if (input >= min && input <= max) return input
|
|
10
10
|
|
package/src/clone.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {_isArray} from './_internals/_isArray'
|
|
1
|
+
import { _isArray } from './_internals/_isArray.js'
|
|
2
2
|
|
|
3
|
-
export function clone(input)
|
|
3
|
+
export function clone(input){
|
|
4
4
|
const out = _isArray(input) ? Array(input.length) : {}
|
|
5
5
|
if (input && input.getTime) return new Date(input.getTime())
|
|
6
6
|
|
|
7
|
-
for (const key in input)
|
|
8
|
-
const v = input[key]
|
|
9
|
-
out[key] =
|
|
10
|
-
typeof v === 'object' && v !== null
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
for (const key in input){
|
|
8
|
+
const v = input[ key ]
|
|
9
|
+
out[ key ] =
|
|
10
|
+
typeof v === 'object' && v !== null ?
|
|
11
|
+
v.getTime ?
|
|
12
|
+
new Date(v.getTime()) :
|
|
13
|
+
clone(v) :
|
|
14
|
+
v
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
return out
|
package/src/complement.js
CHANGED
package/src/compose.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { pipe } from './pipe.js'
|
|
2
|
+
|
|
3
|
+
export function compose(){
|
|
4
|
+
if (arguments.length === 0){
|
|
3
5
|
throw new Error('compose requires at least one argument')
|
|
4
6
|
}
|
|
5
7
|
|
|
6
|
-
return
|
|
7
|
-
const list = fns.slice()
|
|
8
|
-
if (list.length > 0) {
|
|
9
|
-
const fn = list.pop()
|
|
10
|
-
let result = fn.apply(this, args)
|
|
11
|
-
while (list.length > 0) {
|
|
12
|
-
result = list.pop()(result)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return result
|
|
16
|
-
}
|
|
17
|
-
}
|
|
8
|
+
return pipe.apply(this, Array.prototype.slice.call(arguments, 0).reverse())
|
|
18
9
|
}
|
package/src/concat.js
CHANGED
package/src/cond.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export function cond(conditions)
|
|
1
|
+
export function cond(conditions){
|
|
2
2
|
return input => {
|
|
3
3
|
let done = false
|
|
4
4
|
let toReturn
|
|
5
|
-
conditions.forEach(([predicate, resultClosure]) => {
|
|
6
|
-
if (!done && predicate(input))
|
|
5
|
+
conditions.forEach(([ predicate, resultClosure ]) => {
|
|
6
|
+
if (!done && predicate(input)){
|
|
7
7
|
done = true
|
|
8
8
|
toReturn = resultClosure(input)
|
|
9
9
|
}
|
package/src/converge.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {curryN} from './curryN'
|
|
2
|
-
import {map} from './map'
|
|
3
|
-
import {max} from './max'
|
|
4
|
-
import {reduce} from './reduce'
|
|
1
|
+
import { curryN } from './curryN.js'
|
|
2
|
+
import { map } from './map.js'
|
|
3
|
+
import { max } from './max.js'
|
|
4
|
+
import { reduce } from './reduce.js'
|
|
5
5
|
|
|
6
|
-
export function converge(fn, transformers)
|
|
6
|
+
export function converge(fn, transformers){
|
|
7
7
|
if (arguments.length === 1)
|
|
8
8
|
return _transformers => converge(fn, _transformers)
|
|
9
9
|
|
|
10
|
-
const highestArity = reduce(
|
|
10
|
+
const highestArity = reduce(
|
|
11
|
+
(a, b) => max(a, b.length), 0, transformers
|
|
12
|
+
)
|
|
11
13
|
|
|
12
|
-
return curryN(highestArity, function ()
|
|
13
|
-
return fn.apply(
|
|
14
|
-
this,
|
|
15
|
-
map(g => g.apply(this, arguments), transformers)
|
|
16
|
-
)
|
|
14
|
+
return curryN(highestArity, function (){
|
|
15
|
+
return fn.apply(this,
|
|
16
|
+
map(g => g.apply(this, arguments), transformers))
|
|
17
17
|
})
|
|
18
18
|
}
|
package/src/count.js
ADDED
package/src/countBy.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function countBy(fn, list){
|
|
2
|
+
if (arguments.length === 1){
|
|
3
|
+
return _list => countBy(fn, _list)
|
|
4
|
+
}
|
|
5
|
+
const willReturn = {}
|
|
6
|
+
|
|
7
|
+
list.forEach(item => {
|
|
8
|
+
const key = fn(item)
|
|
9
|
+
if (!willReturn[ key ]){
|
|
10
|
+
willReturn[ key ] = 1
|
|
11
|
+
} else {
|
|
12
|
+
willReturn[ key ]++
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
return willReturn
|
|
17
|
+
}
|
package/src/curry.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function curry(fn, args = [])
|
|
1
|
+
export function curry(fn, args = []){
|
|
2
2
|
return (..._args) =>
|
|
3
|
-
(rest =>
|
|
3
|
+
(rest => rest.length >= fn.length ? fn(...rest) : curry(fn, rest))([
|
|
4
4
|
...args,
|
|
5
5
|
..._args,
|
|
6
6
|
])
|
package/src/curryN.js
CHANGED
|
@@ -1,83 +1,103 @@
|
|
|
1
|
-
function _curryN(
|
|
2
|
-
|
|
1
|
+
function _curryN(
|
|
2
|
+
n, cache, fn
|
|
3
|
+
){
|
|
4
|
+
return function (){
|
|
3
5
|
let ci = 0
|
|
4
6
|
let ai = 0
|
|
5
7
|
const cl = cache.length
|
|
6
8
|
const al = arguments.length
|
|
7
9
|
const args = new Array(cl + al)
|
|
8
|
-
while (ci < cl)
|
|
9
|
-
args[ci] = cache[ci]
|
|
10
|
+
while (ci < cl){
|
|
11
|
+
args[ ci ] = cache[ ci ]
|
|
10
12
|
ci++
|
|
11
13
|
}
|
|
12
|
-
while (ai < al)
|
|
13
|
-
args[cl + ai] = arguments[ai]
|
|
14
|
+
while (ai < al){
|
|
15
|
+
args[ cl + ai ] = arguments[ ai ]
|
|
14
16
|
ai++
|
|
15
17
|
}
|
|
16
18
|
const remaining = n - args.length
|
|
17
19
|
|
|
18
|
-
return args.length >= n
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
return args.length >= n ?
|
|
21
|
+
fn.apply(this, args) :
|
|
22
|
+
_arity(remaining, _curryN(
|
|
23
|
+
n, args, fn
|
|
24
|
+
))
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
function _arity(n, fn)
|
|
25
|
-
switch (n)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
28
|
+
function _arity(n, fn){
|
|
29
|
+
switch (n){
|
|
30
|
+
case 0:
|
|
31
|
+
return function (){
|
|
32
|
+
return fn.apply(this, arguments)
|
|
33
|
+
}
|
|
34
|
+
case 1:
|
|
35
|
+
return function (_1){
|
|
36
|
+
return fn.apply(this, arguments)
|
|
37
|
+
}
|
|
38
|
+
case 2:
|
|
39
|
+
return function (_1, _2){
|
|
40
|
+
return fn.apply(this, arguments)
|
|
41
|
+
}
|
|
42
|
+
case 3:
|
|
43
|
+
return function (
|
|
44
|
+
_1, _2, _3
|
|
45
|
+
){
|
|
46
|
+
return fn.apply(this, arguments)
|
|
47
|
+
}
|
|
48
|
+
case 4:
|
|
49
|
+
return function (
|
|
50
|
+
_1, _2, _3, _4
|
|
51
|
+
){
|
|
52
|
+
return fn.apply(this, arguments)
|
|
53
|
+
}
|
|
54
|
+
case 5:
|
|
55
|
+
return function (
|
|
56
|
+
_1, _2, _3, _4, _5
|
|
57
|
+
){
|
|
58
|
+
return fn.apply(this, arguments)
|
|
59
|
+
}
|
|
60
|
+
case 6:
|
|
61
|
+
return function (
|
|
62
|
+
_1, _2, _3, _4, _5, _6
|
|
63
|
+
){
|
|
64
|
+
return fn.apply(this, arguments)
|
|
65
|
+
}
|
|
66
|
+
case 7:
|
|
67
|
+
return function (
|
|
68
|
+
_1, _2, _3, _4, _5, _6, _7
|
|
69
|
+
){
|
|
70
|
+
return fn.apply(this, arguments)
|
|
71
|
+
}
|
|
72
|
+
case 8:
|
|
73
|
+
return function (
|
|
74
|
+
_1, _2, _3, _4, _5, _6, _7, _8
|
|
75
|
+
){
|
|
76
|
+
return fn.apply(this, arguments)
|
|
77
|
+
}
|
|
78
|
+
case 9:
|
|
79
|
+
return function (
|
|
80
|
+
_1, _2, _3, _4, _5, _6, _7, _8, _9
|
|
81
|
+
){
|
|
82
|
+
return fn.apply(this, arguments)
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
return function (
|
|
86
|
+
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10
|
|
87
|
+
){
|
|
88
|
+
return fn.apply(this, arguments)
|
|
89
|
+
}
|
|
70
90
|
}
|
|
71
91
|
}
|
|
72
92
|
|
|
73
|
-
export function curryN(n, fn)
|
|
93
|
+
export function curryN(n, fn){
|
|
74
94
|
if (arguments.length === 1) return _fn => curryN(n, _fn)
|
|
75
95
|
|
|
76
|
-
if (n > 10)
|
|
77
|
-
throw new Error(
|
|
78
|
-
'First argument to _arity must be a non-negative integer no greater than ten'
|
|
79
|
-
)
|
|
96
|
+
if (n > 10){
|
|
97
|
+
throw new Error('First argument to _arity must be a non-negative integer no greater than ten')
|
|
80
98
|
}
|
|
81
99
|
|
|
82
|
-
return _arity(n, _curryN(
|
|
100
|
+
return _arity(n, _curryN(
|
|
101
|
+
n, [], fn
|
|
102
|
+
))
|
|
83
103
|
}
|
package/src/defaultTo.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function isFalsy(input)
|
|
1
|
+
function isFalsy(input){
|
|
2
2
|
return (
|
|
3
3
|
input === undefined || input === null || Number.isNaN(input) === true
|
|
4
4
|
)
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export function defaultTo(defaultArgument, input)
|
|
8
|
-
if (arguments.length === 1)
|
|
7
|
+
export function defaultTo(defaultArgument, input){
|
|
8
|
+
if (arguments.length === 1){
|
|
9
9
|
return _input => defaultTo(defaultArgument, _input)
|
|
10
10
|
}
|
|
11
11
|
|
package/src/difference.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {includes} from './includes'
|
|
2
|
-
import {uniq} from './uniq'
|
|
1
|
+
import { includes } from './includes.js'
|
|
2
|
+
import { uniq } from './uniq.js'
|
|
3
3
|
|
|
4
|
-
export function difference(a, b)
|
|
4
|
+
export function difference(a, b){
|
|
5
5
|
if (arguments.length === 1) return _b => difference(a, _b)
|
|
6
6
|
|
|
7
7
|
return uniq(a).filter(aInstance => !includes(aInstance, b))
|
package/src/dissoc.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export function dissoc(prop, obj)
|
|
1
|
+
export function dissoc(prop, obj){
|
|
2
2
|
if (arguments.length === 1) return _obj => dissoc(prop, _obj)
|
|
3
3
|
|
|
4
4
|
if (obj === null || obj === undefined) return {}
|
|
5
5
|
|
|
6
6
|
const willReturn = {}
|
|
7
|
-
for (const p in obj)
|
|
8
|
-
willReturn[p] = obj[p]
|
|
7
|
+
for (const p in obj){
|
|
8
|
+
willReturn[ p ] = obj[ p ]
|
|
9
9
|
}
|
|
10
|
-
delete willReturn[prop]
|
|
10
|
+
delete willReturn[ prop ]
|
|
11
11
|
|
|
12
12
|
return willReturn
|
|
13
13
|
}
|
package/src/divide.js
CHANGED