rambda 9.4.2 → 10.0.0-alpha.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 +69 -1
- package/README.md +4637 -13433
- package/dist/rambda.esm.js +1487 -0
- package/dist/rambda.js +952 -2113
- package/dist/rambda.umd.js +1595 -1
- package/immutable.d.ts +1066 -1293
- package/index.d.ts +1066 -1293
- package/package.json +95 -94
- package/rambda.js +10 -138
- package/src/_internals/baseSlice.js +5 -7
- package/src/_internals/createPath.js +4 -6
- package/src/_internals/includes.js +8 -4
- package/src/_internals/set.js +11 -11
- package/src/all.js +8 -6
- package/src/allPass.js +4 -4
- package/src/any.js +10 -10
- package/src/anyPass.js +4 -4
- package/src/append.js +4 -6
- package/src/checkObjectWithSpec.js +16 -0
- package/src/complement.js +1 -1
- package/src/concat.js +2 -4
- package/src/count.js +5 -4
- package/src/countBy.js +6 -7
- package/src/defaultTo.js +4 -6
- package/src/drop.js +4 -2
- package/src/dropLast.js +4 -8
- package/src/dropLastWhile.js +17 -26
- package/src/dropWhile.js +14 -22
- package/src/eqBy.js +3 -8
- package/src/eqProps.js +3 -8
- package/src/equals.js +99 -58
- package/src/evolve.js +19 -52
- package/src/excludes.js +5 -0
- package/src/filter.js +10 -40
- package/src/filterObject.js +13 -0
- package/src/find.js +6 -6
- package/src/findIndex.js +5 -5
- package/src/findLast.js +6 -6
- package/src/findLastIndex.js +5 -5
- package/src/flatMap.js +3 -0
- package/src/flatten.js +5 -5
- package/src/groupBy.js +9 -7
- package/src/head.js +5 -3
- package/src/includes.js +10 -7
- package/src/indexOf.js +2 -6
- package/src/init.js +6 -8
- package/src/innerJoin.js +11 -19
- package/src/intersection.js +2 -4
- package/src/intersperse.js +7 -7
- package/src/join.js +2 -4
- package/src/last.js +4 -4
- package/src/lastIndexOf.js +2 -6
- package/src/map.js +9 -49
- package/src/mapAsync.js +11 -0
- package/src/mapObject.js +18 -0
- package/src/mapObjectAsync.js +10 -0
- package/src/match.js +6 -6
- package/src/maxBy.js +2 -8
- package/src/merge.js +4 -1
- package/src/mergeTypes.js +3 -0
- package/src/minBy.js +2 -8
- package/src/modifyPath.js +22 -25
- package/src/none.js +8 -6
- package/src/objOf.js +2 -6
- package/src/omit.js +26 -11
- package/src/partition.js +20 -23
- package/src/path.js +14 -15
- package/src/pick.js +15 -15
- package/src/pipe.js +70 -13
- package/src/pipeAsync.js +10 -0
- package/src/pluck.js +7 -9
- package/src/prepend.js +2 -6
- package/src/prop.js +2 -10
- package/src/propEq.js +8 -10
- package/src/propOr.js +7 -8
- package/src/propSatisfies.js +2 -7
- package/src/range.js +3 -3
- package/src/reduce.js +15 -30
- package/src/reject.js +2 -4
- package/src/replace.js +2 -8
- package/src/replaceItemAtIndex.js +15 -0
- package/src/sort.js +2 -4
- package/src/sortBy.js +3 -3
- package/src/sortWith.js +9 -13
- package/src/split.js +2 -4
- package/src/splitEvery.js +6 -8
- package/src/symmetricDifference.js +5 -8
- package/src/tail.js +2 -2
- package/src/take.js +11 -9
- package/src/takeLast.js +14 -14
- package/src/takeLastWhile.js +19 -20
- package/src/takeWhile.js +12 -21
- package/src/tap.js +3 -3
- package/src/test.js +2 -8
- package/src/tryCatch.js +5 -14
- package/src/type.js +6 -5
- package/src/union.js +10 -8
- package/src/uniq.js +2 -2
- package/src/uniqBy.js +5 -6
- package/src/uniqWith.js +10 -14
- package/src/unless.js +7 -9
- package/src/unwind.js +6 -14
- package/src/update.js +8 -11
- package/src/when.js +7 -9
- package/src/zip.js +8 -8
- package/src/zipWith.js +5 -7
- package/src/F.js +0 -3
- package/src/T.js +0 -3
- package/src/_internals/_arity.js +0 -64
- package/src/_internals/compare.js +0 -3
- package/src/_internals/constants.js +0 -1
- package/src/_internals/createPathInput.js +0 -7
- package/src/_internals/isFalsy.js +0 -13
- package/src/_internals/isInteger.js +0 -10
- package/src/_internals/isIterable.js +0 -5
- package/src/_internals/isObject.js +0 -5
- package/src/_internals/isTruthy.js +0 -13
- package/src/_internals/objectIs.js +0 -9
- package/src/_internals/utils.js +0 -21
- package/src/add.js +0 -5
- package/src/addIndex.js +0 -23
- package/src/addIndexRight.js +0 -9
- package/src/adjust.js +0 -16
- package/src/always.js +0 -3
- package/src/and.js +0 -5
- package/src/ap.js +0 -7
- package/src/aperture.js +0 -15
- package/src/apply.js +0 -7
- package/src/applySpec.js +0 -132
- package/src/applyTo.js +0 -7
- package/src/ascend.js +0 -23
- package/src/assoc.js +0 -11
- package/src/assocPath.js +0 -46
- package/src/binary.js +0 -5
- package/src/bind.js +0 -9
- package/src/both.js +0 -5
- package/src/call.js +0 -1
- package/src/chain.js +0 -7
- package/src/clamp.js +0 -15
- package/src/clone.js +0 -18
- package/src/collectBy.js +0 -27
- package/src/comparator.js +0 -5
- package/src/compose.js +0 -9
- package/src/composeWith.js +0 -33
- package/src/cond.js +0 -14
- package/src/converge.js +0 -18
- package/src/curry.js +0 -7
- package/src/curryN.js +0 -40
- package/src/dec.js +0 -1
- package/src/descend.js +0 -17
- package/src/difference.js +0 -8
- package/src/differenceWith.js +0 -20
- package/src/dissoc.js +0 -13
- package/src/dissocPath.js +0 -47
- package/src/divide.js +0 -5
- package/src/dropRepeats.js +0 -20
- package/src/dropRepeatsBy.js +0 -21
- package/src/dropRepeatsWith.js +0 -28
- package/src/either.js +0 -8
- package/src/empty.js +0 -15
- package/src/endsWith.js +0 -23
- package/src/flip.js +0 -23
- package/src/forEach.js +0 -19
- package/src/forEachObjIndexed.js +0 -24
- package/src/fromPairs.js +0 -6
- package/src/groupWith.js +0 -46
- package/src/gt.js +0 -6
- package/src/gte.js +0 -6
- package/src/has.js +0 -7
- package/src/hasIn.js +0 -9
- package/src/hasPath.js +0 -9
- package/src/identical.js +0 -7
- package/src/identity.js +0 -3
- package/src/ifElse.js +0 -17
- package/src/inc.js +0 -1
- package/src/indexBy.js +0 -29
- package/src/insert.js +0 -11
- package/src/insertAll.js +0 -7
- package/src/is.js +0 -8
- package/src/isEmpty.js +0 -18
- package/src/isNil.js +0 -3
- package/src/isNotEmpty.js +0 -5
- package/src/isNotNil.js +0 -3
- package/src/isPromise.js +0 -5
- package/src/juxt.js +0 -3
- package/src/keys.js +0 -3
- package/src/length.js +0 -8
- package/src/lens.js +0 -7
- package/src/lensIndex.js +0 -7
- package/src/lensPath.js +0 -7
- package/src/lensProp.js +0 -7
- package/src/lt.js +0 -6
- package/src/lte.js +0 -6
- package/src/mathMod.js +0 -8
- package/src/max.js +0 -5
- package/src/maybe.js +0 -13
- package/src/mean.js +0 -5
- package/src/median.js +0 -17
- package/src/mergeAll.js +0 -11
- package/src/mergeDeepLeft.js +0 -5
- package/src/mergeDeepRight.js +0 -24
- package/src/mergeLeft.js +0 -7
- package/src/mergeRight.js +0 -8
- package/src/mergeWith.js +0 -25
- package/src/min.js +0 -5
- package/src/modify.js +0 -23
- package/src/modulo.js +0 -5
- package/src/move.js +0 -19
- package/src/multiply.js +0 -5
- package/src/negate.js +0 -3
- package/src/not.js +0 -3
- package/src/nth.js +0 -9
- package/src/of.js +0 -3
- package/src/on.js +0 -16
- package/src/once.js +0 -24
- package/src/or.js +0 -5
- package/src/over.js +0 -14
- package/src/partial.js +0 -17
- package/src/partialObject.js +0 -5
- package/src/pathEq.js +0 -11
- package/src/pathOr.js +0 -11
- package/src/pathSatisfies.js +0 -9
- package/src/paths.js +0 -9
- package/src/pickAll.js +0 -23
- package/src/pickBy.js +0 -11
- package/src/product.js +0 -4
- package/src/propIs.js +0 -10
- package/src/props.js +0 -13
- package/src/reduceBy.js +0 -29
- package/src/removeIndex.js +0 -7
- package/src/repeat.js +0 -7
- package/src/reverse.js +0 -9
- package/src/set.js +0 -9
- package/src/slice.js +0 -9
- package/src/splitAt.js +0 -21
- package/src/splitWhen.js +0 -25
- package/src/startsWith.js +0 -23
- package/src/subtract.js +0 -5
- package/src/sum.js +0 -3
- package/src/swap.js +0 -42
- package/src/times.js +0 -12
- package/src/toLower.js +0 -3
- package/src/toPairs.js +0 -3
- package/src/toString.js +0 -3
- package/src/toUpper.js +0 -3
- package/src/transpose.js +0 -10
- package/src/trim.js +0 -3
- package/src/unapply.js +0 -5
- package/src/unnest.js +0 -9
- package/src/values.js +0 -6
- package/src/view.js +0 -10
- package/src/where.js +0 -15
- package/src/whereAny.js +0 -12
- package/src/whereEq.js +0 -14
- package/src/without.js +0 -15
- package/src/xor.js +0 -5
- package/src/zipObj.js +0 -13
package/src/path.js
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
import { createPath } from './_internals/createPath.js'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function path(pathInput, obj) {
|
|
4
|
+
if (arguments.length === 1) {
|
|
5
|
+
return _obj => path(pathInput, _obj)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (!obj) {
|
|
9
|
+
return undefined
|
|
10
|
+
}
|
|
4
11
|
let willReturn = obj
|
|
5
12
|
let counter = 0
|
|
6
13
|
|
|
7
14
|
const pathArrValue = createPath(pathInput)
|
|
8
15
|
|
|
9
|
-
while (counter < pathArrValue.length){
|
|
10
|
-
if (willReturn === null || willReturn === undefined){
|
|
16
|
+
while (counter < pathArrValue.length) {
|
|
17
|
+
if (willReturn === null || willReturn === undefined) {
|
|
18
|
+
return undefined
|
|
19
|
+
}
|
|
20
|
+
if (willReturn[pathArrValue[counter]] === null) {
|
|
11
21
|
return undefined
|
|
12
22
|
}
|
|
13
|
-
if (willReturn[ pathArrValue[ counter ] ] === null) return undefined
|
|
14
23
|
|
|
15
|
-
willReturn = willReturn[
|
|
24
|
+
willReturn = willReturn[pathArrValue[counter]]
|
|
16
25
|
counter++
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
return willReturn
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
export function path(pathInput, obj){
|
|
23
|
-
if (arguments.length === 1) return _obj => path(pathInput, _obj)
|
|
24
|
-
|
|
25
|
-
if (obj === null || obj === undefined){
|
|
26
|
-
return undefined
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return pathFn(pathInput, obj)
|
|
30
|
-
}
|
package/src/pick.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { createPath } from './_internals/createPath.js'
|
|
2
2
|
|
|
3
|
-
export function pick(propsToPick
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let counter = 0
|
|
3
|
+
export function pick(propsToPick) {
|
|
4
|
+
return input => {
|
|
5
|
+
if (!input === null) {
|
|
6
|
+
return undefined
|
|
7
|
+
}
|
|
8
|
+
const keys = createPath(propsToPick, ',')
|
|
9
|
+
const willReturn = {}
|
|
10
|
+
let counter = 0
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
while (counter < keys.length) {
|
|
13
|
+
if (keys[counter] in input) {
|
|
14
|
+
willReturn[keys[counter]] = input[keys[counter]]
|
|
15
|
+
}
|
|
16
|
+
counter++
|
|
16
17
|
}
|
|
17
|
-
counter++
|
|
18
|
-
}
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
return willReturn
|
|
20
|
+
}
|
|
21
21
|
}
|
package/src/pipe.js
CHANGED
|
@@ -1,23 +1,80 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { reduceFn } from './reduce.js'
|
|
1
|
+
import { reduce } from './reduce.js'
|
|
3
2
|
|
|
4
|
-
export function
|
|
5
|
-
|
|
3
|
+
export function _arity(n, fn) {
|
|
4
|
+
switch (n) {
|
|
5
|
+
case 0:
|
|
6
|
+
return function () {
|
|
7
|
+
return fn.apply(this, arguments)
|
|
8
|
+
}
|
|
9
|
+
case 1:
|
|
10
|
+
return function (a0) {
|
|
11
|
+
return fn.apply(this, arguments)
|
|
12
|
+
}
|
|
13
|
+
case 2:
|
|
14
|
+
return function (a0, a1) {
|
|
15
|
+
return fn.apply(this, arguments)
|
|
16
|
+
}
|
|
17
|
+
case 3:
|
|
18
|
+
return function (a0, a1, a2) {
|
|
19
|
+
return fn.apply(this, arguments)
|
|
20
|
+
}
|
|
21
|
+
case 4:
|
|
22
|
+
return function (a0, a1, a2, a3) {
|
|
23
|
+
return fn.apply(this, arguments)
|
|
24
|
+
}
|
|
25
|
+
case 5:
|
|
26
|
+
return function (a0, a1, a2, a3, a4) {
|
|
27
|
+
return fn.apply(this, arguments)
|
|
28
|
+
}
|
|
29
|
+
case 6:
|
|
30
|
+
return function (a0, a1, a2, a3, a4, a5) {
|
|
31
|
+
return fn.apply(this, arguments)
|
|
32
|
+
}
|
|
33
|
+
case 7:
|
|
34
|
+
return function (a0, a1, a2, a3, a4, a5, a6) {
|
|
35
|
+
return fn.apply(this, arguments)
|
|
36
|
+
}
|
|
37
|
+
case 8:
|
|
38
|
+
return function (a0, a1, a2, a3, a4, a5, a6, a7) {
|
|
39
|
+
return fn.apply(this, arguments)
|
|
40
|
+
}
|
|
41
|
+
case 9:
|
|
42
|
+
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
|
|
43
|
+
return fn.apply(this, arguments)
|
|
44
|
+
}
|
|
45
|
+
case 10:
|
|
46
|
+
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
|
47
|
+
return fn.apply(this, arguments)
|
|
48
|
+
}
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(
|
|
51
|
+
'First argument to _arity must be a non-negative integer no greater than ten',
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function _pipe(f, g) {
|
|
57
|
+
return function () {
|
|
6
58
|
return g.call(this, f.apply(this, arguments))
|
|
7
59
|
}
|
|
8
60
|
}
|
|
9
61
|
|
|
10
|
-
|
|
11
|
-
if (arguments.length === 0){
|
|
62
|
+
function pipeFn() {
|
|
63
|
+
if (arguments.length === 0) {
|
|
12
64
|
throw new Error('pipe requires at least one argument')
|
|
13
65
|
}
|
|
14
66
|
|
|
15
|
-
return _arity(
|
|
16
|
-
|
|
67
|
+
return _arity(
|
|
68
|
+
arguments[0].length,
|
|
69
|
+
reduce(
|
|
17
70
|
_pipe,
|
|
18
|
-
arguments[
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
71
|
+
arguments[0],
|
|
72
|
+
)(Array.prototype.slice.call(arguments, 1, Number.POSITIVE_INFINITY)),
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function pipe(...inputs) {
|
|
77
|
+
const [input, ...fnList] = inputs
|
|
78
|
+
|
|
79
|
+
return pipeFn(...fnList)(input)
|
|
23
80
|
}
|
package/src/pipeAsync.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type } from './type.js'
|
|
2
|
+
|
|
3
|
+
export async function pipeAsync(input, ...fnList) {
|
|
4
|
+
let willReturn = input
|
|
5
|
+
for (const fn of fnList) {
|
|
6
|
+
const initialResult = fn(willReturn)
|
|
7
|
+
willReturn = type(initialResult) === 'Promise' ? await initialResult : initialResult
|
|
8
|
+
}
|
|
9
|
+
return willReturn
|
|
10
|
+
}
|
package/src/pluck.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function pluck(property, list){
|
|
4
|
-
if (arguments.length === 1) return _list => pluck(property, _list)
|
|
5
|
-
|
|
1
|
+
export function pluck(property) {
|
|
2
|
+
return list => {
|
|
6
3
|
const willReturn = []
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
if (x[
|
|
10
|
-
willReturn.push(x[
|
|
5
|
+
list.forEach(x => {
|
|
6
|
+
if (x[property] !== undefined) {
|
|
7
|
+
willReturn.push(x[property])
|
|
11
8
|
}
|
|
12
|
-
}
|
|
9
|
+
})
|
|
13
10
|
|
|
14
11
|
return willReturn
|
|
15
12
|
}
|
|
13
|
+
}
|
package/src/prepend.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export function prepend(x
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (typeof input === 'string') return [ x ].concat(input.split(''))
|
|
5
|
-
|
|
6
|
-
return [ x ].concat(input)
|
|
1
|
+
export function prepend(x) {
|
|
2
|
+
return list=> [x].concat(list)
|
|
7
3
|
}
|
package/src/prop.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
export function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return obj[ searchProperty ]
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function prop(searchProperty, obj){
|
|
8
|
-
if (arguments.length === 1) return _obj => prop(searchProperty, _obj)
|
|
9
|
-
|
|
10
|
-
return propFn(searchProperty, obj)
|
|
1
|
+
export function prop(searchProperty) {
|
|
2
|
+
return obj => (obj ? obj[searchProperty] : undefined)
|
|
11
3
|
}
|
package/src/propEq.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { equals } from './equals.js'
|
|
3
|
-
import { prop } from './prop.js'
|
|
1
|
+
import { equalsFn } from './equals.js'
|
|
4
2
|
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
){
|
|
8
|
-
|
|
3
|
+
export function propEq(valueToMatch, propToFind) {
|
|
4
|
+
return obj => {
|
|
5
|
+
if (!obj) {
|
|
6
|
+
return false
|
|
7
|
+
}
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
return equalsFn(valueToMatch, obj[propToFind])
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
export const propEq = curry(propEqFn)
|
package/src/propOr.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { curry } from './curry.js'
|
|
2
1
|
import { defaultTo } from './defaultTo.js'
|
|
3
2
|
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
){
|
|
7
|
-
|
|
3
|
+
export function propOr(defaultValue, property) {
|
|
4
|
+
return obj => {
|
|
5
|
+
if (!obj) {
|
|
6
|
+
return defaultValue
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
return defaultTo(defaultValue, obj[property])
|
|
10
|
+
}
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
export const propOr = curry(propOrFn)
|
package/src/propSatisfies.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { curry } from './curry.js'
|
|
2
1
|
import { prop } from './prop.js'
|
|
3
2
|
|
|
4
|
-
function
|
|
5
|
-
predicate
|
|
6
|
-
){
|
|
7
|
-
return predicate(prop(property, obj))
|
|
3
|
+
export function propSatisfies(predicate, property) {
|
|
4
|
+
return obj => predicate(prop(property, obj))
|
|
8
5
|
}
|
|
9
|
-
|
|
10
|
-
export const propSatisfies = curry(propSatisfiesFn)
|
package/src/range.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export function range(start
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export function range(start){
|
|
2
|
+
return end => {
|
|
4
3
|
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))){
|
|
5
4
|
throw new TypeError('Both arguments to range must be numbers')
|
|
6
5
|
}
|
|
@@ -16,3 +15,4 @@ export function range(start, end){
|
|
|
16
15
|
|
|
17
16
|
return willReturn
|
|
18
17
|
}
|
|
18
|
+
}
|
package/src/reduce.js
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
import { isArray } from './_internals/isArray.js'
|
|
2
|
-
import { curry } from './curry.js'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return acc
|
|
15
|
-
}
|
|
16
|
-
if (!isArray(list)){
|
|
17
|
-
throw new TypeError('reduce: list must be array or iterable')
|
|
18
|
-
}
|
|
19
|
-
let index = 0
|
|
20
|
-
const len = list.length
|
|
3
|
+
export function reduce(reducer, acc) {
|
|
4
|
+
return list => {
|
|
5
|
+
if (list == null) {
|
|
6
|
+
return acc
|
|
7
|
+
}
|
|
8
|
+
if (!isArray(list)) {
|
|
9
|
+
throw new TypeError('reduce: list must be array or iterable')
|
|
10
|
+
}
|
|
11
|
+
let index = 0
|
|
12
|
+
const len = list.length
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
)
|
|
26
|
-
if (acc instanceof ReduceStopper){
|
|
27
|
-
return acc.value
|
|
14
|
+
while (index < len) {
|
|
15
|
+
acc = reducer(acc, list[index], index, list)
|
|
16
|
+
index++
|
|
28
17
|
}
|
|
29
|
-
index++
|
|
30
|
-
}
|
|
31
18
|
|
|
32
|
-
|
|
19
|
+
return acc
|
|
20
|
+
}
|
|
33
21
|
}
|
|
34
|
-
|
|
35
|
-
export const reduce = curry(reduceFn)
|
|
36
|
-
export const reduceStopper = value => new ReduceStopper(value)
|
package/src/reject.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { filter } from './filter.js'
|
|
2
2
|
|
|
3
|
-
export function reject(predicate
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return filter(x => !predicate(x), list)
|
|
3
|
+
export function reject(predicate) {
|
|
4
|
+
return list => filter(x => !predicate(x), list)
|
|
7
5
|
}
|
package/src/replace.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function replaceFn(
|
|
4
|
-
pattern, replacer, str
|
|
5
|
-
){
|
|
6
|
-
return str.replace(pattern, replacer)
|
|
1
|
+
export function replace(pattern, replacer) {
|
|
2
|
+
return str => str.replace(pattern, replacer)
|
|
7
3
|
}
|
|
8
|
-
|
|
9
|
-
export const replace = curry(replaceFn)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { cloneList } from './_internals/cloneList.js'
|
|
2
|
+
|
|
3
|
+
export function replaceItemAtIndex(index, replaceFn) {
|
|
4
|
+
return list => {
|
|
5
|
+
const actualIndex = index < 0 ? list.length + index : index
|
|
6
|
+
if (index >= list.length || actualIndex < 0) {
|
|
7
|
+
return list
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const clone = cloneList(list)
|
|
11
|
+
clone[actualIndex] = replaceFn(clone[actualIndex])
|
|
12
|
+
|
|
13
|
+
return clone
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/sort.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { cloneList } from './_internals/cloneList.js'
|
|
2
2
|
|
|
3
|
-
export function sort(sortFn
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return cloneList(list).sort(sortFn)
|
|
3
|
+
export function sort(sortFn){
|
|
4
|
+
return list => cloneList(list).sort(sortFn)
|
|
7
5
|
}
|
package/src/sortBy.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { cloneList } from './_internals/cloneList.js'
|
|
2
2
|
|
|
3
|
-
export function sortBy(sortFn
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export function sortBy(sortFn){
|
|
4
|
+
return list => {
|
|
6
5
|
const clone = cloneList(list)
|
|
7
6
|
|
|
8
7
|
return clone.sort((a, b) => {
|
|
@@ -14,3 +13,4 @@ export function sortBy(sortFn, list){
|
|
|
14
13
|
return aSortResult < bSortResult ? -1 : 1
|
|
15
14
|
})
|
|
16
15
|
}
|
|
16
|
+
}
|
package/src/sortWith.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
function sortHelper(
|
|
2
|
-
a, b, listOfSortingFns
|
|
3
|
-
){
|
|
1
|
+
function sortHelper(a, b, listOfSortingFns) {
|
|
4
2
|
let result = 0
|
|
5
3
|
let i = 0
|
|
6
|
-
while (result === 0 && i < listOfSortingFns.length){
|
|
7
|
-
result = listOfSortingFns[
|
|
4
|
+
while (result === 0 && i < listOfSortingFns.length) {
|
|
5
|
+
result = listOfSortingFns[i](a, b)
|
|
8
6
|
i += 1
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
return result
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
export function sortWith(listOfSortingFns
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (Array.isArray(list) === false)
|
|
12
|
+
export function sortWith(listOfSortingFns) {
|
|
13
|
+
return list => {
|
|
14
|
+
if (Array.isArray(list) === false) {
|
|
19
15
|
return []
|
|
16
|
+
}
|
|
20
17
|
|
|
21
18
|
const clone = list.slice()
|
|
22
|
-
clone.sort((a, b) => sortHelper(
|
|
23
|
-
a, b, listOfSortingFns
|
|
24
|
-
))
|
|
19
|
+
clone.sort((a, b) => sortHelper(a, b, listOfSortingFns))
|
|
25
20
|
|
|
26
21
|
return clone
|
|
27
22
|
}
|
|
23
|
+
}
|
package/src/split.js
CHANGED
package/src/splitEvery.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
export function splitEvery(sliceLength
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if (sliceLength < 1){
|
|
1
|
+
export function splitEvery(sliceLength) {
|
|
2
|
+
return list => {
|
|
3
|
+
if (sliceLength < 1) {
|
|
7
4
|
throw new Error('First argument to splitEvery must be a positive integer')
|
|
8
5
|
}
|
|
9
6
|
|
|
10
7
|
const willReturn = []
|
|
11
8
|
let counter = 0
|
|
12
9
|
|
|
13
|
-
while (counter <
|
|
14
|
-
willReturn.push(
|
|
10
|
+
while (counter < list.length) {
|
|
11
|
+
willReturn.push(list.slice(counter, (counter += sliceLength)))
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
return willReturn
|
|
18
15
|
}
|
|
16
|
+
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { concat } from './concat.js'
|
|
2
1
|
import { filter } from './filter.js'
|
|
3
2
|
import { includes } from './includes.js'
|
|
4
3
|
|
|
5
|
-
export function symmetricDifference(x
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return concat(filter(value => !includes(value, y), x),
|
|
11
|
-
filter(value => !includes(value, x), y))
|
|
4
|
+
export function symmetricDifference(x) {
|
|
5
|
+
return y => [
|
|
6
|
+
...filter(value => !includes(value)(y))(x),
|
|
7
|
+
...filter(value => !includes(value)(x))(y),
|
|
8
|
+
]
|
|
12
9
|
}
|
package/src/tail.js
CHANGED
package/src/take.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import baseSlice from './_internals/baseSlice.js'
|
|
1
|
+
import { baseSlice } from './_internals/baseSlice.js'
|
|
2
2
|
|
|
3
|
-
export function take(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export function take(numberOfItems) {
|
|
4
|
+
return input => {
|
|
5
|
+
if (numberOfItems < 0) {
|
|
6
|
+
return input.slice()
|
|
7
|
+
}
|
|
8
|
+
if (typeof input === 'string') {
|
|
9
|
+
return input.slice(0, numberOfItems)
|
|
10
|
+
}
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
12
|
+
return baseSlice(input, 0, numberOfItems)
|
|
13
|
+
}
|
|
12
14
|
}
|
package/src/takeLast.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import baseSlice from './_internals/baseSlice.js'
|
|
1
|
+
import { baseSlice } from './_internals/baseSlice.js'
|
|
2
2
|
|
|
3
|
-
export function takeLast(
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export function takeLast(numberOfItems) {
|
|
4
|
+
return input => {
|
|
5
|
+
const len = input.length
|
|
6
|
+
if (numberOfItems < 0) {
|
|
7
|
+
return input.slice()
|
|
8
|
+
}
|
|
9
|
+
let numValue = numberOfItems > len ? len : numberOfItems
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
if (typeof input === 'string') {
|
|
12
|
+
return input.slice(len - numValue)
|
|
13
|
+
}
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
return listOrString.slice(len - numValue)
|
|
15
|
+
numValue = len - numValue
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return baseSlice(
|
|
17
|
-
listOrString, numValue, len
|
|
18
|
-
)
|
|
17
|
+
return baseSlice(input, numValue, len)
|
|
18
|
+
}
|
|
19
19
|
}
|
package/src/takeLastWhile.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return isArray(input) ? toReturn.reverse() : toReturn.reverse().join('')
|
|
1
|
+
export function takeLastWhile(predicate) {
|
|
2
|
+
return input => {
|
|
3
|
+
if (input.length === 0) {
|
|
4
|
+
return input
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const toReturn = []
|
|
8
|
+
let counter = input.length
|
|
9
|
+
|
|
10
|
+
while (counter) {
|
|
11
|
+
const item = input[--counter]
|
|
12
|
+
if (!predicate(item)) {
|
|
13
|
+
break
|
|
14
|
+
}
|
|
15
|
+
toReturn.push(item)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return toReturn.reverse()
|
|
19
|
+
}
|
|
21
20
|
}
|