rambda 10.0.0-alpha.0 → 10.0.0-beta.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 +124 -16
- package/README.md +5526 -1730
- package/dist/{rambda.esm.js → rambda.cjs} +663 -355
- package/dist/rambda.js +545 -456
- package/dist/rambda.umd.js +563 -357
- package/immutable.d.ts +321 -343
- package/index.d.ts +321 -343
- package/package.json +20 -13
- package/rambda.js +16 -1
- package/src/addProp.js +3 -0
- package/src/append.js +5 -5
- package/src/ascend.js +16 -0
- package/src/compact.js +12 -0
- package/src/concat.js +1 -1
- package/src/count.js +7 -7
- package/src/countBy.js +12 -12
- package/src/createObjectFromKeys.js +10 -0
- package/src/descend.js +10 -0
- package/src/dropLast.js +1 -3
- package/src/eqProps.js +1 -2
- package/src/equals.js +2 -2
- package/src/evolve.js +2 -23
- package/src/filter.js +14 -14
- package/src/find.js +10 -10
- package/src/findIndex.js +9 -9
- package/src/findLast.js +8 -8
- package/src/findLastIndex.js +8 -8
- package/src/findNth.js +16 -0
- package/src/groupBy.js +14 -13
- package/src/includes.js +12 -13
- package/src/interpolate.js +29 -0
- package/src/intersection.js +1 -1
- package/src/intersperse.js +12 -12
- package/src/join.js +1 -1
- package/src/mapAsync.js +3 -3
- package/src/mapKeys.js +11 -0
- package/src/mapObjectAsync.js +9 -9
- package/src/mapParallelAsync.js +3 -0
- package/src/match.js +5 -5
- package/src/modifyProp.js +20 -0
- package/src/objectIncludes.js +12 -0
- package/src/partition.js +13 -37
- package/src/partitionObject.js +15 -0
- package/src/permutations.js +40 -0
- package/src/pipeAsync.js +7 -6
- package/src/pluck.js +9 -9
- package/src/prepend.js +1 -1
- package/src/propSatisfies.js +1 -3
- package/src/range.js +35 -12
- package/src/reject.js +1 -1
- package/src/rejectObject.js +13 -0
- package/src/shuffle.js +13 -0
- package/src/sort.js +1 -1
- package/src/sortBy.js +12 -10
- package/src/sortObject.js +15 -0
- package/src/sortWith.js +8 -8
- package/src/split.js +2 -2
- package/src/splitEvery.js +11 -11
- package/src/takeLastWhile.js +18 -18
- package/src/tap.js +4 -4
- package/src/test.js +1 -1
- package/src/uniqBy.js +4 -4
- package/src/uniqWith.js +10 -10
- package/src/modifyPath.js +0 -30
package/src/mapKeys.js
ADDED
package/src/mapObjectAsync.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export function mapObjectAsync(fn) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
2
|
+
return async obj => {
|
|
3
|
+
const willReturn = {}
|
|
4
|
+
for (const prop in obj) {
|
|
5
|
+
willReturn[prop] = await fn(obj[prop], prop)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return willReturn
|
|
9
|
+
}
|
|
10
|
+
}
|
package/src/match.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function match(pattern) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
return input => {
|
|
3
|
+
const willReturn = input.match(pattern)
|
|
4
|
+
|
|
5
|
+
return willReturn === null ? [] : willReturn
|
|
6
|
+
}
|
|
7
7
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isArray } from './_internals/isArray.js'
|
|
2
|
+
import { update } from './update.js'
|
|
3
|
+
|
|
4
|
+
function modifyFn(property, fn, list) {
|
|
5
|
+
if (list[property] === undefined) {
|
|
6
|
+
return list
|
|
7
|
+
}
|
|
8
|
+
if (isArray(list)) {
|
|
9
|
+
return update(property, fn(list[property]))(list)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
...list,
|
|
14
|
+
[property]: fn(list[property]),
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function modifyProp(property, fn) {
|
|
19
|
+
return obj => modifyFn(property, fn, obj)
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { equals } from './equals.js'
|
|
2
|
+
import { filterObject } from './filterObject.js'
|
|
3
|
+
|
|
4
|
+
export function objectIncludes(condition) {
|
|
5
|
+
return obj => {
|
|
6
|
+
const result = filterObject((conditionValue, conditionProp) =>
|
|
7
|
+
equals(conditionValue)(obj[conditionProp]),
|
|
8
|
+
)(condition)
|
|
9
|
+
|
|
10
|
+
return Object.keys(result).length === Object.keys(condition).length
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/partition.js
CHANGED
|
@@ -1,41 +1,17 @@
|
|
|
1
|
-
import { isArray } from './_internals/isArray.js'
|
|
2
|
-
|
|
3
|
-
export function partitionObject(predicate, iterable) {
|
|
4
|
-
const yes = {}
|
|
5
|
-
const no = {}
|
|
6
|
-
Object.entries(iterable).forEach(([prop, value]) => {
|
|
7
|
-
if (predicate(value, prop)) {
|
|
8
|
-
yes[prop] = value
|
|
9
|
-
} else {
|
|
10
|
-
no[prop] = value
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
return [yes, no]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function partitionArray(predicate, list, indexed = false) {
|
|
18
|
-
const yes = []
|
|
19
|
-
const no = []
|
|
20
|
-
let counter = -1
|
|
21
|
-
|
|
22
|
-
while (counter++ < list.length - 1) {
|
|
23
|
-
if (indexed ? predicate(list[counter], counter) : predicate(list[counter])) {
|
|
24
|
-
yes.push(list[counter])
|
|
25
|
-
} else {
|
|
26
|
-
no.push(list[counter])
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return [yes, no]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
1
|
export function partition(predicate) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
const yes = []
|
|
4
|
+
const no = []
|
|
5
|
+
let counter = -1
|
|
6
|
+
|
|
7
|
+
while (counter++ < list.length - 1) {
|
|
8
|
+
if (predicate(list[counter], counter)) {
|
|
9
|
+
yes.push(list[counter])
|
|
10
|
+
} else {
|
|
11
|
+
no.push(list[counter])
|
|
12
|
+
}
|
|
37
13
|
}
|
|
38
14
|
|
|
39
|
-
return
|
|
40
|
-
|
|
15
|
+
return [yes, no]
|
|
16
|
+
}
|
|
41
17
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function partitionObject(predicate) {
|
|
2
|
+
return obj => {
|
|
3
|
+
const yes = {}
|
|
4
|
+
const no = {}
|
|
5
|
+
Object.entries(obj).forEach(([prop, value]) => {
|
|
6
|
+
if (predicate(value, prop)) {
|
|
7
|
+
yes[prop] = value
|
|
8
|
+
} else {
|
|
9
|
+
no[prop] = value
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return [yes, no]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { cloneList } from './_internals/cloneList.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Source:
|
|
5
|
+
* https://github.com/denoland/std/blob/main/collections/permutations.ts
|
|
6
|
+
*/
|
|
7
|
+
export function permutations(inputArray) {
|
|
8
|
+
const result = [];
|
|
9
|
+
const array = cloneList(inputArray);
|
|
10
|
+
const k = array.length;
|
|
11
|
+
if (k === 0) {
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const c = new Array(k).fill(0);
|
|
16
|
+
|
|
17
|
+
result.push([...array]);
|
|
18
|
+
|
|
19
|
+
let i = 1;
|
|
20
|
+
|
|
21
|
+
while (i < k) {
|
|
22
|
+
if (c[i] < i) {
|
|
23
|
+
if (i % 2 === 0) {
|
|
24
|
+
[array[0], array[i]] = [array[i], array[0]]
|
|
25
|
+
} else {
|
|
26
|
+
[array[c[i]], array[i]] = [array[i], array[c[i]]]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
result.push([...array]);
|
|
30
|
+
|
|
31
|
+
c[i] += 1;
|
|
32
|
+
i = 1;
|
|
33
|
+
} else {
|
|
34
|
+
c[i] = 0;
|
|
35
|
+
i += 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}
|
package/src/pipeAsync.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type } from './type.js'
|
|
2
2
|
|
|
3
3
|
export async function pipeAsync(input, ...fnList) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
let willReturn = input
|
|
5
|
+
for (const fn of fnList) {
|
|
6
|
+
const initialResult = fn(willReturn)
|
|
7
|
+
willReturn =
|
|
8
|
+
type(initialResult) === 'Promise' ? await initialResult : initialResult
|
|
9
|
+
}
|
|
10
|
+
return willReturn
|
|
10
11
|
}
|
package/src/pluck.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export function pluck(property) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
const willReturn = []
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
list.forEach(x => {
|
|
6
|
+
if (x[property] !== undefined) {
|
|
7
|
+
willReturn.push(x[property])
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
}
|
|
11
|
+
return willReturn
|
|
12
|
+
}
|
|
13
13
|
}
|
package/src/prepend.js
CHANGED
package/src/propSatisfies.js
CHANGED
package/src/range.js
CHANGED
|
@@ -1,18 +1,41 @@
|
|
|
1
|
-
export function range(start){
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export function range(start) {
|
|
2
|
+
return end => {
|
|
3
|
+
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
4
|
+
throw new TypeError('Both arguments to range must be numbers')
|
|
5
|
+
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
if (end <= start) {
|
|
8
|
+
return []
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
const len = end - start
|
|
12
|
+
const willReturn = Array(len)
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
for (let i = 0; i < len + 1; i++) {
|
|
15
|
+
willReturn[i] = start + i
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
return willReturn
|
|
19
|
+
}
|
|
17
20
|
}
|
|
21
|
+
|
|
22
|
+
export function rangeDescending(start) {
|
|
23
|
+
return end => {
|
|
24
|
+
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
25
|
+
throw new TypeError('Both arguments to range must be numbers')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (end >= start) {
|
|
29
|
+
return []
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const len = start - end
|
|
33
|
+
const willReturn = Array(len)
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < len + 1; i++) {
|
|
36
|
+
willReturn[i] = start - i
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return willReturn
|
|
40
|
+
}
|
|
18
41
|
}
|
package/src/reject.js
CHANGED
package/src/shuffle.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function shuffle(listInput) {
|
|
2
|
+
const list = cloneList(listInput)
|
|
3
|
+
let counter = list.length
|
|
4
|
+
while (counter > 0) {
|
|
5
|
+
const index = Math.floor(Math.random() * counter)
|
|
6
|
+
counter--
|
|
7
|
+
const temp = list[counter]
|
|
8
|
+
list[counter] = list[index]
|
|
9
|
+
list[index] = temp
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return list
|
|
13
|
+
}
|
package/src/sort.js
CHANGED
package/src/sortBy.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
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 => {
|
|
5
|
+
const clone = cloneList(list)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
return clone.sort((a, b) => {
|
|
8
|
+
const aSortResult = sortFn(a)
|
|
9
|
+
const bSortResult = sortFn(b)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
if (aSortResult === bSortResult) {
|
|
12
|
+
return 0
|
|
13
|
+
}
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
15
|
+
return aSortResult < bSortResult ? -1 : 1
|
|
16
|
+
})
|
|
17
|
+
}
|
|
16
18
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sort } from './sort.js'
|
|
2
|
+
|
|
3
|
+
export function sortObject(predicate) {
|
|
4
|
+
return obj => {
|
|
5
|
+
const keys = Object.keys(obj)
|
|
6
|
+
const sortedKeys = sort((a, b) => predicate(a, b, obj[a], obj[b]))(keys)
|
|
7
|
+
|
|
8
|
+
const toReturn = {}
|
|
9
|
+
sortedKeys.forEach(singleKey => {
|
|
10
|
+
toReturn[singleKey] = obj[singleKey]
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return toReturn
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/sortWith.js
CHANGED
|
@@ -10,14 +10,14 @@ function sortHelper(a, b, listOfSortingFns) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function sortWith(listOfSortingFns) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
return list => {
|
|
14
|
+
if (Array.isArray(list) === false) {
|
|
15
|
+
return []
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const clone = list.slice()
|
|
19
|
+
clone.sort((a, b) => sortHelper(a, b, listOfSortingFns))
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
}
|
|
21
|
+
return clone
|
|
22
|
+
}
|
|
23
23
|
}
|
package/src/split.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function split(separator){
|
|
2
|
-
|
|
1
|
+
export function split(separator) {
|
|
2
|
+
return str => str.split(separator)
|
|
3
3
|
}
|
package/src/splitEvery.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export function splitEvery(sliceLength) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
if (sliceLength < 1) {
|
|
4
|
+
throw new Error('First argument to splitEvery must be a positive integer')
|
|
5
|
+
}
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const willReturn = []
|
|
8
|
+
let counter = 0
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
while (counter < list.length) {
|
|
11
|
+
willReturn.push(list.slice(counter, (counter += sliceLength)))
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
}
|
|
14
|
+
return willReturn
|
|
15
|
+
}
|
|
16
16
|
}
|
package/src/takeLastWhile.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export function takeLastWhile(predicate) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
}
|
|
20
20
|
}
|
package/src/tap.js
CHANGED
package/src/test.js
CHANGED
package/src/uniqBy.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { _Set } from '../src/_internals/set.js'
|
|
2
2
|
|
|
3
3
|
export function uniqBy(fn) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
return list => {
|
|
5
|
+
const set = new _Set()
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
return list.filter(item => set.checkUniqueness(fn(item)))
|
|
8
|
+
}
|
|
9
9
|
}
|
package/src/uniqWith.js
CHANGED
|
@@ -14,18 +14,18 @@ function includesWith(predicate, target, list) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function uniqWith(predicate) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
return list => {
|
|
18
|
+
let index = -1
|
|
19
|
+
const willReturn = []
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
while (++index < list.length) {
|
|
22
|
+
const value = list[index]
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
if (!includesWith(predicate, value, willReturn)) {
|
|
25
|
+
willReturn.push(value)
|
|
26
|
+
}
|
|
26
27
|
}
|
|
27
|
-
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
}
|
|
29
|
+
return willReturn
|
|
30
|
+
}
|
|
31
31
|
}
|
package/src/modifyPath.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createPath } from './_internals/createPath.js'
|
|
2
|
-
import { path as pathModule } from './path.js'
|
|
3
|
-
|
|
4
|
-
function assoc(prop, newValue) {
|
|
5
|
-
return obj => Object.assign({}, obj, { [prop]: newValue })
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function modifyPathFn(pathInput, fn, obj) {
|
|
9
|
-
const path = createPath(pathInput)
|
|
10
|
-
if (path.length === 1) {
|
|
11
|
-
return {
|
|
12
|
-
...obj,
|
|
13
|
-
[path[0]]: fn(obj[path[0]]),
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (pathModule(path)(obj) === undefined) {
|
|
17
|
-
return obj
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const val = modifyPathFn(Array.prototype.slice.call(path, 1), fn, obj[path[0]])
|
|
21
|
-
if (val === obj[path[0]]) {
|
|
22
|
-
return obj
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return assoc(path[0], val)(obj)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function modifyPath(pathInput, fn) {
|
|
29
|
-
return obj => modifyPathFn(pathInput, fn, obj)
|
|
30
|
-
}
|