rambda 10.3.3 → 11.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 +36 -0
- package/README.md +865 -389
- package/dist/rambda.cjs +175 -150
- package/dist/rambda.js +171 -150
- package/dist/rambda.umd.js +175 -150
- package/index.d.cts +60 -31
- package/index.d.ts +60 -31
- package/package.json +9 -8
- package/rambda.js +5 -1
- package/src/difference.js +9 -0
- package/src/exists.js +7 -0
- package/src/{innerJoin.js → intersectionWith.js} +1 -1
- package/src/mapParallelAsync.js +12 -2
- package/src/range.js +7 -32
- package/src/rangeDescending.js +8 -0
- package/src/unionWith.js +11 -0
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ const result = pipe(
|
|
|
21
21
|
//=> [6, 8]
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
You can test this example in <a href="https://rambda.
|
|
24
|
+
You can test this example in <a href="https://rambda.netlify.app/?const%20result%20%3D%20R.pipe(%0A%20%20%5B1%2C%202%2C%203%2C%204%5D%2C%0A%20%20R.filter(x%20%3D%3E%20x%20%3E%202)%2C%0A%20%20R.map(x%20%3D%3E%20x%20*%202)%2C%0A)%0A%2F%2F%20%3D%3E%20%5B6%2C%208%5D">Rambda's REPL</a>
|
|
25
25
|
|
|
26
26
|
* [API](#api)
|
|
27
27
|
* [Changelog](#-changelog)
|
|
@@ -183,7 +183,7 @@ const result = R.pipe(
|
|
|
183
183
|
// => { a: 1, b: 'foo', c: 3 }
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
186
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pipe(%0A%09%7B%20a%3A%201%2C%20b%3A%20'foo'%20%7D%2C%0A%09R.addProp('c'%2C%203)%0A)%0A%2F%2F%20%3D%3E%20%7B%20a%3A%201%2C%20b%3A%20'foo'%2C%20c%3A%203%20%7D">Try this <strong>R.addProp</strong> example in Rambda REPL</a>
|
|
187
187
|
|
|
188
188
|
<details>
|
|
189
189
|
|
|
@@ -278,7 +278,7 @@ const result = R.pipe(
|
|
|
278
278
|
// => [{a: 1, b: 2, c: '3'}, {a: 3, b: 4, c: '7'}]
|
|
279
279
|
```
|
|
280
280
|
|
|
281
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
281
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pipe(%0A%09%5B%0A%09%09%7Ba%3A%201%2C%20b%3A%202%7D%2C%0A%09%09%7Ba%3A%203%2C%20b%3A%204%7D%2C%0A%09%5D%2C%0A%09R.addPropToObjects(%0A%09%09'c'%2C%0A%09%09(x)%20%3D%3E%20String(x.a%20%2B%20x.b)%2C%0A%09)%0A)%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A%201%2C%20b%3A%202%2C%20c%3A%20'3'%7D%2C%20%7Ba%3A%203%2C%20b%3A%204%2C%20c%3A%20'7'%7D%5D">Try this <strong>R.addPropToObjects</strong> example in Rambda REPL</a>
|
|
282
282
|
|
|
283
283
|
<details>
|
|
284
284
|
|
|
@@ -393,7 +393,7 @@ const result = R.pipe(
|
|
|
393
393
|
) // => true
|
|
394
394
|
```
|
|
395
395
|
|
|
396
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
396
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%200%2C%201%2C%202%2C%203%2C%204%20%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%20-1%0A%0Aconst%20result%20%3D%20R.pipe(%0A%09list%2C%0A%09R.all(predicate)%0A)%20%2F%2F%20%3D%3E%20true">Try this <strong>R.all</strong> example in Rambda REPL</a>
|
|
397
397
|
|
|
398
398
|
<details>
|
|
399
399
|
|
|
@@ -491,7 +491,7 @@ const result = R.pipe(
|
|
|
491
491
|
) // => [[1, 2, 3, 4]]
|
|
492
492
|
```
|
|
493
493
|
|
|
494
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
494
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%5B1%2C%202%2C%203%2C%204%5D%2C%20%5B3%2C%204%2C%205%5D%5D%0Aconst%20result%20%3D%20R.pipe(%0A%09list%2C%0A%09R.filter(R.allPass(%5BR.includes(2)%2C%20R.includes(3)%5D))%0A)%20%2F%2F%20%3D%3E%20%5B%5B1%2C%202%2C%203%2C%204%5D%5D">Try this <strong>R.allPass</strong> example in Rambda REPL</a>
|
|
495
495
|
|
|
496
496
|
<details>
|
|
497
497
|
|
|
@@ -565,7 +565,10 @@ describe('allPass', () => {
|
|
|
565
565
|
[1, 2, 3, 4],
|
|
566
566
|
[3, 4, 5],
|
|
567
567
|
]
|
|
568
|
-
const result = R.pipe(list, R.map(R.allPass([
|
|
568
|
+
const result = R.pipe(list, R.map(R.allPass([
|
|
569
|
+
(x) => x.length > 2,
|
|
570
|
+
(x) => x.includes(3)
|
|
571
|
+
])))
|
|
569
572
|
result // $ExpectType boolean[]
|
|
570
573
|
})
|
|
571
574
|
})
|
|
@@ -591,7 +594,7 @@ R.any(predicate)(list)
|
|
|
591
594
|
// => true
|
|
592
595
|
```
|
|
593
596
|
|
|
594
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
597
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20*%20x%20%3E%208%0Aconst%20result%20%3D%20R.any(predicate)(list)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.any</strong> example in Rambda REPL</a>
|
|
595
598
|
|
|
596
599
|
<details>
|
|
597
600
|
|
|
@@ -688,7 +691,7 @@ const result = fn(input)
|
|
|
688
691
|
// => true
|
|
689
692
|
```
|
|
690
693
|
|
|
691
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
694
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20isBig%20%3D%20x%20%3D%3E%20x%20%3E%2020%0Aconst%20isOdd%20%3D%20x%20%3D%3E%20x%20%25%202%20%3D%3D%3D%201%0Aconst%20input%20%3D%2011%0A%0Aconst%20fn%20%3D%20R.anyPass(%0A%20%20%5BisBig%2C%20isOdd%5D%0A)%0A%0Aconst%20result%20%3D%20fn(input)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.anyPass</strong> example in Rambda REPL</a>
|
|
692
695
|
|
|
693
696
|
<details>
|
|
694
697
|
|
|
@@ -828,7 +831,7 @@ describe('anyPass', () => {
|
|
|
828
831
|
|
|
829
832
|
```typescript
|
|
830
833
|
|
|
831
|
-
append<T>(el: T): (list: T[]) => T[]
|
|
834
|
+
append<T>(el: T): (list: readonly T[]) => T[]
|
|
832
835
|
```
|
|
833
836
|
|
|
834
837
|
It adds element `x` at the end of `iterable`.
|
|
@@ -838,15 +841,15 @@ const result = R.append('foo')(['bar', 'baz'])
|
|
|
838
841
|
// => ['bar', 'baz', 'foo']
|
|
839
842
|
```
|
|
840
843
|
|
|
841
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
844
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.append('foo')(%5B'bar'%2C%20'baz'%5D)%0A%2F%2F%20%3D%3E%20%5B'bar'%2C%20'baz'%2C%20'foo'%5D">Try this <strong>R.append</strong> example in Rambda REPL</a>
|
|
842
845
|
|
|
843
846
|
<details>
|
|
844
847
|
|
|
845
848
|
<summary>All TypeScript definitions</summary>
|
|
846
849
|
|
|
847
850
|
```typescript
|
|
848
|
-
append<T>(el: T): (list: T[]) => T[];
|
|
849
851
|
append<T>(el: T): (list: readonly T[]) => T[];
|
|
852
|
+
append<T>(el: T): (list: T[]) => T[];
|
|
850
853
|
```
|
|
851
854
|
|
|
852
855
|
</details>
|
|
@@ -930,7 +933,7 @@ const result = R.pipe(
|
|
|
930
933
|
// => [{a: 0}, {a: 1}, {a: 2}]
|
|
931
934
|
```
|
|
932
935
|
|
|
933
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
936
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pipe(%0A%09%5B%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%2C%20%7Ba%3A%200%7D%5D%2C%0A%09R.sort(R.ascend(R.prop('a')))%0A)%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A%200%7D%2C%20%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%5D">Try this <strong>R.ascend</strong> example in Rambda REPL</a>
|
|
934
937
|
|
|
935
938
|
<details>
|
|
936
939
|
|
|
@@ -1136,7 +1139,7 @@ const result = condition(input)
|
|
|
1136
1139
|
// => true
|
|
1137
1140
|
```
|
|
1138
1141
|
|
|
1139
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1142
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20condition%20%3D%20R.checkObjectWithSpec(%7B%0A%20%20a%20%3A%20x%20%3D%3E%20typeof%20x%20%3D%3D%3D%20%22string%22%2C%0A%20%20b%20%3A%20x%20%3D%3E%20x%20%3D%3D%3D%204%0A%7D)%0Aconst%20input%20%3D%20%7B%0A%20%20a%20%3A%20%22foo%22%2C%0A%20%20b%20%3A%204%2C%0A%20%20c%20%3A%2011%2C%0A%7D%0A%0Aconst%20result%20%3D%20condition(input)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.checkObjectWithSpec</strong> example in Rambda REPL</a>
|
|
1140
1143
|
|
|
1141
1144
|
<details>
|
|
1142
1145
|
|
|
@@ -1272,7 +1275,7 @@ const result = R.pipe(
|
|
|
1272
1275
|
// => { a: ['a', 'b', 'c'], b: [1, 2, 3], c: { a: 1, b: 2, c: 0, f: false } }
|
|
1273
1276
|
```
|
|
1274
1277
|
|
|
1275
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1278
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pipe(%0A%09%7B%0A%09%09a%3A%20%5B%20undefined%2C%20''%2C%20'a'%2C%20'b'%2C%20'c'%5D%2C%0A%09%09b%3A%20%5B1%2C2%2C%20null%2C%200%2C%20undefined%2C%203%5D%2C%0A%09%09c%3A%20%7B%20a%3A%201%2C%20b%3A%202%2C%20c%3A%200%2C%20d%3A%20undefined%2C%20e%3A%20null%2C%20f%3A%20false%20%7D%2C%0A%09%7D%2C%0A%09x%20%3D%3E%20(%7B%0A%09%09a%3A%20R.compact(x.a)%2C%0A%09%09b%3A%20R.compact(x.b)%2C%0A%09%09c%3A%20R.compact(x.c)%0A%09%7D)%0A)%0A%2F%2F%20%3D%3E%20%7B%20a%3A%20%5B'a'%2C%20'b'%2C%20'c'%5D%2C%20b%3A%20%5B1%2C%202%2C%203%5D%2C%20c%3A%20%7B%20a%3A%201%2C%20b%3A%202%2C%20c%3A%200%2C%20f%3A%20false%20%7D%20%7D">Try this <strong>R.compact</strong> example in Rambda REPL</a>
|
|
1276
1279
|
|
|
1277
1280
|
<details>
|
|
1278
1281
|
|
|
@@ -1392,7 +1395,7 @@ const result = [
|
|
|
1392
1395
|
] => [ true, false ]
|
|
1393
1396
|
```
|
|
1394
1397
|
|
|
1395
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1398
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20fn%20%3D%20x%20%3D%3E%20x%20%3E%205%0Aconst%20inverted%20%3D%20complement(fn)%0A%0Aconst%20result%20%3D%20%5B%0A%20%20fn(7)%2C%0A%20%20inverted(7)%0A%5D%20%3D%3E%20%5B%20true%2C%20false%20%5D">Try this <strong>R.complement</strong> example in Rambda REPL</a>
|
|
1396
1399
|
|
|
1397
1400
|
<details>
|
|
1398
1401
|
|
|
@@ -1473,7 +1476,7 @@ R.concat([1, 2])([3, 4]) // => [1, 2, 3, 4]
|
|
|
1473
1476
|
R.concat('foo')('bar') // => 'foobar'
|
|
1474
1477
|
```
|
|
1475
1478
|
|
|
1476
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1479
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?R.concat(%5B1%2C%202%5D)(%5B3%2C%204%5D)%20%2F%2F%20%3D%3E%20%5B1%2C%202%2C%203%2C%204%5D%0Aconst%20result%20%3D%20R.concat('foo')('bar')%20%2F%2F%20%3D%3E%20'foobar'">Try this <strong>R.concat</strong> example in Rambda REPL</a>
|
|
1477
1480
|
|
|
1478
1481
|
<details>
|
|
1479
1482
|
|
|
@@ -1592,7 +1595,7 @@ const result = R.count(x => x.a !== undefined)(list)
|
|
|
1592
1595
|
// => 2
|
|
1593
1596
|
```
|
|
1594
1597
|
|
|
1595
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1598
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%7Ba%3A%201%7D%2C%201%2C%20%7Ba%3A2%7D%5D%0Aconst%20result%20%3D%20R.count(x%20%3D%3E%20x.a%20!%3D%3D%20undefined)(list)%0A%2F%2F%20%3D%3E%202">Try this <strong>R.count</strong> example in Rambda REPL</a>
|
|
1596
1599
|
|
|
1597
1600
|
<details>
|
|
1598
1601
|
|
|
@@ -1683,7 +1686,7 @@ const expected = { a: 2, b: 2, c: 2 }
|
|
|
1683
1686
|
// => `result` is equal to `expected`
|
|
1684
1687
|
```
|
|
1685
1688
|
|
|
1686
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1689
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%20'a'%2C%20'A'%2C%20'b'%2C%20'B'%2C%20'c'%2C%20'C'%20%5D%0A%0Aconst%20result%20%3D%20countBy(x%20%3D%3E%20x.toLowerCase())(%20list)%0Aconst%20expected%20%3D%20%7B%20a%3A%202%2C%20b%3A%202%2C%20c%3A%202%20%7D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.countBy</strong> example in Rambda REPL</a>
|
|
1687
1690
|
|
|
1688
1691
|
<details>
|
|
1689
1692
|
|
|
@@ -1781,7 +1784,7 @@ const result = R.createObjectFromKeys(
|
|
|
1781
1784
|
// => {a: 'a-0', b: 'b-1', c: 'c-2'}
|
|
1782
1785
|
```
|
|
1783
1786
|
|
|
1784
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1787
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.createObjectFromKeys(%0A%09(x%2C%20index)%20%3D%3E%20%60%24%7Bx%7D-%24%7Bindex%7D%60%0A)(%5B'a'%2C%20'b'%2C%20'c'%5D)%0A%2F%2F%20%3D%3E%20%7Ba%3A%20'a-0'%2C%20b%3A%20'b-1'%2C%20c%3A%20'c-2'%7D">Try this <strong>R.createObjectFromKeys</strong> example in Rambda REPL</a>
|
|
1785
1788
|
|
|
1786
1789
|
<details>
|
|
1787
1790
|
|
|
@@ -1857,7 +1860,7 @@ R.defaultTo('foo'))(undefined) // => 'foo'
|
|
|
1857
1860
|
R.defaultTo('foo')('') // => 'foo'
|
|
1858
1861
|
```
|
|
1859
1862
|
|
|
1860
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1863
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?R.defaultTo('foo')('bar')%20%2F%2F%20%3D%3E%20'bar'%0AR.defaultTo('foo'))(undefined)%20%2F%2F%20%3D%3E%20'foo'%0A%0A%2F%2F%20Important%20-%20emtpy%20string%20is%20not%20falsy%20value%0Aconst%20result%20%3D%20R.defaultTo('foo')('')%20%2F%2F%20%3D%3E%20'foo'">Try this <strong>R.defaultTo</strong> example in Rambda REPL</a>
|
|
1861
1864
|
|
|
1862
1865
|
<details>
|
|
1863
1866
|
|
|
@@ -1956,7 +1959,7 @@ const result = R.pipe(
|
|
|
1956
1959
|
// => [{a: 2}, {a: 1}, {a: 0}]
|
|
1957
1960
|
```
|
|
1958
1961
|
|
|
1959
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
1962
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pipe(%0A%09%5B%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%2C%20%7Ba%3A%200%7D%5D%2C%0A%09R.sort(R.descend(R.prop('a')))%0A)%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A%202%7D%2C%20%7Ba%3A%201%7D%2C%20%7Ba%3A%200%7D%5D">Try this <strong>R.descend</strong> example in Rambda REPL</a>
|
|
1960
1963
|
|
|
1961
1964
|
<details>
|
|
1962
1965
|
|
|
@@ -1989,6 +1992,105 @@ export function descend(getFunction) {
|
|
|
1989
1992
|
|
|
1990
1993
|
[](#descend)
|
|
1991
1994
|
|
|
1995
|
+
### difference
|
|
1996
|
+
|
|
1997
|
+
```typescript
|
|
1998
|
+
|
|
1999
|
+
difference<T>(x: T[]): (y: T[]) => T[]
|
|
2000
|
+
```
|
|
2001
|
+
|
|
2002
|
+
It returns a merged list of `x` and `y` with all equal elements removed.
|
|
2003
|
+
|
|
2004
|
+
`R.equals` is used to determine equality.
|
|
2005
|
+
|
|
2006
|
+
```javascript
|
|
2007
|
+
const x = [ 1, 2, 3, 4 ]
|
|
2008
|
+
const y = [ 3, 4, 5, 6 ]
|
|
2009
|
+
|
|
2010
|
+
const result = R.difference(x)(y)
|
|
2011
|
+
// => [ 1, 2, 5, 6 ]
|
|
2012
|
+
```
|
|
2013
|
+
|
|
2014
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20x%20%3D%20%5B%201%2C%202%2C%203%2C%204%20%5D%0Aconst%20y%20%3D%20%5B%203%2C%204%2C%205%2C%206%20%5D%0A%0Aconst%20result%20%3D%20R.difference(x)(y)%0A%2F%2F%20%3D%3E%20%5B%201%2C%202%2C%205%2C%206%20%5D">Try this <strong>R.difference</strong> example in Rambda REPL</a>
|
|
2015
|
+
|
|
2016
|
+
<details>
|
|
2017
|
+
|
|
2018
|
+
<summary>All TypeScript definitions</summary>
|
|
2019
|
+
|
|
2020
|
+
```typescript
|
|
2021
|
+
difference<T>(x: T[]): (y: T[]) => T[];
|
|
2022
|
+
```
|
|
2023
|
+
|
|
2024
|
+
</details>
|
|
2025
|
+
|
|
2026
|
+
<details>
|
|
2027
|
+
|
|
2028
|
+
<summary><strong>R.difference</strong> source</summary>
|
|
2029
|
+
|
|
2030
|
+
```javascript
|
|
2031
|
+
import { filter } from './filter.js'
|
|
2032
|
+
import { includes } from './includes.js'
|
|
2033
|
+
|
|
2034
|
+
export function difference(x) {
|
|
2035
|
+
return y => ([
|
|
2036
|
+
...filter(value => !includes(value)(y))(x),
|
|
2037
|
+
...filter(value => !includes(value)(x))(y),
|
|
2038
|
+
])
|
|
2039
|
+
}
|
|
2040
|
+
```
|
|
2041
|
+
|
|
2042
|
+
</details>
|
|
2043
|
+
|
|
2044
|
+
<details>
|
|
2045
|
+
|
|
2046
|
+
<summary><strong>Tests</strong></summary>
|
|
2047
|
+
|
|
2048
|
+
```javascript
|
|
2049
|
+
import { difference } from './difference.js'
|
|
2050
|
+
|
|
2051
|
+
test('difference', () => {
|
|
2052
|
+
const list1 = [1, 2, 3, 4]
|
|
2053
|
+
const list2 = [3, 4, 5, 6]
|
|
2054
|
+
expect(difference(list1)(list2)).toEqual([1, 2, 5, 6])
|
|
2055
|
+
expect(difference([])([])).toEqual([])
|
|
2056
|
+
})
|
|
2057
|
+
|
|
2058
|
+
test('difference with objects', () => {
|
|
2059
|
+
const list1 = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
|
|
2060
|
+
const list2 = [{ id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }]
|
|
2061
|
+
expect(difference(list1)(list2)).toEqual([
|
|
2062
|
+
{ id: 1 },
|
|
2063
|
+
{ id: 2 },
|
|
2064
|
+
{ id: 5 },
|
|
2065
|
+
{ id: 6 },
|
|
2066
|
+
])
|
|
2067
|
+
})
|
|
2068
|
+
```
|
|
2069
|
+
|
|
2070
|
+
</details>
|
|
2071
|
+
|
|
2072
|
+
<details>
|
|
2073
|
+
|
|
2074
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
2075
|
+
|
|
2076
|
+
```typescript
|
|
2077
|
+
import { difference } from 'rambda'
|
|
2078
|
+
|
|
2079
|
+
describe('R.difference', () => {
|
|
2080
|
+
it('happy', () => {
|
|
2081
|
+
const list1 = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
|
|
2082
|
+
const list2 = [{ id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }]
|
|
2083
|
+
const result = difference(list1)(list2)
|
|
2084
|
+
|
|
2085
|
+
result // $ExpectType { id: number; }[]
|
|
2086
|
+
})
|
|
2087
|
+
})
|
|
2088
|
+
```
|
|
2089
|
+
|
|
2090
|
+
</details>
|
|
2091
|
+
|
|
2092
|
+
[](#difference)
|
|
2093
|
+
|
|
1992
2094
|
### drop
|
|
1993
2095
|
|
|
1994
2096
|
```typescript
|
|
@@ -2002,7 +2104,7 @@ It returns `howMany` items dropped from beginning of list.
|
|
|
2002
2104
|
R.drop(2)(['foo', 'bar', 'baz']) // => ['baz']
|
|
2003
2105
|
```
|
|
2004
2106
|
|
|
2005
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2107
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.drop(2)(%5B'foo'%2C%20'bar'%2C%20'baz'%5D)%20%2F%2F%20%3D%3E%20%5B'baz'%5D">Try this <strong>R.drop</strong> example in Rambda REPL</a>
|
|
2006
2108
|
|
|
2007
2109
|
<details>
|
|
2008
2110
|
|
|
@@ -2135,7 +2237,7 @@ const result = dropLastWhile(predicate)(list);
|
|
|
2135
2237
|
// => [1, 2]
|
|
2136
2238
|
```
|
|
2137
2239
|
|
|
2138
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2240
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%3B%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%3D%203%0A%0Aconst%20result%20%3D%20dropLastWhile(predicate)(list)%3B%0A%2F%2F%20%3D%3E%20%5B1%2C%202%5D">Try this <strong>R.dropLastWhile</strong> example in Rambda REPL</a>
|
|
2139
2241
|
|
|
2140
2242
|
<details>
|
|
2141
2243
|
|
|
@@ -2219,7 +2321,7 @@ const result = R.dropRepeatsBy(
|
|
|
2219
2321
|
// => [1, 2, 3]
|
|
2220
2322
|
```
|
|
2221
2323
|
|
|
2222
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2324
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.dropRepeatsBy(%0A%20%20Math.abs%2C%0A%20%20%5B1%2C%20-1%2C%202%2C%203%2C%20-3%5D%0A)%0A%2F%2F%20%3D%3E%20%5B1%2C%202%2C%203%5D">Try this <strong>R.dropRepeatsBy</strong> example in Rambda REPL</a>
|
|
2223
2325
|
|
|
2224
2326
|
<details>
|
|
2225
2327
|
|
|
@@ -2247,7 +2349,7 @@ const result = R.dropRepeatsWith(R.prop('a'))(list)
|
|
|
2247
2349
|
// => [{a:1,b:2}, {a:2, b:4}]
|
|
2248
2350
|
```
|
|
2249
2351
|
|
|
2250
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2352
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%7Ba%3A1%2Cb%3A2%7D%2C%20%7Ba%3A1%2Cb%3A3%7D%2C%20%7Ba%3A2%2C%20b%3A4%7D%5D%0Aconst%20result%20%3D%20R.dropRepeatsWith(R.prop('a'))(list)%0A%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A1%2Cb%3A2%7D%2C%20%7Ba%3A2%2C%20b%3A4%7D%5D">Try this <strong>R.dropRepeatsWith</strong> example in Rambda REPL</a>
|
|
2251
2353
|
|
|
2252
2354
|
<details>
|
|
2253
2355
|
|
|
@@ -2275,7 +2377,7 @@ const result = R.dropWhile(predicate)(list)
|
|
|
2275
2377
|
// => [3, 4]
|
|
2276
2378
|
```
|
|
2277
2379
|
|
|
2278
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2380
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%2C%204%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3C%203%0Aconst%20result%20%3D%20R.dropWhile(predicate)(list)%0A%2F%2F%20%3D%3E%20%5B3%2C%204%5D">Try this <strong>R.dropWhile</strong> example in Rambda REPL</a>
|
|
2279
2381
|
|
|
2280
2382
|
<details>
|
|
2281
2383
|
|
|
@@ -2394,7 +2496,7 @@ const result = R.duplicateBy(x => x, list)
|
|
|
2394
2496
|
// => [{a:1}]
|
|
2395
2497
|
```
|
|
2396
2498
|
|
|
2397
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2499
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%7Ba%3A1%7D%2C%20%7Ba%3A2%7D%2C%20%7Ba%3A1%7D%5D%0Aconst%20result%20%3D%20R.duplicateBy(x%20%3D%3E%20x%2C%20list)%0A%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A1%7D%5D">Try this <strong>R.duplicateBy</strong> example in Rambda REPL</a>
|
|
2398
2500
|
|
|
2399
2501
|
<details>
|
|
2400
2502
|
|
|
@@ -2462,7 +2564,7 @@ const result = R.eqBy(Math.abs, 5)(-5)
|
|
|
2462
2564
|
// => true
|
|
2463
2565
|
```
|
|
2464
2566
|
|
|
2465
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2567
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.eqBy(Math.abs%2C%205)(-5)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.eqBy</strong> example in Rambda REPL</a>
|
|
2466
2568
|
|
|
2467
2569
|
<details>
|
|
2468
2570
|
|
|
@@ -2531,7 +2633,7 @@ const result = R.eqProps('a', obj1)(obj2)
|
|
|
2531
2633
|
// => true
|
|
2532
2634
|
```
|
|
2533
2635
|
|
|
2534
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2636
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj1%20%3D%20%7Ba%3A%201%2C%20b%3A2%7D%0Aconst%20obj2%20%3D%20%7Ba%3A%201%2C%20b%3A3%7D%0Aconst%20result%20%3D%20R.eqProps('a'%2C%20obj1)(obj2)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.eqProps</strong> example in Rambda REPL</a>
|
|
2535
2637
|
|
|
2536
2638
|
<details>
|
|
2537
2639
|
|
|
@@ -2630,7 +2732,7 @@ R.equals(
|
|
|
2630
2732
|
) // => true
|
|
2631
2733
|
```
|
|
2632
2734
|
|
|
2633
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
2735
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?R.equals(%0A%20%20%5B1%2C%20%7Ba%3A2%7D%2C%20%5B%7Bb%3A%203%7D%5D%5D%2C%0A%20%20%5B1%2C%20%7Ba%3A2%7D%2C%20%5B%7Bb%3A%203%7D%5D%5D%0Aconst%20result%20%3D%20)%20%2F%2F%20%3D%3E%20true">Try this <strong>R.equals</strong> example in Rambda REPL</a>
|
|
2634
2736
|
|
|
2635
2737
|
<details>
|
|
2636
2738
|
|
|
@@ -3122,7 +3224,7 @@ const result = R.pipe(
|
|
|
3122
3224
|
// => result is { foo: 3, baz: 'baz' }
|
|
3123
3225
|
```
|
|
3124
3226
|
|
|
3125
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
3227
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20input%20%3D%20%7B%0A%09foo%3A%202%2C%0A%09baz%3A%20'baz'%2C%0A%7D%0Aconst%20result%20%3D%20R.pipe(%0A%09input%2C%0A%09R.evolve(%7B%0A%09%09foo%3A%20x%20%3D%3E%20x%20%2B%201%2C%0A%09%7D)%0A)%0A%2F%2F%20%3D%3E%20result%20is%20%7B%20foo%3A%203%2C%20baz%3A%20'baz'%20%7D">Try this <strong>R.evolve</strong> example in Rambda REPL</a>
|
|
3126
3228
|
|
|
3127
3229
|
<details>
|
|
3128
3230
|
|
|
@@ -3213,7 +3315,7 @@ it('R.evolve', () => {
|
|
|
3213
3315
|
|
|
3214
3316
|
```typescript
|
|
3215
3317
|
|
|
3216
|
-
excludes
|
|
3318
|
+
excludes(list: readonly string[] | string): (substringToFind: string) => boolean
|
|
3217
3319
|
```
|
|
3218
3320
|
|
|
3219
3321
|
Opposite of `R.includes`
|
|
@@ -3222,21 +3324,21 @@ Opposite of `R.includes`
|
|
|
3222
3324
|
|
|
3223
3325
|
```javascript
|
|
3224
3326
|
const result = [
|
|
3225
|
-
R.excludes('
|
|
3226
|
-
R.excludes({a:
|
|
3327
|
+
R.excludes('foo')('ar'),
|
|
3328
|
+
R.excludes([{a: 1}])({a: 2})
|
|
3227
3329
|
]
|
|
3228
3330
|
// => [true, true ]
|
|
3229
3331
|
```
|
|
3230
3332
|
|
|
3231
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
3333
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.excludes('foo')('ar')%2C%0A%20%20R.excludes(%5B%7Ba%3A%201%7D%5D)(%7Ba%3A%202%7D)%0A%5D%0A%2F%2F%20%3D%3E%20%5Btrue%2C%20true%20%5D">Try this <strong>R.excludes</strong> example in Rambda REPL</a>
|
|
3232
3334
|
|
|
3233
3335
|
<details>
|
|
3234
3336
|
|
|
3235
3337
|
<summary>All TypeScript definitions</summary>
|
|
3236
3338
|
|
|
3237
3339
|
```typescript
|
|
3238
|
-
excludes
|
|
3239
|
-
excludes<T>(
|
|
3340
|
+
excludes(list: readonly string[] | string): (substringToFind: string) => boolean;
|
|
3341
|
+
excludes<T>(list: readonly T[]): (target: T) => boolean;
|
|
3240
3342
|
```
|
|
3241
3343
|
|
|
3242
3344
|
</details>
|
|
@@ -3289,7 +3391,7 @@ import { excludes, pipe } from 'rambda'
|
|
|
3289
3391
|
describe('R.excludes', () => {
|
|
3290
3392
|
it('happy', () => {
|
|
3291
3393
|
const list = [{ a: { b: '1' } }, { a: { b: '2' } }, { a: { b: '3' } }]
|
|
3292
|
-
const result = pipe(
|
|
3394
|
+
const result = pipe({ a: { b: '1' } }, excludes(list))
|
|
3293
3395
|
result // $ExpectType boolean
|
|
3294
3396
|
})
|
|
3295
3397
|
it('with string', () => {
|
|
@@ -3303,6 +3405,96 @@ describe('R.excludes', () => {
|
|
|
3303
3405
|
|
|
3304
3406
|
[](#excludes)
|
|
3305
3407
|
|
|
3408
|
+
### exists
|
|
3409
|
+
|
|
3410
|
+
```typescript
|
|
3411
|
+
|
|
3412
|
+
exists<T>(predicate: (x: T) => boolean): (list: T[]) => boolean
|
|
3413
|
+
```
|
|
3414
|
+
|
|
3415
|
+
It returns `true` if there is at least one element in `list` that satisfy the `predicate`.
|
|
3416
|
+
|
|
3417
|
+
```javascript
|
|
3418
|
+
const predicate = x => R.type(x.foo) === 'Number'
|
|
3419
|
+
const list = [{foo: 'bar'}, {foo: 1}]
|
|
3420
|
+
|
|
3421
|
+
const result = R.exists(predicate)(list)
|
|
3422
|
+
// => true
|
|
3423
|
+
```
|
|
3424
|
+
|
|
3425
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%20'bar'%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.exists(predicate)(list)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.exists</strong> example in Rambda REPL</a>
|
|
3426
|
+
|
|
3427
|
+
<details>
|
|
3428
|
+
|
|
3429
|
+
<summary>All TypeScript definitions</summary>
|
|
3430
|
+
|
|
3431
|
+
```typescript
|
|
3432
|
+
exists<T>(predicate: (x: T) => boolean): (list: T[]) => boolean;
|
|
3433
|
+
```
|
|
3434
|
+
|
|
3435
|
+
</details>
|
|
3436
|
+
|
|
3437
|
+
<details>
|
|
3438
|
+
|
|
3439
|
+
<summary><strong>R.exists</strong> source</summary>
|
|
3440
|
+
|
|
3441
|
+
```javascript
|
|
3442
|
+
import { find } from './find.js'
|
|
3443
|
+
|
|
3444
|
+
export function exists(predicate) {
|
|
3445
|
+
return list => {
|
|
3446
|
+
return find(predicate)(list) !== undefined
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
```
|
|
3450
|
+
|
|
3451
|
+
</details>
|
|
3452
|
+
|
|
3453
|
+
<details>
|
|
3454
|
+
|
|
3455
|
+
<summary><strong>Tests</strong></summary>
|
|
3456
|
+
|
|
3457
|
+
```javascript
|
|
3458
|
+
import { exists } from './exists.js'
|
|
3459
|
+
import { propEq } from './propEq.js'
|
|
3460
|
+
|
|
3461
|
+
const list = [{ a: 1 }, { a: 2 }, { a: 3 }]
|
|
3462
|
+
|
|
3463
|
+
test('happy', () => {
|
|
3464
|
+
const fn = propEq(2, 'a')
|
|
3465
|
+
expect(exists(fn)(list)).toBe(true)
|
|
3466
|
+
})
|
|
3467
|
+
|
|
3468
|
+
test('nothing is found', () => {
|
|
3469
|
+
const fn = propEq(4, 'a')
|
|
3470
|
+
expect(exists(fn)(list)).toBe(false)
|
|
3471
|
+
})
|
|
3472
|
+
```
|
|
3473
|
+
|
|
3474
|
+
</details>
|
|
3475
|
+
|
|
3476
|
+
<details>
|
|
3477
|
+
|
|
3478
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
3479
|
+
|
|
3480
|
+
```typescript
|
|
3481
|
+
import { exists, pipe } from 'rambda'
|
|
3482
|
+
|
|
3483
|
+
const list = [1, 2, 3]
|
|
3484
|
+
|
|
3485
|
+
describe('R.exists', () => {
|
|
3486
|
+
it('happy', () => {
|
|
3487
|
+
const predicate = (x: number) => x > 2
|
|
3488
|
+
const result = pipe(list, exists(predicate))
|
|
3489
|
+
result // $ExpectType boolean
|
|
3490
|
+
})
|
|
3491
|
+
})
|
|
3492
|
+
```
|
|
3493
|
+
|
|
3494
|
+
</details>
|
|
3495
|
+
|
|
3496
|
+
[](#exists)
|
|
3497
|
+
|
|
3306
3498
|
### filter
|
|
3307
3499
|
|
|
3308
3500
|
```typescript
|
|
@@ -3321,7 +3513,7 @@ const result = R.filter(predicate)(list)
|
|
|
3321
3513
|
// => [2, 3]
|
|
3322
3514
|
```
|
|
3323
3515
|
|
|
3324
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
3516
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%201%0Aconst%20list%20%3D%20%5B1%2C%202%2C%203%5D%0Aconst%20result%20%3D%20R.filter(predicate)(list)%0A%2F%2F%20%3D%3E%20%5B2%2C%203%5D">Try this <strong>R.filter</strong> example in Rambda REPL</a>
|
|
3325
3517
|
|
|
3326
3518
|
<details>
|
|
3327
3519
|
|
|
@@ -3333,10 +3525,10 @@ filter<T, S extends T>(
|
|
|
3333
3525
|
): (list: T[]) => S[];
|
|
3334
3526
|
filter<T>(
|
|
3335
3527
|
predicate: BooleanConstructor,
|
|
3336
|
-
): (list: readonly T[]) =>
|
|
3528
|
+
): (list: readonly T[]) => ExcludeFalsy<T>[];
|
|
3337
3529
|
filter<T>(
|
|
3338
3530
|
predicate: BooleanConstructor,
|
|
3339
|
-
): (list: T[]) =>
|
|
3531
|
+
): (list: T[]) => ExcludeFalsy<T>[];
|
|
3340
3532
|
filter<T>(
|
|
3341
3533
|
predicate: (value: T) => boolean,
|
|
3342
3534
|
): (list: T[]) => T[];
|
|
@@ -3400,20 +3592,45 @@ test('using Boolean', () => {
|
|
|
3400
3592
|
<summary><strong>TypeScript</strong> test</summary>
|
|
3401
3593
|
|
|
3402
3594
|
```typescript
|
|
3403
|
-
import { filter, pipe } from 'rambda'
|
|
3595
|
+
import { filter, includes, pipe, reject, sort, split, uniq } from 'rambda'
|
|
3404
3596
|
|
|
3405
3597
|
const list = [1, 2, 3]
|
|
3406
3598
|
|
|
3407
3599
|
describe('R.filter with array', () => {
|
|
3408
3600
|
it('within pipe', () => {
|
|
3409
|
-
const
|
|
3601
|
+
const _result = pipe(
|
|
3410
3602
|
list,
|
|
3411
3603
|
filter(x => {
|
|
3412
3604
|
x // $ExpectType number
|
|
3413
3605
|
return x > 1
|
|
3414
3606
|
}),
|
|
3415
3607
|
)
|
|
3416
|
-
|
|
3608
|
+
_result // $ExpectType number[]
|
|
3609
|
+
})
|
|
3610
|
+
|
|
3611
|
+
it('complex example', () => {
|
|
3612
|
+
const text = `Dies ist ein einfacher Beispielsatz. Il fait beau aujourd'hui!`
|
|
3613
|
+
const language = 'de'
|
|
3614
|
+
const SENTENCE_END_CHARS = ['.', '!', '?', '।', '؟']
|
|
3615
|
+
const result = pipe(
|
|
3616
|
+
text,
|
|
3617
|
+
split(''),
|
|
3618
|
+
uniq,
|
|
3619
|
+
filter(char => {
|
|
3620
|
+
if (language === 'de') {
|
|
3621
|
+
return /[A-Za-zäßüöÜÖÄ]/g.test(char) === false
|
|
3622
|
+
}
|
|
3623
|
+
if (language === 'fr') {
|
|
3624
|
+
return /[A-Za-zÀÉàâçèéêîïôùû']/g.test(char) === false
|
|
3625
|
+
}
|
|
3626
|
+
throw new Error(`Language ${language} not supported`)
|
|
3627
|
+
}),
|
|
3628
|
+
sort((a, b) => (a === b ? 0 : a > b ? 1 : -1)),
|
|
3629
|
+
filter(char => char.trim().length > 0),
|
|
3630
|
+
reject(includes(SENTENCE_END_CHARS)),
|
|
3631
|
+
)
|
|
3632
|
+
|
|
3633
|
+
result // $ExpectType string[]
|
|
3417
3634
|
})
|
|
3418
3635
|
it('narrowing type', () => {
|
|
3419
3636
|
interface Foo {
|
|
@@ -3422,17 +3639,15 @@ describe('R.filter with array', () => {
|
|
|
3422
3639
|
interface Bar extends Foo {
|
|
3423
3640
|
b: string
|
|
3424
3641
|
}
|
|
3425
|
-
|
|
3426
|
-
const testList: T[]= [{ a: 1 }, { a: 2 }, { a: 3 }]
|
|
3642
|
+
type T = Foo | Bar
|
|
3643
|
+
const testList: T[] = [{ a: 1 }, { a: 2 }, { a: 3 }]
|
|
3427
3644
|
const filterBar = (x: T): x is Bar => {
|
|
3428
3645
|
return typeof (x as Bar).b === 'string'
|
|
3429
3646
|
}
|
|
3430
|
-
const
|
|
3431
|
-
|
|
3432
|
-
filter(filterBar),
|
|
3433
|
-
)
|
|
3434
|
-
result // $ExpectType Bar[]
|
|
3647
|
+
const _result = pipe(testList, filter(filterBar))
|
|
3648
|
+
_result // $ExpectType Bar[]
|
|
3435
3649
|
})
|
|
3650
|
+
|
|
3436
3651
|
it('narrowing type - readonly', () => {
|
|
3437
3652
|
interface Foo {
|
|
3438
3653
|
a: number
|
|
@@ -3440,30 +3655,33 @@ describe('R.filter with array', () => {
|
|
|
3440
3655
|
interface Bar extends Foo {
|
|
3441
3656
|
b: string
|
|
3442
3657
|
}
|
|
3443
|
-
|
|
3444
|
-
const testList: T[]= [{ a: 1 }, { a: 2 }, { a: 3 }] as const
|
|
3658
|
+
type T = Foo | Bar
|
|
3659
|
+
const testList: T[] = [{ a: 1 }, { a: 2 }, { a: 3 }] as const
|
|
3445
3660
|
const filterBar = (x: T): x is Bar => {
|
|
3446
3661
|
return typeof (x as Bar).b === 'string'
|
|
3447
3662
|
}
|
|
3448
|
-
const
|
|
3449
|
-
|
|
3450
|
-
filter(filterBar),
|
|
3451
|
-
)
|
|
3452
|
-
result // $ExpectType Bar[]
|
|
3663
|
+
const _result = pipe(testList, filter(filterBar))
|
|
3664
|
+
_result // $ExpectType Bar[]
|
|
3453
3665
|
})
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
const
|
|
3457
|
-
|
|
3666
|
+
|
|
3667
|
+
it('filtering NonNullable - list of objects', () => {
|
|
3668
|
+
const testList = [{ a: 1 }, { a: 2 }, false, { a: 3 }]
|
|
3669
|
+
const _result = pipe(testList, filter(Boolean))
|
|
3670
|
+
_result // $ExpectType { a: number; }[]
|
|
3458
3671
|
})
|
|
3672
|
+
|
|
3459
3673
|
it('filtering NonNullable - readonly', () => {
|
|
3460
|
-
const testList = [1, 2, null, undefined, 3] as const
|
|
3674
|
+
const testList = [1, 2, true, false, null, undefined, 3] as const
|
|
3461
3675
|
const result = pipe(testList, filter(Boolean))
|
|
3462
3676
|
result.includes(1)
|
|
3463
3677
|
// @ts-expect-error
|
|
3678
|
+
result.includes(true)
|
|
3679
|
+
// @ts-expect-error
|
|
3680
|
+
result.includes(false)
|
|
3681
|
+
// @ts-expect-error
|
|
3464
3682
|
result.includes(4)
|
|
3465
3683
|
// @ts-expect-error
|
|
3466
|
-
result.includes(undefined)
|
|
3684
|
+
result.includes(undefined)
|
|
3467
3685
|
// @ts-expect-error
|
|
3468
3686
|
result.includes(null)
|
|
3469
3687
|
})
|
|
@@ -3583,7 +3801,7 @@ const result = R.filterObject(
|
|
|
3583
3801
|
// => {a: 1, c: 3}
|
|
3584
3802
|
```
|
|
3585
3803
|
|
|
3586
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
3804
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.filterObject(%0A%09(val%2C%20prop)%20%3D%3E%20prop%20%3D%3D%3D%20'a'%20%7C%7C%20val%20%3E%201%0A)(%7Ba%3A%201%2C%20b%3A%202%2C%20c%3A3%7D)%0A%2F%2F%20%3D%3E%20%7Ba%3A%201%2C%20c%3A%203%7D">Try this <strong>R.filterObject</strong> example in Rambda REPL</a>
|
|
3587
3805
|
|
|
3588
3806
|
<details>
|
|
3589
3807
|
|
|
@@ -3691,7 +3909,7 @@ const result = R.find(predicate)(list)
|
|
|
3691
3909
|
// => {foo: 1}
|
|
3692
3910
|
```
|
|
3693
3911
|
|
|
3694
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
3912
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%20'bar'%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.find(predicate)(list)%0A%2F%2F%20%3D%3E%20%7Bfoo%3A%201%7D">Try this <strong>R.find</strong> example in Rambda REPL</a>
|
|
3695
3913
|
|
|
3696
3914
|
<details>
|
|
3697
3915
|
|
|
@@ -3795,7 +4013,7 @@ const result = R.findIndex(predicate)(list)
|
|
|
3795
4013
|
// => 1
|
|
3796
4014
|
```
|
|
3797
4015
|
|
|
3798
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4016
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%20'bar'%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.findIndex(predicate)(list)%0A%2F%2F%20%3D%3E%201">Try this <strong>R.findIndex</strong> example in Rambda REPL</a>
|
|
3799
4017
|
|
|
3800
4018
|
<details>
|
|
3801
4019
|
|
|
@@ -3890,7 +4108,7 @@ const result = R.findLast(predicate)(list)
|
|
|
3890
4108
|
// => {foo: 1}
|
|
3891
4109
|
```
|
|
3892
4110
|
|
|
3893
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4111
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%200%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.findLast(predicate)(list)%0A%2F%2F%20%3D%3E%20%7Bfoo%3A%201%7D">Try this <strong>R.findLast</strong> example in Rambda REPL</a>
|
|
3894
4112
|
|
|
3895
4113
|
<details>
|
|
3896
4114
|
|
|
@@ -3945,7 +4163,7 @@ const result = R.findLastIndex(predicate)(list)
|
|
|
3945
4163
|
// => 1
|
|
3946
4164
|
```
|
|
3947
4165
|
|
|
3948
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4166
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%200%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.findLastIndex(predicate)(list)%0A%2F%2F%20%3D%3E%201">Try this <strong>R.findLastIndex</strong> example in Rambda REPL</a>
|
|
3949
4167
|
|
|
3950
4168
|
<details>
|
|
3951
4169
|
|
|
@@ -4034,7 +4252,7 @@ const result = R.findNth(predicate, 2)(list)
|
|
|
4034
4252
|
// => {foo: 2}
|
|
4035
4253
|
```
|
|
4036
4254
|
|
|
4037
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4255
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%200%7D%2C%20%7Bfoo%3A%201%7D%2C%20%7Bfoo%3A%202%7D%2C%20%7Bfoo%3A%203%7D%5D%0A%0Aconst%20result%20%3D%20R.findNth(predicate%2C%202)(list)%0A%2F%2F%20%3D%3E%20%7Bfoo%3A%202%7D">Try this <strong>R.findNth</strong> example in Rambda REPL</a>
|
|
4038
4256
|
|
|
4039
4257
|
<details>
|
|
4040
4258
|
|
|
@@ -4112,7 +4330,7 @@ const result = R.flatMap(duplicate)(list)
|
|
|
4112
4330
|
// => [ 1, 1, 2, 2, 3, 3 ]
|
|
4113
4331
|
```
|
|
4114
4332
|
|
|
4115
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4333
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20duplicate%20%3D%20n%20%3D%3E%20%5B%20n%2C%20n%20%5D%0Aconst%20list%20%3D%20%5B%201%2C%202%2C%203%20%5D%0A%0Aconst%20result%20%3D%20R.flatMap(duplicate)(list)%0A%2F%2F%20%3D%3E%20%5B%201%2C%201%2C%202%2C%202%2C%203%2C%203%20%5D">Try this <strong>R.flatMap</strong> example in Rambda REPL</a>
|
|
4116
4334
|
|
|
4117
4335
|
<details>
|
|
4118
4336
|
|
|
@@ -4233,7 +4451,7 @@ const result = R.flatten<number>([
|
|
|
4233
4451
|
// => [ 1, 2, 3, 30, 300, 4 ]
|
|
4234
4452
|
```
|
|
4235
4453
|
|
|
4236
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4454
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.flatten%3Cnumber%3E(%5B%0A%20%201%2C%0A%20%202%2C%0A%20%20%5B3%2C%2030%2C%20%5B300%5D%5D%2C%0A%20%20%5B4%5D%0A%5D)%0A%2F%2F%20%3D%3E%20%5B%201%2C%202%2C%203%2C%2030%2C%20300%2C%204%20%5D">Try this <strong>R.flatten</strong> example in Rambda REPL</a>
|
|
4237
4455
|
|
|
4238
4456
|
<details>
|
|
4239
4457
|
|
|
@@ -4331,7 +4549,7 @@ const result = R.flattenObject(
|
|
|
4331
4549
|
// => [3, 1, 2] or [2, 3, 1] or ...
|
|
4332
4550
|
```
|
|
4333
4551
|
|
|
4334
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4552
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.flattenObject(%0A%09%5B1%2C%202%2C%203%5D%0A)%0A%2F%2F%20%3D%3E%20%5B3%2C%201%2C%202%5D%20or%20%5B2%2C%203%2C%201%5D%20or%20...">Try this <strong>R.flattenObject</strong> example in Rambda REPL</a>
|
|
4335
4553
|
|
|
4336
4554
|
<details>
|
|
4337
4555
|
|
|
@@ -4555,7 +4773,7 @@ const result = R.groupBy(groupFn, list)
|
|
|
4555
4773
|
// => { '1': ['a', 'b'], '2': ['aa', 'bb'] }
|
|
4556
4774
|
```
|
|
4557
4775
|
|
|
4558
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4776
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%20'a'%2C%20'b'%2C%20'aa'%2C%20'bb'%20%5D%0Aconst%20groupFn%20%3D%20x%20%3D%3E%20x.length%0A%0Aconst%20result%20%3D%20R.groupBy(groupFn%2C%20list)%0A%2F%2F%20%3D%3E%20%7B%20'1'%3A%20%5B'a'%2C%20'b'%5D%2C%20'2'%3A%20%5B'aa'%2C%20'bb'%5D%20%7D">Try this <strong>R.groupBy</strong> example in Rambda REPL</a>
|
|
4559
4777
|
|
|
4560
4778
|
<details>
|
|
4561
4779
|
|
|
@@ -4672,7 +4890,7 @@ const result = [
|
|
|
4672
4890
|
// => [1, 'f']
|
|
4673
4891
|
```
|
|
4674
4892
|
|
|
4675
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
4893
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.head(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.head('foo')%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%20'f'%5D">Try this <strong>R.head</strong> example in Rambda REPL</a>
|
|
4676
4894
|
|
|
4677
4895
|
<details>
|
|
4678
4896
|
|
|
@@ -4780,7 +4998,7 @@ describe('R.head', () => {
|
|
|
4780
4998
|
|
|
4781
4999
|
```typescript
|
|
4782
5000
|
|
|
4783
|
-
includes(
|
|
5001
|
+
includes<T>(list: readonly T[]): (target: T) => boolean
|
|
4784
5002
|
```
|
|
4785
5003
|
|
|
4786
5004
|
If `input` is string, then this method work as native `String.includes`.
|
|
@@ -4789,21 +5007,21 @@ If `input` is array, then `R.equals` is used to define if `valueToFind` belongs
|
|
|
4789
5007
|
|
|
4790
5008
|
```javascript
|
|
4791
5009
|
const result = [
|
|
4792
|
-
R.includes('
|
|
4793
|
-
R.includes({a: 1})(
|
|
5010
|
+
R.includes('foo')('oo'),
|
|
5011
|
+
R.includes([{a: 1}])({a: 1})
|
|
4794
5012
|
]
|
|
4795
5013
|
// => [true, true ]
|
|
4796
5014
|
```
|
|
4797
5015
|
|
|
4798
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5016
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.includes('foo')('oo')%2C%0A%20%20R.includes(%5B%7Ba%3A%201%7D%5D)(%7Ba%3A%201%7D)%0A%5D%0A%2F%2F%20%3D%3E%20%5Btrue%2C%20true%20%5D">Try this <strong>R.includes</strong> example in Rambda REPL</a>
|
|
4799
5017
|
|
|
4800
5018
|
<details>
|
|
4801
5019
|
|
|
4802
5020
|
<summary>All TypeScript definitions</summary>
|
|
4803
5021
|
|
|
4804
5022
|
```typescript
|
|
4805
|
-
includes(
|
|
4806
|
-
includes
|
|
5023
|
+
includes<T>(list: readonly T[]): (target: T) => boolean;
|
|
5024
|
+
includes(list: readonly string[] | string): (substringToFind: string) => boolean;
|
|
4807
5025
|
```
|
|
4808
5026
|
|
|
4809
5027
|
</details>
|
|
@@ -4880,28 +5098,22 @@ test('with wrong input that does not throw', () => {
|
|
|
4880
5098
|
<summary><strong>TypeScript</strong> test</summary>
|
|
4881
5099
|
|
|
4882
5100
|
```typescript
|
|
4883
|
-
import { pipe, includes
|
|
5101
|
+
import { pipe , includes} from 'rambda'
|
|
4884
5102
|
|
|
4885
5103
|
describe('R.includes', () => {
|
|
4886
5104
|
it('happy', () => {
|
|
4887
5105
|
const list = [{ a: { b: '1' } }, { a: { b: '2' } }, { a: { b: '3' } }]
|
|
4888
|
-
const result = pipe(
|
|
5106
|
+
const result = pipe({ a: { b: '1' } }, includes(list))
|
|
4889
5107
|
result // $ExpectType boolean
|
|
4890
5108
|
})
|
|
4891
5109
|
it('with string', () => {
|
|
4892
|
-
const result = pipe('
|
|
5110
|
+
const result = pipe('oo', includes('foo'))
|
|
4893
5111
|
result // $ExpectType boolean
|
|
4894
5112
|
})
|
|
4895
5113
|
it('with array of strings', () => {
|
|
4896
|
-
const result = pipe(['1','2'
|
|
5114
|
+
const result = pipe('1', includes(['1','2','3']))
|
|
4897
5115
|
result // $ExpectType boolean
|
|
4898
5116
|
})
|
|
4899
|
-
it('without R.pipe', () => {
|
|
4900
|
-
const result1 = includes('1')(['1', '2'])
|
|
4901
|
-
const result2 = includes(1)([1, 2])
|
|
4902
|
-
result1 // $ExpectType boolean
|
|
4903
|
-
result2 // $ExpectType boolean
|
|
4904
|
-
})
|
|
4905
5117
|
})
|
|
4906
5118
|
```
|
|
4907
5119
|
|
|
@@ -4927,7 +5139,7 @@ const result = R.indexBy(
|
|
|
4927
5139
|
// => {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
|
|
4928
5140
|
```
|
|
4929
5141
|
|
|
4930
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5142
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.indexBy(%0A%09'id'%0A)(%5B%7Bid%3A%20'xyz'%2C%20title%3A%20'A'%7D%2C%20%7Bid%3A%20'abc'%2C%20title%3A%20'B'%7D%5D)%0A%2F%2F%20%3D%3E%20%7Babc%3A%20%7Bid%3A%20'abc'%2C%20title%3A%20'B'%7D%2C%20xyz%3A%20%7Bid%3A%20'xyz'%2C%20title%3A%20'A'%7D%7D">Try this <strong>R.indexBy</strong> example in Rambda REPL</a>
|
|
4931
5143
|
|
|
4932
5144
|
<details>
|
|
4933
5145
|
|
|
@@ -5029,7 +5241,7 @@ const result = [
|
|
|
5029
5241
|
// => [0, 1]
|
|
5030
5242
|
```
|
|
5031
5243
|
|
|
5032
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5244
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.indexOf(%7Ba%3A1%7D)(%5B%7Ba%3A1%7D%2C%20%7Ba%3A2%7D%5D)%2C%0A%20%20R.indexOf(2)(%5B1%2C%202%2C%203%5D)%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B0%2C%201%5D">Try this <strong>R.indexOf</strong> example in Rambda REPL</a>
|
|
5033
5245
|
|
|
5034
5246
|
<details>
|
|
5035
5247
|
|
|
@@ -5129,7 +5341,7 @@ const result = [
|
|
|
5129
5341
|
// => [[1, 2], 'fo']
|
|
5130
5342
|
```
|
|
5131
5343
|
|
|
5132
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5344
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.init(%5B1%2C%202%2C%203%5D)%20%2C%0A%20%20R.init('foo')%20%20%2F%2F%20%3D%3E%20'fo'%0A%5D%0A%2F%2F%20%3D%3E%20%5B%5B1%2C%202%5D%2C%20'fo'%5D">Try this <strong>R.init</strong> example in Rambda REPL</a>
|
|
5133
5345
|
|
|
5134
5346
|
<details>
|
|
5135
5347
|
|
|
@@ -5215,130 +5427,6 @@ describe('R.init', () => {
|
|
|
5215
5427
|
|
|
5216
5428
|
[](#init)
|
|
5217
5429
|
|
|
5218
|
-
### innerJoin
|
|
5219
|
-
|
|
5220
|
-
```typescript
|
|
5221
|
-
|
|
5222
|
-
innerJoin<T1, T2>(
|
|
5223
|
-
pred: (a: T1, b: T2) => boolean,
|
|
5224
|
-
list1: T1[],
|
|
5225
|
-
): (list2: T2[]) => T1[]
|
|
5226
|
-
```
|
|
5227
|
-
|
|
5228
|
-
It returns a new list by applying a `predicate` function to all elements of `list1` and `list2` and keeping only these elements where `predicate` returns `true`.
|
|
5229
|
-
|
|
5230
|
-
```javascript
|
|
5231
|
-
const list1 = [1, 2, 3, 4, 5]
|
|
5232
|
-
const list2 = [4, 5, 6]
|
|
5233
|
-
const predicate = (x, y) => x >= y
|
|
5234
|
-
const result = R.innerJoin(predicate, list1)(list2)
|
|
5235
|
-
// => [4, 5]
|
|
5236
|
-
```
|
|
5237
|
-
|
|
5238
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20list1%20%3D%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%0Aconst%20list2%20%3D%20%5B4%2C%205%2C%206%5D%0Aconst%20predicate%20%3D%20(x%2C%20y)%20%3D%3E%20x%20%3E%3D%20y%0Aconst%20result%20%3D%20R.innerJoin(predicate%2C%20list1)(list2)%0A%2F%2F%20%3D%3E%20%5B4%2C%205%5D">Try this <strong>R.innerJoin</strong> example in Rambda REPL</a>
|
|
5239
|
-
|
|
5240
|
-
<details>
|
|
5241
|
-
|
|
5242
|
-
<summary>All TypeScript definitions</summary>
|
|
5243
|
-
|
|
5244
|
-
```typescript
|
|
5245
|
-
innerJoin<T1, T2>(
|
|
5246
|
-
pred: (a: T1, b: T2) => boolean,
|
|
5247
|
-
list1: T1[],
|
|
5248
|
-
): (list2: T2[]) => T1[];
|
|
5249
|
-
```
|
|
5250
|
-
|
|
5251
|
-
</details>
|
|
5252
|
-
|
|
5253
|
-
<details>
|
|
5254
|
-
|
|
5255
|
-
<summary><strong>R.innerJoin</strong> source</summary>
|
|
5256
|
-
|
|
5257
|
-
```javascript
|
|
5258
|
-
function _includesWith(pred, x, list) {
|
|
5259
|
-
let idx = 0
|
|
5260
|
-
const len = list.length
|
|
5261
|
-
|
|
5262
|
-
while (idx < len) {
|
|
5263
|
-
if (pred(x, list[idx])) {
|
|
5264
|
-
return true
|
|
5265
|
-
}
|
|
5266
|
-
|
|
5267
|
-
idx += 1
|
|
5268
|
-
}
|
|
5269
|
-
|
|
5270
|
-
return false
|
|
5271
|
-
}
|
|
5272
|
-
function _filter(fn, list) {
|
|
5273
|
-
let idx = 0
|
|
5274
|
-
const len = list.length
|
|
5275
|
-
const result = []
|
|
5276
|
-
|
|
5277
|
-
while (idx < len) {
|
|
5278
|
-
if (fn(list[idx])) {
|
|
5279
|
-
result[result.length] = list[idx]
|
|
5280
|
-
}
|
|
5281
|
-
|
|
5282
|
-
idx += 1
|
|
5283
|
-
}
|
|
5284
|
-
|
|
5285
|
-
return result
|
|
5286
|
-
}
|
|
5287
|
-
|
|
5288
|
-
export function innerJoin(pred, xs) {
|
|
5289
|
-
return ys => _filter(x => _includesWith(pred, x, ys), xs)
|
|
5290
|
-
}
|
|
5291
|
-
```
|
|
5292
|
-
|
|
5293
|
-
</details>
|
|
5294
|
-
|
|
5295
|
-
<details>
|
|
5296
|
-
|
|
5297
|
-
<summary><strong>Tests</strong></summary>
|
|
5298
|
-
|
|
5299
|
-
```javascript
|
|
5300
|
-
import { innerJoin } from './innerJoin.js'
|
|
5301
|
-
|
|
5302
|
-
const a = {
|
|
5303
|
-
id: 1,
|
|
5304
|
-
name: 'a',
|
|
5305
|
-
}
|
|
5306
|
-
const b = {
|
|
5307
|
-
id: 2,
|
|
5308
|
-
name: 'b',
|
|
5309
|
-
}
|
|
5310
|
-
const c = {
|
|
5311
|
-
id: 3,
|
|
5312
|
-
name: 'c',
|
|
5313
|
-
}
|
|
5314
|
-
const f = (a, b) => innerJoin((r, id) => r.id === id, a)(b)
|
|
5315
|
-
|
|
5316
|
-
test('only returns elements from the first list', () => {
|
|
5317
|
-
expect(f([a, b, c], [])).toEqual([])
|
|
5318
|
-
expect(f([a, b, c], [1])).toEqual([a])
|
|
5319
|
-
expect(f([a, b, c], [1, 2])).toEqual([a, b])
|
|
5320
|
-
expect(f([a, b, c], [1, 2, 3])).toEqual([a, b, c])
|
|
5321
|
-
expect(f([a, b, c], [1, 2, 3, 4])).toEqual([a, b, c])
|
|
5322
|
-
})
|
|
5323
|
-
|
|
5324
|
-
test('does not remove duplicates', () => {
|
|
5325
|
-
expect(f([a, a, a], [1, 2, 3])).toEqual([a, a, a])
|
|
5326
|
-
expect(f([a, b, c], [1, 1, 1])).toEqual([a])
|
|
5327
|
-
})
|
|
5328
|
-
|
|
5329
|
-
test('readme example', () => {
|
|
5330
|
-
const list1 = [1, 2, 3, 4, 5]
|
|
5331
|
-
const list2 = [4, 5, 6]
|
|
5332
|
-
const predicate = (x, y) => x >= y
|
|
5333
|
-
const result = innerJoin(predicate, list1)(list2)
|
|
5334
|
-
expect(result).toEqual([4, 5])
|
|
5335
|
-
})
|
|
5336
|
-
```
|
|
5337
|
-
|
|
5338
|
-
</details>
|
|
5339
|
-
|
|
5340
|
-
[](#innerJoin)
|
|
5341
|
-
|
|
5342
5430
|
### interpolate
|
|
5343
5431
|
|
|
5344
5432
|
```typescript
|
|
@@ -5357,7 +5445,7 @@ const expected = 'foo is BAR even 1 more'
|
|
|
5357
5445
|
// => `result` is equal to `expected`
|
|
5358
5446
|
```
|
|
5359
5447
|
|
|
5360
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5448
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20inputWithTags%20%3D%20'foo%20is%20%7B%7Bbar%7D%7D%20even%20%7B%7Ba%7D%7D%20more'%0Aconst%20templateArguments%20%3D%20%7B%22bar%22%3A%22BAR%22%2C%20a%3A%201%7D%0A%0Aconst%20result%20%3D%20R.interpolate(inputWithTags%2C%20templateArguments)%0Aconst%20expected%20%3D%20'foo%20is%20BAR%20even%201%20more'%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.interpolate</strong> example in Rambda REPL</a>
|
|
5361
5449
|
|
|
5362
5450
|
<details>
|
|
5363
5451
|
|
|
@@ -5456,8 +5544,6 @@ intersection<T>(listA: T[]): (listB: T[]) => T[]
|
|
|
5456
5544
|
|
|
5457
5545
|
It loops through `listA` and `listB` and returns the intersection of the two according to `R.equals`.
|
|
5458
5546
|
|
|
5459
|
-
> :boom: There is slight difference between Rambda and Ramda implementation. Ramda.intersection(['a', 'b', 'c'], ['c', 'b']) result is "[ 'c', 'b' ]", but Rambda result is "[ 'b', 'c' ]".
|
|
5460
|
-
|
|
5461
5547
|
```javascript
|
|
5462
5548
|
const listA = [ { id : 1 }, { id : 2 }, { id : 3 }, { id : 4 } ]
|
|
5463
5549
|
const listB = [ { id : 3 }, { id : 4 }, { id : 5 }, { id : 6 } ]
|
|
@@ -5466,7 +5552,7 @@ const result = R.intersection(listA)(listB)
|
|
|
5466
5552
|
// => [{ id : 3 }, { id : 4 }]
|
|
5467
5553
|
```
|
|
5468
5554
|
|
|
5469
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5555
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20listA%20%3D%20%5B%20%7B%20id%20%3A%201%20%7D%2C%20%7B%20id%20%3A%202%20%7D%2C%20%7B%20id%20%3A%203%20%7D%2C%20%7B%20id%20%3A%204%20%7D%20%5D%0Aconst%20listB%20%3D%20%5B%20%7B%20id%20%3A%203%20%7D%2C%20%7B%20id%20%3A%204%20%7D%2C%20%7B%20id%20%3A%205%20%7D%2C%20%7B%20id%20%3A%206%20%7D%20%5D%0A%0Aconst%20result%20%3D%20R.intersection(listA)(listB)%0A%2F%2F%20%3D%3E%20%5B%7B%20id%20%3A%203%20%7D%2C%20%7B%20id%20%3A%204%20%7D%5D">Try this <strong>R.intersection</strong> example in Rambda REPL</a>
|
|
5470
5556
|
|
|
5471
5557
|
<details>
|
|
5472
5558
|
|
|
@@ -5480,14 +5566,143 @@ intersection<T>(listA: T[]): (listB: T[]) => T[];
|
|
|
5480
5566
|
|
|
5481
5567
|
<details>
|
|
5482
5568
|
|
|
5483
|
-
<summary><strong>R.intersection</strong> source</summary>
|
|
5569
|
+
<summary><strong>R.intersection</strong> source</summary>
|
|
5570
|
+
|
|
5571
|
+
```javascript
|
|
5572
|
+
import { filter } from './filter.js'
|
|
5573
|
+
import { includes } from './includes.js'
|
|
5574
|
+
|
|
5575
|
+
export function intersection(listA) {
|
|
5576
|
+
return listB => filter(x => includes(x)(listA))(listB)
|
|
5577
|
+
}
|
|
5578
|
+
```
|
|
5579
|
+
|
|
5580
|
+
</details>
|
|
5581
|
+
|
|
5582
|
+
<details>
|
|
5583
|
+
|
|
5584
|
+
<summary><strong>Tests</strong></summary>
|
|
5585
|
+
|
|
5586
|
+
```javascript
|
|
5587
|
+
import { intersection } from './intersection.js'
|
|
5588
|
+
|
|
5589
|
+
test('intersection', () => {
|
|
5590
|
+
const list1 = [1, 2, 3, 4]
|
|
5591
|
+
const list2 = [3, 4, 5, 6]
|
|
5592
|
+
expect(intersection(list1)(list2)).toEqual([3, 4])
|
|
5593
|
+
expect(intersection([])([])).toEqual([])
|
|
5594
|
+
})
|
|
5595
|
+
|
|
5596
|
+
test('intersection with objects', () => {
|
|
5597
|
+
const list1 = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
|
|
5598
|
+
const list2 = [{ id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }]
|
|
5599
|
+
expect(intersection(list1)(list2)).toEqual([{ id: 3 }, { id: 4 }])
|
|
5600
|
+
})
|
|
5601
|
+
|
|
5602
|
+
test('order is the same as in Ramda', () => {
|
|
5603
|
+
const list = ['a', 'b', 'c', 'd']
|
|
5604
|
+
|
|
5605
|
+
expect(intersection(list)(['b', 'c'])).toEqual(['b', 'c'])
|
|
5606
|
+
expect(intersection(list)(['c', 'b'])).toEqual(['c', 'b'])
|
|
5607
|
+
})
|
|
5608
|
+
```
|
|
5609
|
+
|
|
5610
|
+
</details>
|
|
5611
|
+
|
|
5612
|
+
<details>
|
|
5613
|
+
|
|
5614
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
5615
|
+
|
|
5616
|
+
```typescript
|
|
5617
|
+
import { intersection } from 'rambda'
|
|
5618
|
+
|
|
5619
|
+
const list1 = [1, 2, 3]
|
|
5620
|
+
const list2 = [1, 3, 5]
|
|
5621
|
+
|
|
5622
|
+
describe('R.intersection', () => {
|
|
5623
|
+
it('happy', () => {
|
|
5624
|
+
const result = intersection(list1)(list2)
|
|
5625
|
+
result // $ExpectType number[]
|
|
5626
|
+
})
|
|
5627
|
+
})
|
|
5628
|
+
```
|
|
5629
|
+
|
|
5630
|
+
</details>
|
|
5631
|
+
|
|
5632
|
+
[](#intersection)
|
|
5633
|
+
|
|
5634
|
+
### intersectionWith
|
|
5635
|
+
|
|
5636
|
+
```typescript
|
|
5637
|
+
|
|
5638
|
+
intersectionWith<T1, T2>(
|
|
5639
|
+
pred: (a: T1, b: T2) => boolean,
|
|
5640
|
+
list1: T1[],
|
|
5641
|
+
): (list2: T2[]) => T1[]
|
|
5642
|
+
```
|
|
5643
|
+
|
|
5644
|
+
It returns a new list by applying a `predicate` function to all elements of `list1` and `list2` and keeping only these elements where `predicate` returns `true`.
|
|
5645
|
+
|
|
5646
|
+
```javascript
|
|
5647
|
+
const list1 = [1, 2, 3, 4, 5]
|
|
5648
|
+
const list2 = [4, 5, 6]
|
|
5649
|
+
const predicate = (x, y) => x >= y
|
|
5650
|
+
const result = R.intersectionWith(predicate, list1)(list2)
|
|
5651
|
+
// => [4, 5]
|
|
5652
|
+
```
|
|
5653
|
+
|
|
5654
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list1%20%3D%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%0Aconst%20list2%20%3D%20%5B4%2C%205%2C%206%5D%0Aconst%20predicate%20%3D%20(x%2C%20y)%20%3D%3E%20x%20%3E%3D%20y%0Aconst%20result%20%3D%20R.intersectionWith(predicate%2C%20list1)(list2)%0A%2F%2F%20%3D%3E%20%5B4%2C%205%5D">Try this <strong>R.intersectionWith</strong> example in Rambda REPL</a>
|
|
5655
|
+
|
|
5656
|
+
<details>
|
|
5657
|
+
|
|
5658
|
+
<summary>All TypeScript definitions</summary>
|
|
5659
|
+
|
|
5660
|
+
```typescript
|
|
5661
|
+
intersectionWith<T1, T2>(
|
|
5662
|
+
pred: (a: T1, b: T2) => boolean,
|
|
5663
|
+
list1: T1[],
|
|
5664
|
+
): (list2: T2[]) => T1[];
|
|
5665
|
+
```
|
|
5666
|
+
|
|
5667
|
+
</details>
|
|
5668
|
+
|
|
5669
|
+
<details>
|
|
5670
|
+
|
|
5671
|
+
<summary><strong>R.intersectionWith</strong> source</summary>
|
|
5672
|
+
|
|
5673
|
+
```javascript
|
|
5674
|
+
function _includesWith(pred, x, list) {
|
|
5675
|
+
let idx = 0
|
|
5676
|
+
const len = list.length
|
|
5677
|
+
|
|
5678
|
+
while (idx < len) {
|
|
5679
|
+
if (pred(x, list[idx])) {
|
|
5680
|
+
return true
|
|
5681
|
+
}
|
|
5682
|
+
|
|
5683
|
+
idx += 1
|
|
5684
|
+
}
|
|
5685
|
+
|
|
5686
|
+
return false
|
|
5687
|
+
}
|
|
5688
|
+
function _filter(fn, list) {
|
|
5689
|
+
let idx = 0
|
|
5690
|
+
const len = list.length
|
|
5691
|
+
const result = []
|
|
5692
|
+
|
|
5693
|
+
while (idx < len) {
|
|
5694
|
+
if (fn(list[idx])) {
|
|
5695
|
+
result[result.length] = list[idx]
|
|
5696
|
+
}
|
|
5697
|
+
|
|
5698
|
+
idx += 1
|
|
5699
|
+
}
|
|
5484
5700
|
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
import { includes } from './includes.js'
|
|
5701
|
+
return result
|
|
5702
|
+
}
|
|
5488
5703
|
|
|
5489
|
-
export function
|
|
5490
|
-
return
|
|
5704
|
+
export function intersectionWith(pred, xs) {
|
|
5705
|
+
return ys => _filter(x => _includesWith(pred, x, ys), xs)
|
|
5491
5706
|
}
|
|
5492
5707
|
```
|
|
5493
5708
|
|
|
@@ -5498,26 +5713,41 @@ export function intersection(listA) {
|
|
|
5498
5713
|
<summary><strong>Tests</strong></summary>
|
|
5499
5714
|
|
|
5500
5715
|
```javascript
|
|
5501
|
-
import {
|
|
5716
|
+
import { intersectionWith } from './intersectionWith.js'
|
|
5502
5717
|
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5718
|
+
const a = {
|
|
5719
|
+
id: 1,
|
|
5720
|
+
name: 'a',
|
|
5721
|
+
}
|
|
5722
|
+
const b = {
|
|
5723
|
+
id: 2,
|
|
5724
|
+
name: 'b',
|
|
5725
|
+
}
|
|
5726
|
+
const c = {
|
|
5727
|
+
id: 3,
|
|
5728
|
+
name: 'c',
|
|
5729
|
+
}
|
|
5730
|
+
const f = (a, b) => intersectionWith((r, id) => r.id === id, a)(b)
|
|
5509
5731
|
|
|
5510
|
-
test('
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
expect(
|
|
5732
|
+
test('only returns elements from the first list', () => {
|
|
5733
|
+
expect(f([a, b, c], [])).toEqual([])
|
|
5734
|
+
expect(f([a, b, c], [1])).toEqual([a])
|
|
5735
|
+
expect(f([a, b, c], [1, 2])).toEqual([a, b])
|
|
5736
|
+
expect(f([a, b, c], [1, 2, 3])).toEqual([a, b, c])
|
|
5737
|
+
expect(f([a, b, c], [1, 2, 3, 4])).toEqual([a, b, c])
|
|
5514
5738
|
})
|
|
5515
5739
|
|
|
5516
|
-
test('
|
|
5517
|
-
|
|
5740
|
+
test('does not remove duplicates', () => {
|
|
5741
|
+
expect(f([a, a, a], [1, 2, 3])).toEqual([a, a, a])
|
|
5742
|
+
expect(f([a, b, c], [1, 1, 1])).toEqual([a])
|
|
5743
|
+
})
|
|
5518
5744
|
|
|
5519
|
-
|
|
5520
|
-
|
|
5745
|
+
test('readme example', () => {
|
|
5746
|
+
const list1 = [1, 2, 3, 4, 5]
|
|
5747
|
+
const list2 = [4, 5, 6]
|
|
5748
|
+
const predicate = (x, y) => x >= y
|
|
5749
|
+
const result = intersectionWith(predicate, list1)(list2)
|
|
5750
|
+
expect(result).toEqual([4, 5])
|
|
5521
5751
|
})
|
|
5522
5752
|
```
|
|
5523
5753
|
|
|
@@ -5528,14 +5758,17 @@ test('order is the same as in Ramda', () => {
|
|
|
5528
5758
|
<summary><strong>TypeScript</strong> test</summary>
|
|
5529
5759
|
|
|
5530
5760
|
```typescript
|
|
5531
|
-
import {
|
|
5761
|
+
import { intersectionWith, pipe } from 'rambda'
|
|
5532
5762
|
|
|
5533
5763
|
const list1 = [1, 2, 3]
|
|
5534
5764
|
const list2 = [1, 3, 5]
|
|
5535
5765
|
|
|
5536
|
-
describe('R.
|
|
5766
|
+
describe('R.intersectionWith', () => {
|
|
5537
5767
|
it('happy', () => {
|
|
5538
|
-
const result =
|
|
5768
|
+
const result = pipe(
|
|
5769
|
+
list1,
|
|
5770
|
+
intersectionWith((x, y) => x === y, list2),
|
|
5771
|
+
)
|
|
5539
5772
|
result // $ExpectType number[]
|
|
5540
5773
|
})
|
|
5541
5774
|
})
|
|
@@ -5543,7 +5776,7 @@ describe('R.intersection', () => {
|
|
|
5543
5776
|
|
|
5544
5777
|
</details>
|
|
5545
5778
|
|
|
5546
|
-
[](#
|
|
5779
|
+
[](#intersectionWith)
|
|
5547
5780
|
|
|
5548
5781
|
### intersperse
|
|
5549
5782
|
|
|
@@ -5561,7 +5794,7 @@ const result = R.intersperse(separator)(list)
|
|
|
5561
5794
|
// => [0, 10, 1, 10, 2, 10, 3]
|
|
5562
5795
|
```
|
|
5563
5796
|
|
|
5564
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5797
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%200%2C%201%2C%202%2C%203%20%5D%0Aconst%20separator%20%3D%2010%0Aconst%20result%20%3D%20R.intersperse(separator)(list)%0A%2F%2F%20%3D%3E%20%5B0%2C%2010%2C%201%2C%2010%2C%202%2C%2010%2C%203%5D">Try this <strong>R.intersperse</strong> example in Rambda REPL</a>
|
|
5565
5798
|
|
|
5566
5799
|
<details>
|
|
5567
5800
|
|
|
@@ -5656,7 +5889,7 @@ It returns a string of all `list` instances joined with a `glue`.
|
|
|
5656
5889
|
R.join('-', [1, 2, 3]) // => '1-2-3'
|
|
5657
5890
|
```
|
|
5658
5891
|
|
|
5659
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5892
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.join('-'%2C%20%5B1%2C%202%2C%203%5D)%20%20%2F%2F%20%3D%3E%20'1-2-3'">Try this <strong>R.join</strong> example in Rambda REPL</a>
|
|
5660
5893
|
|
|
5661
5894
|
<details>
|
|
5662
5895
|
|
|
@@ -5721,7 +5954,7 @@ const result = [
|
|
|
5721
5954
|
// => [3, 'o']
|
|
5722
5955
|
```
|
|
5723
5956
|
|
|
5724
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
5957
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.last(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.last('foo')%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B3%2C%20'o'%5D">Try this <strong>R.last</strong> example in Rambda REPL</a>
|
|
5725
5958
|
|
|
5726
5959
|
<details>
|
|
5727
5960
|
|
|
@@ -5800,7 +6033,7 @@ const result = [
|
|
|
5800
6033
|
// => [4, -1]
|
|
5801
6034
|
```
|
|
5802
6035
|
|
|
5803
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
6036
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%2C%201%2C%202%2C%203%5D%0Aconst%20result%20%3D%20%5B%0A%20%20R.lastIndexOf(2)(list)%2C%0A%20%20R.lastIndexOf(4)(list)%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B4%2C%20-1%5D">Try this <strong>R.lastIndexOf</strong> example in Rambda REPL</a>
|
|
5804
6037
|
|
|
5805
6038
|
<details>
|
|
5806
6039
|
|
|
@@ -5903,7 +6136,7 @@ const result = R.map(fn)(iterable),
|
|
|
5903
6136
|
// => [2, 4]
|
|
5904
6137
|
```
|
|
5905
6138
|
|
|
5906
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
6139
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20fn%20%3D%20x%20%3D%3E%20x%20*%202%0A%0Aconst%20iterable%20%3D%20%5B1%2C%202%5D%0Aconst%20obj%20%3D%20%7Ba%3A%201%2C%20b%3A%202%7D%0A%0Aconst%20result%20%3D%20R.map(fn)(iterable)%2C%0A%2F%2F%20%3D%3E%20%5B2%2C%204%5D">Try this <strong>R.map</strong> example in Rambda REPL</a>
|
|
5907
6140
|
|
|
5908
6141
|
<details>
|
|
5909
6142
|
|
|
@@ -6022,7 +6255,7 @@ const result = await R.mapAsync(fn)([1, 2, 3])
|
|
|
6022
6255
|
// `result` resolves after 3 seconds to `[2, 3, 4]`
|
|
6023
6256
|
```
|
|
6024
6257
|
|
|
6025
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
6258
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?async%20function%20fn(x)%7B%0A%20%20await%20R.delay(1000)%0A%0A%20%20return%20x%2B1%0A%7D%0A%0Aconst%20result%20%3D%20await%20R.mapAsync(fn)(%5B1%2C%202%2C%203%5D)%0A%2F%2F%20%60result%60%20resolves%20after%203%20seconds%20to%20%60%5B2%2C%203%2C%204%5D%60">Try this <strong>R.mapAsync</strong> example in Rambda REPL</a>
|
|
6026
6259
|
|
|
6027
6260
|
<details>
|
|
6028
6261
|
|
|
@@ -6166,7 +6399,7 @@ const result = R.mapKeys(
|
|
|
6166
6399
|
// => { A1: 1, B2: 2 }
|
|
6167
6400
|
```
|
|
6168
6401
|
|
|
6169
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
6402
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.mapKeys(%0A%09(key%2C%20value)%20%3D%3E%20key.toUpperCase()%2Bvalue%0A%09)(%0A%09%7B%20a%3A%201%2C%20b%3A%202%20%7D%0A)%0A%2F%2F%20%3D%3E%20%7B%20A1%3A%201%2C%20B2%3A%202%20%7D">Try this <strong>R.mapKeys</strong> example in Rambda REPL</a>
|
|
6170
6403
|
|
|
6171
6404
|
<details>
|
|
6172
6405
|
|
|
@@ -6257,7 +6490,7 @@ const result = R.mapObject(fn)(obj)
|
|
|
6257
6490
|
// => {a: 'a-1', b: 'b-2'}
|
|
6258
6491
|
```
|
|
6259
6492
|
|
|
6260
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
6493
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20fn%20%3D%20(val%2C%20prop)%20%3D%3E%20%60%24%7Bprop%7D-%24%7Bval%7D%60%0Aconst%20obj%20%3D%20%7Ba%3A%201%2C%20b%3A%202%7D%0A%0Aconst%20result%20%3D%20R.mapObject(fn)(obj)%0A%2F%2F%20%3D%3E%20%7Ba%3A%20'a-1'%2C%20b%3A%20'b-2'%7D">Try this <strong>R.mapObject</strong> example in Rambda REPL</a>
|
|
6261
6494
|
|
|
6262
6495
|
<details>
|
|
6263
6496
|
|
|
@@ -6493,22 +6726,22 @@ it('R.mapObjectAsync', async () => {
|
|
|
6493
6726
|
```typescript
|
|
6494
6727
|
|
|
6495
6728
|
mapParallelAsync<T extends IterableContainer, U>(
|
|
6496
|
-
fn: (value: T[number]
|
|
6729
|
+
fn: (value: T[number]) => Promise<U>,
|
|
6730
|
+
batchSize?: number,
|
|
6497
6731
|
): (data: T) => Promise<Mapped<T, U>>
|
|
6498
6732
|
```
|
|
6499
6733
|
|
|
6500
6734
|
Wrapper around `Promise.all` for asynchronous mapping with `fn` over members of `list`.
|
|
6735
|
+
There is optional `batchSize` parameter to allow parallel execution to run in batches. In this case, the whole batch must complete before the next batch starts.
|
|
6501
6736
|
|
|
6502
6737
|
<details>
|
|
6503
6738
|
|
|
6504
6739
|
<summary>All TypeScript definitions</summary>
|
|
6505
6740
|
|
|
6506
6741
|
```typescript
|
|
6507
|
-
mapParallelAsync<T extends IterableContainer, U>(
|
|
6508
|
-
fn: (value: T[number], index: number) => Promise<U>,
|
|
6509
|
-
): (data: T) => Promise<Mapped<T, U>>;
|
|
6510
6742
|
mapParallelAsync<T extends IterableContainer, U>(
|
|
6511
6743
|
fn: (value: T[number]) => Promise<U>,
|
|
6744
|
+
batchSize?: number,
|
|
6512
6745
|
): (data: T) => Promise<Mapped<T, U>>;
|
|
6513
6746
|
```
|
|
6514
6747
|
|
|
@@ -6519,8 +6752,18 @@ mapParallelAsync<T extends IterableContainer, U>(
|
|
|
6519
6752
|
<summary><strong>R.mapParallelAsync</strong> source</summary>
|
|
6520
6753
|
|
|
6521
6754
|
```javascript
|
|
6522
|
-
export function mapParallelAsync(fn)
|
|
6523
|
-
|
|
6755
|
+
export function mapParallelAsync(fn, batchSize){
|
|
6756
|
+
if(!batchSize) return async list => Promise.all(list.map(fn))
|
|
6757
|
+
|
|
6758
|
+
return async list => {
|
|
6759
|
+
const result = []
|
|
6760
|
+
for(let i = 0; i < list.length; i += batchSize){
|
|
6761
|
+
const batch = list.slice(i, i + batchSize)
|
|
6762
|
+
const batchResult = await Promise.all(batch.map((x, j) => fn(x, i + j)))
|
|
6763
|
+
result.push(...batchResult)
|
|
6764
|
+
}
|
|
6765
|
+
return result
|
|
6766
|
+
}
|
|
6524
6767
|
}
|
|
6525
6768
|
```
|
|
6526
6769
|
|
|
@@ -6556,6 +6799,17 @@ test('pipeAsync', async () => {
|
|
|
6556
6799
|
)
|
|
6557
6800
|
expect(result).toEqual([ 2,3,4 ])
|
|
6558
6801
|
})
|
|
6802
|
+
|
|
6803
|
+
test('with batchSize', async () => {
|
|
6804
|
+
const fn = async (x, i) => {
|
|
6805
|
+
await delay(100)
|
|
6806
|
+
return `${x}:${i}`
|
|
6807
|
+
}
|
|
6808
|
+
const result = await mapParallelAsync(fn, 2)([1, 2, 3, 4, 5])
|
|
6809
|
+
expect(result).toEqual(
|
|
6810
|
+
['1:0', '2:1', '3:2', '4:3', '5:4']
|
|
6811
|
+
)
|
|
6812
|
+
})
|
|
6559
6813
|
```
|
|
6560
6814
|
|
|
6561
6815
|
</details>
|
|
@@ -6566,46 +6820,53 @@ test('pipeAsync', async () => {
|
|
|
6566
6820
|
|
|
6567
6821
|
```typescript
|
|
6568
6822
|
|
|
6569
|
-
mapPropObject<T extends object, K extends keyof T, Value>(
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6823
|
+
mapPropObject<T extends object, K extends keyof T, Value extends unknown>(
|
|
6824
|
+
prop: K,
|
|
6825
|
+
valueMapper: (
|
|
6826
|
+
listItem: T[K] extends ReadonlyArray<infer ElementType> ? ElementType : never,
|
|
6827
|
+
list: T[K] extends ReadonlyArray<any> ? T[K] : never,
|
|
6828
|
+
) => Value,
|
|
6575
6829
|
): (data: T) => T[K] extends ReadonlyArray<any>
|
|
6576
|
-
|
|
6577
|
-
|
|
6830
|
+
? MergeTypes<Omit<T, K> & { [P in K]: Value[] }>
|
|
6831
|
+
: never
|
|
6578
6832
|
```
|
|
6579
6833
|
|
|
6580
|
-
|
|
6834
|
+
Convenience method, when one needs to maps over a object property that is a list.
|
|
6581
6835
|
|
|
6582
6836
|
```javascript
|
|
6583
6837
|
const result = pipe(
|
|
6584
6838
|
{ a: [1,2,3], b: 'foo' },
|
|
6585
|
-
mapPropObject(x => {
|
|
6586
|
-
x // $ExpectType { a: number; b: string; }
|
|
6839
|
+
mapPropObject('a',x => {
|
|
6587
6840
|
return {
|
|
6588
6841
|
a: x,
|
|
6589
6842
|
flag: x > 2,
|
|
6590
6843
|
}
|
|
6591
|
-
}
|
|
6844
|
+
}),
|
|
6592
6845
|
)
|
|
6593
6846
|
// => { a: [{ a: 1, flag: false },{ a: 2, flag: false }, { a: 3, flag: true }], b: 'foo' }
|
|
6594
6847
|
```
|
|
6595
6848
|
|
|
6596
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
6849
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20pipe(%0A%09%7B%20a%3A%20%5B1%2C2%2C3%5D%2C%20b%3A%20'foo'%20%7D%2C%0A%09mapPropObject('a'%2Cx%20%3D%3E%20%7B%0A%09%09return%20%7B%0A%09%09%09a%3A%20x%2C%0A%09%09%09flag%3A%20x%20%3E%202%2C%0A%09%09%7D%0A%09%7D)%2C%0A)%0A%2F%2F%20%3D%3E%20%7B%20a%3A%20%5B%7B%20a%3A%201%2C%20flag%3A%20false%20%7D%2C%7B%20a%3A%202%2C%20flag%3A%20false%20%7D%2C%20%7B%20a%3A%203%2C%20flag%3A%20true%20%7D%5D%2C%20b%3A%20'foo'%20%7D">Try this <strong>R.mapPropObject</strong> example in Rambda REPL</a>
|
|
6597
6850
|
|
|
6598
6851
|
<details>
|
|
6599
6852
|
|
|
6600
6853
|
<summary>All TypeScript definitions</summary>
|
|
6601
6854
|
|
|
6602
6855
|
```typescript
|
|
6603
|
-
mapPropObject<T extends object, K extends keyof T, Value>(
|
|
6856
|
+
mapPropObject<T extends object, K extends keyof T, Value extends unknown>(
|
|
6857
|
+
prop: K,
|
|
6858
|
+
valueMapper: (
|
|
6859
|
+
listItem: T[K] extends ReadonlyArray<infer ElementType> ? ElementType : never,
|
|
6860
|
+
list: T[K] extends ReadonlyArray<any> ? T[K] : never,
|
|
6861
|
+
) => Value,
|
|
6862
|
+
): (data: T) => T[K] extends ReadonlyArray<any>
|
|
6863
|
+
? MergeTypes<Omit<T, K> & { [P in K]: Value[] }>
|
|
6864
|
+
: never;
|
|
6865
|
+
mapPropObject<T extends object, K extends keyof T, Value extends unknown>(
|
|
6866
|
+
prop: K,
|
|
6604
6867
|
valueMapper: (
|
|
6605
|
-
|
|
6606
|
-
data: T[K],
|
|
6868
|
+
listItem: T[K] extends ReadonlyArray<infer ElementType> ? ElementType : never,
|
|
6607
6869
|
) => Value,
|
|
6608
|
-
prop: K,
|
|
6609
6870
|
): (data: T) => T[K] extends ReadonlyArray<any>
|
|
6610
6871
|
? MergeTypes<Omit<T, K> & { [P in K]: Value[] }>
|
|
6611
6872
|
: never;
|
|
@@ -6664,24 +6925,52 @@ it('happy', () => {
|
|
|
6664
6925
|
<summary><strong>TypeScript</strong> test</summary>
|
|
6665
6926
|
|
|
6666
6927
|
```typescript
|
|
6667
|
-
import { mapPropObject, pipe } from 'rambda'
|
|
6928
|
+
import { map, mapPropObject, pipe } from 'rambda'
|
|
6668
6929
|
|
|
6669
6930
|
describe('R.mapPropObject', () => {
|
|
6670
6931
|
it('iterable with one arguments', () => {
|
|
6671
6932
|
const result = pipe(
|
|
6672
6933
|
{ a: [1,2,3], b: 'foo' },
|
|
6673
|
-
mapPropObject(x => {
|
|
6934
|
+
mapPropObject('a', x => {
|
|
6674
6935
|
x // $ExpectType number
|
|
6675
6936
|
return {
|
|
6676
6937
|
a: x,
|
|
6677
6938
|
flag: x > 2,
|
|
6678
6939
|
}
|
|
6679
|
-
}
|
|
6940
|
+
}),
|
|
6680
6941
|
)
|
|
6681
6942
|
|
|
6682
6943
|
result.a // $ExpectType { a: number; flag: boolean; }[]
|
|
6683
6944
|
result.b // $ExpectType string
|
|
6684
6945
|
})
|
|
6946
|
+
|
|
6947
|
+
it('iterable with two arguments', () => {
|
|
6948
|
+
const result = pipe(
|
|
6949
|
+
{ a: [1,2,3], b: 'foo' },
|
|
6950
|
+
mapPropObject('a', (x, list) => {
|
|
6951
|
+
x // $ExpectType number
|
|
6952
|
+
list // $ExpectType number[]
|
|
6953
|
+
return list.length
|
|
6954
|
+
}),
|
|
6955
|
+
)
|
|
6956
|
+
result.a // $ExpectType number[]
|
|
6957
|
+
result.b // $ExpectType string
|
|
6958
|
+
})
|
|
6959
|
+
|
|
6960
|
+
it('more complex example', () => {
|
|
6961
|
+
const result = pipe(
|
|
6962
|
+
[{a:[true, false, true], b: 'foo'}],
|
|
6963
|
+
map(
|
|
6964
|
+
mapPropObject( 'a',(a) => {
|
|
6965
|
+
a // $ExpectType boolean
|
|
6966
|
+
return {a, b: 2}
|
|
6967
|
+
})
|
|
6968
|
+
)
|
|
6969
|
+
)
|
|
6970
|
+
|
|
6971
|
+
result[0].a[0].a // $ExpectType boolean
|
|
6972
|
+
result[0].a[0].b // $ExpectType number
|
|
6973
|
+
})
|
|
6685
6974
|
})
|
|
6686
6975
|
```
|
|
6687
6976
|
|
|
@@ -6706,7 +6995,7 @@ const result = [
|
|
|
6706
6995
|
// => [[], ['ba', 'na', 'na']]
|
|
6707
6996
|
```
|
|
6708
6997
|
|
|
6709
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
6998
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.match('a'%2C%20'foo')%2C%0A%20%20R.match(%2F(%5Ba-z%5Da)%2Fg%2C%20'bananas')%0A%5D%0A%2F%2F%20%3D%3E%20%5B%5B%5D%2C%20%5B'ba'%2C%20'na'%2C%20'na'%5D%5D">Try this <strong>R.match</strong> example in Rambda REPL</a>
|
|
6710
6999
|
|
|
6711
7000
|
<details>
|
|
6712
7001
|
|
|
@@ -6792,7 +7081,7 @@ const compareFn = Math.abs
|
|
|
6792
7081
|
R.maxBy(compareFn, 5, -7) // => -7
|
|
6793
7082
|
```
|
|
6794
7083
|
|
|
6795
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7084
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20compareFn%20%3D%20Math.abs%0A%0Aconst%20result%20%3D%20R.maxBy(compareFn%2C%205%2C%20-7)%20%2F%2F%20%3D%3E%20-7">Try this <strong>R.maxBy</strong> example in Rambda REPL</a>
|
|
6796
7085
|
|
|
6797
7086
|
<details>
|
|
6798
7087
|
|
|
@@ -6975,7 +7264,7 @@ const compareFn = Math.abs
|
|
|
6975
7264
|
R.minBy(compareFn, -5, 2) // => -5
|
|
6976
7265
|
```
|
|
6977
7266
|
|
|
6978
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7267
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20compareFn%20%3D%20Math.abs%0A%0Aconst%20result%20%3D%20R.minBy(compareFn%2C%20-5%2C%202)%20%2F%2F%20%3D%3E%20-5">Try this <strong>R.minBy</strong> example in Rambda REPL</a>
|
|
6979
7268
|
|
|
6980
7269
|
<details>
|
|
6981
7270
|
|
|
@@ -7032,7 +7321,7 @@ const result = R.pipe(
|
|
|
7032
7321
|
) // => [1, 3, 3]
|
|
7033
7322
|
```
|
|
7034
7323
|
|
|
7035
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7324
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pipe(%0A%09%5B1%2C%202%2C%203%5D%2C%0A%09R.modifyItemAtIndex(1%2C%20x%20%3D%3E%20x%20%2B%201)%0A)%20%2F%2F%20%3D%3E%20%5B1%2C%203%2C%203%5D">Try this <strong>R.modifyItemAtIndex</strong> example in Rambda REPL</a>
|
|
7036
7325
|
|
|
7037
7326
|
<details>
|
|
7038
7327
|
|
|
@@ -7113,7 +7402,7 @@ const result = R.modifyPath('a.b.c', x=> x+1, {a:{b: {c:1}}})
|
|
|
7113
7402
|
// => {a:{b: {c:2}}}
|
|
7114
7403
|
```
|
|
7115
7404
|
|
|
7116
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7405
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.modifyPath('a.b.c'%2C%20x%3D%3E%20x%2B1%2C%20%7Ba%3A%7Bb%3A%20%7Bc%3A1%7D%7D%7D)%0A%2F%2F%20%3D%3E%20%7Ba%3A%7Bb%3A%20%7Bc%3A2%7D%7D%7D">Try this <strong>R.modifyPath</strong> example in Rambda REPL</a>
|
|
7117
7406
|
|
|
7118
7407
|
<details>
|
|
7119
7408
|
|
|
@@ -7256,7 +7545,7 @@ const result = R.modifyProp('age', x => x + 1)(person)
|
|
|
7256
7545
|
// => {name: 'foo', age: 21}
|
|
7257
7546
|
```
|
|
7258
7547
|
|
|
7259
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7548
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20person%20%3D%20%7B%0A%20%20name%20%3A%20'foo'%2C%0A%20%20age%20%20%3A%2020%2C%0A%7D%0Aconst%20result%20%3D%20R.modifyProp('age'%2C%20x%20%3D%3E%20x%20%2B%201)(person)%0A%2F%2F%20%3D%3E%20%7Bname%3A%20'foo'%2C%20age%3A%2021%7D">Try this <strong>R.modifyProp</strong> example in Rambda REPL</a>
|
|
7260
7549
|
|
|
7261
7550
|
<details>
|
|
7262
7551
|
|
|
@@ -7379,7 +7668,7 @@ const result = R.none(predicate)(arr)
|
|
|
7379
7668
|
// => true
|
|
7380
7669
|
```
|
|
7381
7670
|
|
|
7382
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7671
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%200%2C%201%2C%202%2C%203%2C%204%20%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%206%0A%0Aconst%20result%20%3D%20R.none(predicate)(arr)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.none</strong> example in Rambda REPL</a>
|
|
7383
7672
|
|
|
7384
7673
|
<details>
|
|
7385
7674
|
|
|
@@ -7475,7 +7764,7 @@ const result = objectIncludes(specification)(input)
|
|
|
7475
7764
|
// => true
|
|
7476
7765
|
```
|
|
7477
7766
|
|
|
7478
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7767
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20specification%20%3D%20%7B%20a%20%3A%20%7B%20b%20%3A%201%20%7D%20%7D%0Aconst%20input%20%3D%20%7B%0A%20%20a%20%3A%20%7B%20b%20%3A%201%20%7D%2C%0A%20%20c%20%3A%202%0A%7D%0A%0Aconst%20result%20%3D%20objectIncludes(specification)(input)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.objectIncludes</strong> example in Rambda REPL</a>
|
|
7479
7768
|
|
|
7480
7769
|
<details>
|
|
7481
7770
|
|
|
@@ -7599,7 +7888,7 @@ const result = R.objOf('foo')('bar')
|
|
|
7599
7888
|
// => {foo: 'bar'}
|
|
7600
7889
|
```
|
|
7601
7890
|
|
|
7602
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7891
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.objOf('foo')('bar')%0A%2F%2F%20%3D%3E%20%7Bfoo%3A%20'bar'%7D">Try this <strong>R.objOf</strong> example in Rambda REPL</a>
|
|
7603
7892
|
|
|
7604
7893
|
<details>
|
|
7605
7894
|
|
|
@@ -7685,7 +7974,7 @@ const result = [
|
|
|
7685
7974
|
// => [{b: 2}, {b: 2}]
|
|
7686
7975
|
```
|
|
7687
7976
|
|
|
7688
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
7977
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj%20%3D%20%7Ba%3A%201%2C%20b%3A%202%2C%20c%3A%203%7D%0Aconst%20propsToOmit%20%3D%20'a%2Cc%2Cd'%0Aconst%20propsToOmitList%20%3D%20%5B'a'%2C%20'c'%2C%20'd'%5D%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.omit(propsToOmit%2C%20obj)%2C%0A%20%20R.omit(propsToOmitList%2C%20obj)%0A%5D%0A%2F%2F%20%3D%3E%20%5B%7Bb%3A%202%7D%2C%20%7Bb%3A%202%7D%5D">Try this <strong>R.omit</strong> example in Rambda REPL</a>
|
|
7689
7978
|
|
|
7690
7979
|
<details>
|
|
7691
7980
|
|
|
@@ -7827,7 +8116,7 @@ const expected = [[3], [1, 2]]
|
|
|
7827
8116
|
// `result` is equal to `expected`
|
|
7828
8117
|
```
|
|
7829
8118
|
|
|
7830
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
8119
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%202%0A%0Aconst%20result%20%3D%20R.partition(predicate)(list)%0A%0Aconst%20expected%20%3D%20%5B%5B3%5D%2C%20%5B1%2C%202%5D%5D%0A%2F%2F%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.partition</strong> example in Rambda REPL</a>
|
|
7831
8120
|
|
|
7832
8121
|
<details>
|
|
7833
8122
|
|
|
@@ -7952,7 +8241,7 @@ const expected = [{c: 3}, {a: 1, b: 2}]
|
|
|
7952
8241
|
// `result` is equal to `expected`
|
|
7953
8242
|
```
|
|
7954
8243
|
|
|
7955
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
8244
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj%20%3D%20%7Ba%3A%201%2C%20b%3A%202%2C%20c%3A%203%7D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%202%0A%0Aconst%20result%20%3D%20R.partition(predicate)(obj)%0A%0Aconst%20expected%20%3D%20%5B%7Bc%3A%203%7D%2C%20%20%7Ba%3A%201%2C%20b%3A%202%7D%5D%0A%2F%2F%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.partitionObject</strong> example in Rambda REPL</a>
|
|
7956
8245
|
|
|
7957
8246
|
<details>
|
|
7958
8247
|
|
|
@@ -8096,7 +8385,7 @@ const result = [
|
|
|
8096
8385
|
// => [1, 1, undefined]
|
|
8097
8386
|
```
|
|
8098
8387
|
|
|
8099
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
8388
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj%20%3D%20%7Ba%3A%20%7Bb%3A%201%7D%7D%0Aconst%20pathToSearch%20%3D%20'a.b'%0Aconst%20pathToSearchList%20%3D%20%5B'a'%2C%20'b'%5D%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.path(pathToSearch%2C%20obj)%2C%0A%20%20R.path(pathToSearchList%2C%20obj)%2C%0A%20%20R.path('a.b.c.d'%2C%20obj)%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%201%2C%20undefined%5D">Try this <strong>R.path</strong> example in Rambda REPL</a>
|
|
8100
8389
|
|
|
8101
8390
|
<details>
|
|
8102
8391
|
|
|
@@ -8252,7 +8541,7 @@ const result = R.pathSatisfies(
|
|
|
8252
8541
|
// => true
|
|
8253
8542
|
```
|
|
8254
8543
|
|
|
8255
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
8544
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pathSatisfies(%0A%20%20x%20%3D%3E%20x%20%3E%200%2C%0A%20%20%5B'a'%2C%20'b'%2C%20'c'%5D%2C%0A%20%20%7Ba%3A%20%7Bb%3A%20%7Bc%3A%201%7D%7D%7D%0A)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.pathSatisfies</strong> example in Rambda REPL</a>
|
|
8256
8545
|
|
|
8257
8546
|
<details>
|
|
8258
8547
|
|
|
@@ -8372,7 +8661,7 @@ const result = R.permutations(
|
|
|
8372
8661
|
// => [[1, 2], [2, 1]]
|
|
8373
8662
|
```
|
|
8374
8663
|
|
|
8375
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
8664
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.permutations(%0A%09%5B1%2C%202%5D%0A)%0A%2F%2F%20%3D%3E%20%5B%5B1%2C%202%5D%2C%20%5B2%2C%201%5D%5D">Try this <strong>R.permutations</strong> example in Rambda REPL</a>
|
|
8376
8665
|
|
|
8377
8666
|
<details>
|
|
8378
8667
|
|
|
@@ -8475,7 +8764,7 @@ const expected = [
|
|
|
8475
8764
|
// => `result` is equal to `expected`
|
|
8476
8765
|
```
|
|
8477
8766
|
|
|
8478
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
8767
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj%20%3D%20%7B%0A%20%20a%20%3A%201%2C%0A%20%20b%20%3A%20false%2C%0A%20%20foo%3A%20'cherry'%0A%7D%0Aconst%20propsToPick%20%3D%20'a%2Cfoo'%0Aconst%20propsToPickList%20%3D%20%5B'a'%2C%20'foo'%5D%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.pick(propsToPick)(obj)%2C%0A%20%20R.pick(propsToPickList)(obj)%2C%0A%20%20R.pick('a%2Cbar')(obj)%2C%0A%20%20R.pick('bar')(obj)%2C%0A%5D%0A%0Aconst%20expected%20%3D%20%5B%0A%20%20%7Ba%3A1%2C%20foo%3A%20'cherry'%7D%2C%0A%20%20%7Ba%3A1%2C%20foo%3A%20'cherry'%7D%2C%0A%20%20%7Ba%3A1%7D%2C%0A%20%20%7B%7D%2C%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.pick</strong> example in Rambda REPL</a>
|
|
8479
8768
|
|
|
8480
8769
|
<details>
|
|
8481
8770
|
|
|
@@ -8614,7 +8903,7 @@ const result = R.pipe(
|
|
|
8614
8903
|
// => [20, 30]
|
|
8615
8904
|
```
|
|
8616
8905
|
|
|
8617
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
8906
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pipe(%0A%20%20%5B1%2C%202%2C%203%5D%2C%0A%20%20R.filter(x%20%3D%3E%20x%20%3E%201)%2C%0A%20%20R.map(x%20%3D%3E%20x*10)%2C%0A)%0A%2F%2F%20%3D%3E%20%5B20%2C%2030%5D">Try this <strong>R.pipe</strong> example in Rambda REPL</a>
|
|
8618
8907
|
|
|
8619
8908
|
<details>
|
|
8620
8909
|
|
|
@@ -8967,7 +9256,7 @@ const result = await R.pipeAsync(
|
|
|
8967
9256
|
// `result` resolves to `RAMBDAX_DELAY104`
|
|
8968
9257
|
```
|
|
8969
9258
|
|
|
8970
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
9259
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20await%20R.pipeAsync(%0A%20%20100%2C%0A%20%20async%20x%20%3D%3E%20%7B%0A%20%20%20%20await%20R.delay(100)%0A%20%20%20%20return%20x%20%2B%202%0A%20%20%7D%2C%0A%20%20x%20%3D%3E%20x%20%2B2%2C%0A%20%20async%20x%20%3D%3E%20%7B%0A%20%20%20%20const%20delayed%20%3D%20await%20R.delay(100)%0A%20%20%20%20return%20delayed%20%2B%20x%0A%20%20%7D%0A)%0A%2F%2F%20%60result%60%20resolves%20to%20%60RAMBDAX_DELAY104%60">Try this <strong>R.pipeAsync</strong> example in Rambda REPL</a>
|
|
8971
9260
|
|
|
8972
9261
|
<details>
|
|
8973
9262
|
|
|
@@ -9083,7 +9372,7 @@ const result = R.pluck(property)(list)
|
|
|
9083
9372
|
// => [1, 2]
|
|
9084
9373
|
```
|
|
9085
9374
|
|
|
9086
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
9375
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%2C%20%7Bb%3A%203%7D%5D%0Aconst%20property%20%3D%20'a'%0A%0Aconst%20result%20%3D%20R.pluck(property)(list)%0A%2F%2F%20%3D%3E%20%5B1%2C%202%5D">Try this <strong>R.pluck</strong> example in Rambda REPL</a>
|
|
9087
9376
|
|
|
9088
9377
|
<details>
|
|
9089
9378
|
|
|
@@ -9189,7 +9478,7 @@ const result = R.prepend('foo', ['bar', 'baz'])
|
|
|
9189
9478
|
// => ['foo', 'bar', 'baz']
|
|
9190
9479
|
```
|
|
9191
9480
|
|
|
9192
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
9481
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.prepend('foo'%2C%20%5B'bar'%2C%20'baz'%5D)%0A%2F%2F%20%3D%3E%20%5B'foo'%2C%20'bar'%2C%20'baz'%5D">Try this <strong>R.prepend</strong> example in Rambda REPL</a>
|
|
9193
9482
|
|
|
9194
9483
|
<details>
|
|
9195
9484
|
|
|
@@ -9253,7 +9542,7 @@ const result = [
|
|
|
9253
9542
|
// => [100, undefined]
|
|
9254
9543
|
```
|
|
9255
9544
|
|
|
9256
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
9545
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.prop('x')(%7Bx%3A%20100%7D)%2C%0A%20%20R.prop('x')(%7Ba%3A%201%7D)%0A%5D%0A%2F%2F%20%3D%3E%20%5B100%2C%20undefined%5D">Try this <strong>R.prop</strong> example in Rambda REPL</a>
|
|
9257
9546
|
|
|
9258
9547
|
<details>
|
|
9259
9548
|
|
|
@@ -9327,7 +9616,7 @@ const result = [
|
|
|
9327
9616
|
// => [true, false]
|
|
9328
9617
|
```
|
|
9329
9618
|
|
|
9330
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
9619
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj%20%3D%20%7B%20foo%3A%20'bar'%20%7D%0Aconst%20secondObj%20%3D%20%7B%20foo%3A%201%20%7D%0A%0Aconst%20propToFind%20%3D%20'foo'%0Aconst%20valueToMatch%20%3D%20'bar'%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.propEq(propToFind%2C%20valueToMatch)(obj)%2C%0A%20%20R.propEq(propToFind%2C%20valueToMatch)(secondObj)%0A%5D%0A%2F%2F%20%3D%3E%20%5Btrue%2C%20false%5D">Try this <strong>R.propEq</strong> example in Rambda REPL</a>
|
|
9331
9620
|
|
|
9332
9621
|
<details>
|
|
9333
9622
|
|
|
@@ -9413,7 +9702,7 @@ const result = [
|
|
|
9413
9702
|
// => [1, 'DEFAULT_VALUE']
|
|
9414
9703
|
```
|
|
9415
9704
|
|
|
9416
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
9705
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj%20%3D%20%7Ba%3A%201%7D%0Aconst%20defaultValue%20%3D%20'DEFAULT_VALUE'%0Aconst%20property%20%3D%20'a'%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.propOr(defaultValue%2C%20property)(obj)%2C%0A%20%20R.propOr(defaultValue%2C%20'foo')(obj)%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%20'DEFAULT_VALUE'%5D">Try this <strong>R.propOr</strong> example in Rambda REPL</a>
|
|
9417
9706
|
|
|
9418
9707
|
<details>
|
|
9419
9708
|
|
|
@@ -9501,7 +9790,7 @@ const result = R.propSatisfies(predicate, property, obj)
|
|
|
9501
9790
|
// => true
|
|
9502
9791
|
```
|
|
9503
9792
|
|
|
9504
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
9793
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj%20%3D%20%7Ba%3A%20%7Bb%3A1%7D%7D%0Aconst%20property%20%3D%20'a'%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%3F.b%20%3D%3D%3D%201%0A%0Aconst%20result%20%3D%20R.propSatisfies(predicate%2C%20property%2C%20obj)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.propSatisfies</strong> example in Rambda REPL</a>
|
|
9505
9794
|
|
|
9506
9795
|
<details>
|
|
9507
9796
|
|
|
@@ -9577,25 +9866,25 @@ describe('R.propSatisfies', () => {
|
|
|
9577
9866
|
|
|
9578
9867
|
```typescript
|
|
9579
9868
|
|
|
9580
|
-
range(
|
|
9869
|
+
range(endInclusive: number) : number[]
|
|
9581
9870
|
```
|
|
9582
9871
|
|
|
9583
|
-
It returns list of numbers between `startInclusive` to `
|
|
9584
|
-
If `start` is greater than `end`, then the result will be in descending order.
|
|
9872
|
+
It returns list of numbers between `startInclusive` to `endInclusive` markers.
|
|
9585
9873
|
|
|
9586
9874
|
```javascript
|
|
9587
|
-
[R.range(
|
|
9588
|
-
// => [[0, 1, 2, 3, 4], [
|
|
9875
|
+
[R.range(5), R.range(1, 5)]
|
|
9876
|
+
// => [[0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]
|
|
9589
9877
|
```
|
|
9590
9878
|
|
|
9591
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
9879
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5BR.range(5)%2C%20R.range(1%2C%205)%5D%0A%2F%2F%20%3D%3E%20%5B%5B0%2C%201%2C%202%2C%203%2C%204%2C%205%5D%2C%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%5D">Try this <strong>R.range</strong> example in Rambda REPL</a>
|
|
9592
9880
|
|
|
9593
9881
|
<details>
|
|
9594
9882
|
|
|
9595
9883
|
<summary>All TypeScript definitions</summary>
|
|
9596
9884
|
|
|
9597
9885
|
```typescript
|
|
9598
|
-
range(
|
|
9886
|
+
range(endInclusive: number) : number[];
|
|
9887
|
+
range(startInclusive: number, endInclusive: number) : number[];
|
|
9599
9888
|
```
|
|
9600
9889
|
|
|
9601
9890
|
</details>
|
|
@@ -9605,37 +9894,14 @@ range(startInclusive: number): (endExclusive: number) => number[];
|
|
|
9605
9894
|
<summary><strong>R.range</strong> source</summary>
|
|
9606
9895
|
|
|
9607
9896
|
```javascript
|
|
9608
|
-
function
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
willReturn[i] = start - i
|
|
9614
|
-
}
|
|
9615
|
-
|
|
9616
|
-
return willReturn
|
|
9617
|
-
}
|
|
9618
|
-
|
|
9619
|
-
export function range(start) {
|
|
9620
|
-
return end => {
|
|
9621
|
-
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
9622
|
-
throw new TypeError('Both arguments to range must be numbers')
|
|
9623
|
-
}
|
|
9624
|
-
|
|
9625
|
-
if (end === start) {
|
|
9626
|
-
return []
|
|
9627
|
-
}
|
|
9628
|
-
if (end < start) return rangeDescending(start,end)
|
|
9629
|
-
|
|
9630
|
-
const len = end - start
|
|
9631
|
-
const willReturn = Array(len)
|
|
9632
|
-
|
|
9633
|
-
for (let i = 0; i < len; i++) {
|
|
9634
|
-
willReturn[i] = start + i
|
|
9635
|
-
}
|
|
9636
|
-
|
|
9637
|
-
return willReturn
|
|
9897
|
+
export function range(a, b) {
|
|
9898
|
+
const start = b === undefined ? 0 : a
|
|
9899
|
+
const end = b === undefined ? a : b
|
|
9900
|
+
if (end<= start) {
|
|
9901
|
+
return []
|
|
9638
9902
|
}
|
|
9903
|
+
const len = end - start
|
|
9904
|
+
return Array.from({ length: len + 1 }, (_, i) => start + i)
|
|
9639
9905
|
}
|
|
9640
9906
|
```
|
|
9641
9907
|
|
|
@@ -9649,9 +9915,10 @@ export function range(start) {
|
|
|
9649
9915
|
import { range } from './range.js'
|
|
9650
9916
|
|
|
9651
9917
|
test('happy', () => {
|
|
9652
|
-
expect(range(
|
|
9653
|
-
|
|
9654
|
-
|
|
9918
|
+
expect(range(5)).toEqual([0, 1, 2, 3, 4, 5])
|
|
9919
|
+
expect(range(3,5)).toEqual([3, 4, 5])
|
|
9920
|
+
expect(range(5,3)).toEqual([])
|
|
9921
|
+
expect(range(0)).toEqual([])
|
|
9655
9922
|
})
|
|
9656
9923
|
```
|
|
9657
9924
|
|
|
@@ -9666,9 +9933,9 @@ import { range } from 'rambda'
|
|
|
9666
9933
|
|
|
9667
9934
|
describe('R.range', () => {
|
|
9668
9935
|
it('curried', () => {
|
|
9669
|
-
const result = range(1)(
|
|
9936
|
+
const result = [range(1, 4), range(1)]
|
|
9670
9937
|
|
|
9671
|
-
result // $ExpectType number[]
|
|
9938
|
+
result // $ExpectType number[][]
|
|
9672
9939
|
})
|
|
9673
9940
|
})
|
|
9674
9941
|
```
|
|
@@ -9677,6 +9944,62 @@ describe('R.range', () => {
|
|
|
9677
9944
|
|
|
9678
9945
|
[](#range)
|
|
9679
9946
|
|
|
9947
|
+
### rangeDescending
|
|
9948
|
+
|
|
9949
|
+
```typescript
|
|
9950
|
+
|
|
9951
|
+
rangeDescending(startInclusive: number, endInclusive: number) : number[]
|
|
9952
|
+
```
|
|
9953
|
+
|
|
9954
|
+
It returns list of numbers between `endInclusive` to `startInclusive` markers.
|
|
9955
|
+
|
|
9956
|
+
<details>
|
|
9957
|
+
|
|
9958
|
+
<summary>All TypeScript definitions</summary>
|
|
9959
|
+
|
|
9960
|
+
```typescript
|
|
9961
|
+
rangeDescending(startInclusive: number, endInclusive: number) : number[];
|
|
9962
|
+
rangeDescending(endInclusive: number) : number[];
|
|
9963
|
+
```
|
|
9964
|
+
|
|
9965
|
+
</details>
|
|
9966
|
+
|
|
9967
|
+
<details>
|
|
9968
|
+
|
|
9969
|
+
<summary><strong>R.rangeDescending</strong> source</summary>
|
|
9970
|
+
|
|
9971
|
+
```javascript
|
|
9972
|
+
export function rangeDescending(start, b) {
|
|
9973
|
+
const end = b === undefined ? 0 : b
|
|
9974
|
+
if (start <= end) {
|
|
9975
|
+
return []
|
|
9976
|
+
}
|
|
9977
|
+
const len = start - end
|
|
9978
|
+
return Array.from({ length: len + 1 }, (_, i) => start - i)
|
|
9979
|
+
}
|
|
9980
|
+
```
|
|
9981
|
+
|
|
9982
|
+
</details>
|
|
9983
|
+
|
|
9984
|
+
<details>
|
|
9985
|
+
|
|
9986
|
+
<summary><strong>Tests</strong></summary>
|
|
9987
|
+
|
|
9988
|
+
```javascript
|
|
9989
|
+
import { rangeDescending } from './rangeDescending.js'
|
|
9990
|
+
|
|
9991
|
+
test('happy', () => {
|
|
9992
|
+
expect(rangeDescending(5)).toEqual([5, 4, 3, 2, 1, 0])
|
|
9993
|
+
expect(rangeDescending(7,3)).toEqual([7, 6, 5, 4,3])
|
|
9994
|
+
expect(rangeDescending(5, 7)).toEqual([])
|
|
9995
|
+
expect(rangeDescending(5, 5)).toEqual([])
|
|
9996
|
+
})
|
|
9997
|
+
```
|
|
9998
|
+
|
|
9999
|
+
</details>
|
|
10000
|
+
|
|
10001
|
+
[](#rangeDescending)
|
|
10002
|
+
|
|
9680
10003
|
### reduce
|
|
9681
10004
|
|
|
9682
10005
|
```typescript
|
|
@@ -9695,7 +10018,7 @@ const result = R.reduce(reducer, initialValue, list)
|
|
|
9695
10018
|
// => 60
|
|
9696
10019
|
```
|
|
9697
10020
|
|
|
9698
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10021
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%5D%0Aconst%20initialValue%20%3D%2010%0Aconst%20reducer%20%3D%20(prev%2C%20current)%20%3D%3E%20prev%20*%20current%0A%0Aconst%20result%20%3D%20R.reduce(reducer%2C%20initialValue%2C%20list)%0A%2F%2F%20%3D%3E%2060">Try this <strong>R.reduce</strong> example in Rambda REPL</a>
|
|
9699
10022
|
|
|
9700
10023
|
<details>
|
|
9701
10024
|
|
|
@@ -9816,7 +10139,7 @@ const result = [
|
|
|
9816
10139
|
// => [[1], {a: 1}]
|
|
9817
10140
|
```
|
|
9818
10141
|
|
|
9819
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10142
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%2C%204%5D%0Aconst%20obj%20%3D%20%7Ba%3A%201%2C%20b%3A%202%7D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%201%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.reject(predicate)(list)%2C%0A%20%20R.reject(predicate)(obj)%0A%5D%0A%2F%2F%20%3D%3E%20%5B%5B1%5D%2C%20%7Ba%3A%201%7D%5D">Try this <strong>R.reject</strong> example in Rambda REPL</a>
|
|
9820
10143
|
|
|
9821
10144
|
<details>
|
|
9822
10145
|
|
|
@@ -9969,7 +10292,7 @@ const result = R.rejectObject(
|
|
|
9969
10292
|
// => {b: 2}
|
|
9970
10293
|
```
|
|
9971
10294
|
|
|
9972
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10295
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.rejectObject(%0A%09(val%2C%20prop)%20%3D%3E%20prop%20%3D%3D%3D%20'a'%20%7C%7C%20val%20%3E%201%0A)(%7Ba%3A%201%2C%20b%3A%202%2C%20c%3A3%7D)%0A%2F%2F%20%3D%3E%20%7Bb%3A%202%7D">Try this <strong>R.rejectObject</strong> example in Rambda REPL</a>
|
|
9973
10296
|
|
|
9974
10297
|
<details>
|
|
9975
10298
|
|
|
@@ -10075,7 +10398,7 @@ const result = [
|
|
|
10075
10398
|
// => ['f|1|o', 'f|1||1|']
|
|
10076
10399
|
```
|
|
10077
10400
|
|
|
10078
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10401
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%09R.replace('o'%2C%20'%7C1%7C')('foo')%2C%0A%09R.replace(%2Fo%2Fg%2C%20'%7C1%7C')('foo')%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B'f%7C1%7Co'%2C%20'f%7C1%7C%7C1%7C'%5D">Try this <strong>R.replace</strong> example in Rambda REPL</a>
|
|
10079
10402
|
|
|
10080
10403
|
<details>
|
|
10081
10404
|
|
|
@@ -10158,7 +10481,7 @@ const result = [
|
|
|
10158
10481
|
// => 'f|1||1|'
|
|
10159
10482
|
```
|
|
10160
10483
|
|
|
10161
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10484
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%09R.replaceAll(%5B'o'%2C%20%2Fa%2Fg%5D%2C%20'%7C1%7C')('foa')%2C%0A%5D%0A%2F%2F%20%3D%3E%20'f%7C1%7C%7C1%7C'">Try this <strong>R.replaceAll</strong> example in Rambda REPL</a>
|
|
10162
10485
|
|
|
10163
10486
|
<details>
|
|
10164
10487
|
|
|
@@ -10250,7 +10573,7 @@ const result = R.shuffle(
|
|
|
10250
10573
|
// => [3, 1, 2] or [2, 3, 1] or ...
|
|
10251
10574
|
```
|
|
10252
10575
|
|
|
10253
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10576
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.shuffle(%0A%09%5B1%2C%202%2C%203%5D%0A)%0A%2F%2F%20%3D%3E%20%5B3%2C%201%2C%202%5D%20or%20%5B2%2C%203%2C%201%5D%20or%20...">Try this <strong>R.shuffle</strong> example in Rambda REPL</a>
|
|
10254
10577
|
|
|
10255
10578
|
<details>
|
|
10256
10579
|
|
|
@@ -10335,7 +10658,7 @@ const expected = [
|
|
|
10335
10658
|
// => `result` is equal to `expected`
|
|
10336
10659
|
```
|
|
10337
10660
|
|
|
10338
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10661
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%0A%20%20%7Ba%3A%202%7D%2C%0A%20%20%7Ba%3A%203%7D%2C%0A%20%20%7Ba%3A%201%7D%0A%5D%0Aconst%20sortFn%20%3D%20(x%2C%20y)%20%3D%3E%20%7B%0A%20%20return%20x.a%20%3E%20y.a%20%3F%201%20%3A%20-1%0A%7D%0A%0Aconst%20result%20%3D%20R.sort(sortFn%2C%20list)%0Aconst%20expected%20%3D%20%5B%0A%20%20%7Ba%3A%201%7D%2C%0A%20%20%7Ba%3A%202%7D%2C%0A%20%20%7Ba%3A%203%7D%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.sort</strong> example in Rambda REPL</a>
|
|
10339
10662
|
|
|
10340
10663
|
<details>
|
|
10341
10664
|
|
|
@@ -10442,7 +10765,7 @@ const expected = [
|
|
|
10442
10765
|
// => `result` is equal to `expected`
|
|
10443
10766
|
```
|
|
10444
10767
|
|
|
10445
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10768
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%0A%20%20%7Ba%3A%202%7D%2C%0A%20%20%7Ba%3A%203%7D%2C%0A%20%20%7Ba%3A%201%7D%0A%5D%0Aconst%20sortFn%20%3D%20x%20%3D%3E%20x.a%0A%0Aconst%20result%20%3D%20R.sortBy(sortFn)(list)%0Aconst%20expected%20%3D%20%5B%0A%20%20%7Ba%3A%201%7D%2C%0A%20%20%7Ba%3A%202%7D%2C%0A%20%20%7Ba%3A%203%7D%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.sortBy</strong> example in Rambda REPL</a>
|
|
10446
10769
|
|
|
10447
10770
|
<details>
|
|
10448
10771
|
|
|
@@ -10542,7 +10865,7 @@ describe('R.sortBy', () => {
|
|
|
10542
10865
|
|
|
10543
10866
|
```typescript
|
|
10544
10867
|
|
|
10545
|
-
sortByDescending<T>(sortFn: (
|
|
10868
|
+
sortByDescending<T>(sortFn: (x: T) => Ord): (list: T[]) => T[]
|
|
10546
10869
|
```
|
|
10547
10870
|
|
|
10548
10871
|
```javascript
|
|
@@ -10562,14 +10885,14 @@ const expected = [
|
|
|
10562
10885
|
// => `result` is equal to `expected`
|
|
10563
10886
|
```
|
|
10564
10887
|
|
|
10565
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10888
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%0A%20%20%7Ba%3A%202%7D%2C%0A%20%20%7Ba%3A%203%7D%2C%0A%20%20%7Ba%3A%201%7D%0A%5D%0Aconst%20sortFn%20%3D%20x%20%3D%3E%20x.a%0A%0Aconst%20result%20%3D%20R.sortByDescending(sortFn)(list)%0Aconst%20expected%20%3D%20%5B%0A%20%20%7Ba%3A%203%7D%2C%0A%20%20%7Ba%3A%202%7D%2C%0A%20%20%7Ba%3A%201%7D%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.sortByDescending</strong> example in Rambda REPL</a>
|
|
10566
10889
|
|
|
10567
10890
|
<details>
|
|
10568
10891
|
|
|
10569
10892
|
<summary>All TypeScript definitions</summary>
|
|
10570
10893
|
|
|
10571
10894
|
```typescript
|
|
10572
|
-
sortByDescending<T>(sortFn: (
|
|
10895
|
+
sortByDescending<T>(sortFn: (x: T) => Ord): (list: T[]) => T[];
|
|
10573
10896
|
```
|
|
10574
10897
|
|
|
10575
10898
|
</details>
|
|
@@ -10588,6 +10911,24 @@ export function sortByDescending(sortFn) {
|
|
|
10588
10911
|
|
|
10589
10912
|
</details>
|
|
10590
10913
|
|
|
10914
|
+
<details>
|
|
10915
|
+
|
|
10916
|
+
<summary><strong>Tests</strong></summary>
|
|
10917
|
+
|
|
10918
|
+
```javascript
|
|
10919
|
+
import { sortByDescending } from './sortByDescending.js'
|
|
10920
|
+
import { path } from './path.js'
|
|
10921
|
+
|
|
10922
|
+
const list = [{ a: { b: 3 } }, { a: { b: 1 } }, { a: { b: 2 } }]
|
|
10923
|
+
const sorted = [{ a: { b: 3 } }, { a: { b: 2 } }, { a: { b: 1 } }]
|
|
10924
|
+
|
|
10925
|
+
test('happy', () => {
|
|
10926
|
+
expect(sortByDescending(path('a.b'))(list)).toEqual(sorted)
|
|
10927
|
+
})
|
|
10928
|
+
```
|
|
10929
|
+
|
|
10930
|
+
</details>
|
|
10931
|
+
|
|
10591
10932
|
[](#sortByDescending)
|
|
10592
10933
|
|
|
10593
10934
|
### sortByPath
|
|
@@ -10616,7 +10957,7 @@ const expected = [
|
|
|
10616
10957
|
// => `result` is equal to `expected`
|
|
10617
10958
|
```
|
|
10618
10959
|
|
|
10619
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
10960
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%0A%09%7Ba%3A%20%7Bb%3A%202%7D%2C%20id%3A1%7D%2C%0A%09%7Ba%3A%20%7Bb%3A%201%7D%2C%20id%3A2%7D%2C%0A%09%7Ba%3A%20%7Bb%3A%203%7D%2C%20id%3A3%7D%2C%0A%5D%0Aconst%20result%20%3D%20R.sortByPath('a.b')(list)%0Aconst%20expected%20%3D%20%5B%0A%09%7Ba%3A%20%7Bb%3A%201%7D%2C%20id%3A2%7D%2C%0A%09%7Ba%3A%20%7Bb%3A%202%7D%2C%20id%3A1%7D%2C%0A%09%7Ba%3A%20%7Bb%3A%203%7D%2C%20id%3A3%7D%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.sortByPath</strong> example in Rambda REPL</a>
|
|
10620
10961
|
|
|
10621
10962
|
<details>
|
|
10622
10963
|
|
|
@@ -10737,7 +11078,7 @@ const expected = [
|
|
|
10737
11078
|
// => `result` is equal to `expected`
|
|
10738
11079
|
```
|
|
10739
11080
|
|
|
10740
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
11081
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%0A%09%7Ba%3A%20%7Bb%3A%202%7D%2C%20id%3A1%7D%2C%0A%09%7Ba%3A%20%7Bb%3A%201%7D%2C%20id%3A2%7D%2C%0A%09%7Ba%3A%20%7Bb%3A%203%7D%2C%20id%3A3%7D%2C%0A%5D%0Aconst%20result%20%3D%20R.sortByPathDescending('a.b')(list)%0Aconst%20expected%20%3D%20%5B%0A%09%7Ba%3A%20%7Bb%3A%203%7D%2C%20id%3A3%7D%0A%09%7Ba%3A%20%7Bb%3A%202%7D%2C%20id%3A1%7D%2C%0A%09%7Ba%3A%20%7Bb%3A%201%7D%2C%20id%3A2%7D%2C%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.sortByPathDescending</strong> example in Rambda REPL</a>
|
|
10741
11082
|
|
|
10742
11083
|
<details>
|
|
10743
11084
|
|
|
@@ -10816,7 +11157,7 @@ const result = R.sortObject(predicate)({a:1, b: 4, c: 2})
|
|
|
10816
11157
|
// => {b: 4, c: 2, a: 1}
|
|
10817
11158
|
```
|
|
10818
11159
|
|
|
10819
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
11160
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20(propA%2C%20propB%2C%20valueA%2C%20valueB)%20%3D%3E%20valueA%20%3E%20valueB%20%3F%20-1%20%3A%201%0A%0Aconst%20result%20%3D%20R.sortObject(predicate)(%7Ba%3A1%2C%20b%3A%204%2C%20c%3A%202%7D)%0A%2F%2F%20%3D%3E%20%7Bb%3A%204%2C%20c%3A%202%2C%20a%3A%201%7D">Try this <strong>R.sortObject</strong> example in Rambda REPL</a>
|
|
10820
11161
|
|
|
10821
11162
|
<details>
|
|
10822
11163
|
|
|
@@ -10963,7 +11304,7 @@ const expected = [
|
|
|
10963
11304
|
// => `result` is equal to `expected`
|
|
10964
11305
|
```
|
|
10965
11306
|
|
|
10966
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
11307
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.sortWith(%5B%0A%20%20%20%20(a%2C%20b)%20%3D%3E%20a.a%20%3D%3D%3D%20b.a%20%3F%200%20%3A%20a.a%20%3E%20b.a%20%3F%201%20%3A%20-1%2C%0A%20%20%20%20(a%2C%20b)%20%3D%3E%20a.b%20%3D%3D%3D%20b.b%20%3F%200%20%3A%20a.b%20%3E%20b.b%20%3F%201%20%3A%20-1%2C%0A%5D)(%5B%0A%20%20%7Ba%3A%201%2C%20b%3A%202%7D%2C%0A%20%20%7Ba%3A%202%2C%20b%3A%201%7D%2C%0A%20%20%7Ba%3A%202%2C%20b%3A%202%7D%2C%0A%20%20%7Ba%3A%201%2C%20b%3A%201%7D%2C%0A%5D)%0Aconst%20expected%20%3D%20%5B%0A%20%20%7Ba%3A%201%2C%20b%3A%201%7D%2C%0A%20%20%7Ba%3A%201%2C%20b%3A%202%7D%2C%0A%20%20%7Ba%3A%202%2C%20b%3A%201%7D%2C%0A%20%20%7Ba%3A%202%2C%20b%3A%202%7D%2C%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.sortWith</strong> example in Rambda REPL</a>
|
|
10967
11308
|
|
|
10968
11309
|
<details>
|
|
10969
11310
|
|
|
@@ -11188,7 +11529,7 @@ const expected = [
|
|
|
11188
11529
|
// => `result` is equal to `expected`
|
|
11189
11530
|
```
|
|
11190
11531
|
|
|
11191
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
11532
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.splitEvery(2)(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.splitEvery(3)('foobar')%0A%5D%0A%0Aconst%20expected%20%3D%20%5B%0A%20%20%5B%5B1%2C%202%5D%2C%20%5B3%5D%5D%2C%0A%20%20%5B'foo'%2C%20'bar'%5D%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.splitEvery</strong> example in Rambda REPL</a>
|
|
11192
11533
|
|
|
11193
11534
|
<details>
|
|
11194
11535
|
|
|
@@ -11264,10 +11605,10 @@ describe('R.splitEvery', () => {
|
|
|
11264
11605
|
|
|
11265
11606
|
```typescript
|
|
11266
11607
|
|
|
11267
|
-
symmetricDifference<T>(x: T[]):
|
|
11608
|
+
symmetricDifference<T>(x: T[]): (y: T[]) => T[]
|
|
11268
11609
|
```
|
|
11269
11610
|
|
|
11270
|
-
It returns
|
|
11611
|
+
It returns all items that are in either of the lists, but not in both.
|
|
11271
11612
|
|
|
11272
11613
|
`R.equals` is used to determine equality.
|
|
11273
11614
|
|
|
@@ -11279,14 +11620,14 @@ const result = R.symmetricDifference(x)(y)
|
|
|
11279
11620
|
// => [ 1, 2, 5, 6 ]
|
|
11280
11621
|
```
|
|
11281
11622
|
|
|
11282
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
11623
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20x%20%3D%20%5B%201%2C%202%2C%203%2C%204%20%5D%0Aconst%20y%20%3D%20%5B%203%2C%204%2C%205%2C%206%20%5D%0A%0Aconst%20result%20%3D%20R.symmetricDifference(x)(y)%0A%2F%2F%20%3D%3E%20%5B%201%2C%202%2C%205%2C%206%20%5D">Try this <strong>R.symmetricDifference</strong> example in Rambda REPL</a>
|
|
11283
11624
|
|
|
11284
11625
|
<details>
|
|
11285
11626
|
|
|
11286
11627
|
<summary>All TypeScript definitions</summary>
|
|
11287
11628
|
|
|
11288
11629
|
```typescript
|
|
11289
|
-
symmetricDifference<T>(x: T[]):
|
|
11630
|
+
symmetricDifference<T>(x: T[]): (y: T[]) => T[];
|
|
11290
11631
|
```
|
|
11291
11632
|
|
|
11292
11633
|
</details>
|
|
@@ -11376,7 +11717,7 @@ const result = [
|
|
|
11376
11717
|
// => [[2, 3], 'oo']
|
|
11377
11718
|
```
|
|
11378
11719
|
|
|
11379
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
11720
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20%5B%0A%20%20R.tail(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.tail('foo')%0A%5D%0A%2F%2F%20%3D%3E%20%5B%5B2%2C%203%5D%2C%20'oo'%5D">Try this <strong>R.tail</strong> example in Rambda REPL</a>
|
|
11380
11721
|
|
|
11381
11722
|
<details>
|
|
11382
11723
|
|
|
@@ -11475,7 +11816,7 @@ const result = [
|
|
|
11475
11816
|
// => [[1, 2], 'fo']
|
|
11476
11817
|
```
|
|
11477
11818
|
|
|
11478
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
11819
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20howMany%20%3D%202%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.take(howMany)(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.take(howMany%2C%20'foobar')%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B%5B1%2C%202%5D%2C%20'fo'%5D">Try this <strong>R.take</strong> example in Rambda REPL</a>
|
|
11479
11820
|
|
|
11480
11821
|
<details>
|
|
11481
11822
|
|
|
@@ -11484,8 +11825,8 @@ const result = [
|
|
|
11484
11825
|
```typescript
|
|
11485
11826
|
take<T>(howMany: number): {
|
|
11486
11827
|
(input: string): string;
|
|
11487
|
-
(input: T[]): T[];
|
|
11488
11828
|
(input: readonly T[]): T[];
|
|
11829
|
+
(input: T[]): T[];
|
|
11489
11830
|
};
|
|
11490
11831
|
...
|
|
11491
11832
|
...
|
|
@@ -11568,7 +11909,7 @@ const result = [
|
|
|
11568
11909
|
// => [[2, 3], 'ar']
|
|
11569
11910
|
```
|
|
11570
11911
|
|
|
11571
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
11912
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20howMany%20%3D%202%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.takeLast(howMany)(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.takeLast(howMany)('foobar')%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B%5B2%2C%203%5D%2C%20'ar'%5D">Try this <strong>R.takeLast</strong> example in Rambda REPL</a>
|
|
11572
11913
|
|
|
11573
11914
|
<details>
|
|
11574
11915
|
|
|
@@ -11577,8 +11918,8 @@ const result = [
|
|
|
11577
11918
|
```typescript
|
|
11578
11919
|
takeLast<T>(howMany: number): {
|
|
11579
11920
|
(input: string): string;
|
|
11580
|
-
(input: T[]): T[];
|
|
11581
11921
|
(input: readonly T[]): T[];
|
|
11922
|
+
(input: T[]): T[];
|
|
11582
11923
|
};
|
|
11583
11924
|
...
|
|
11584
11925
|
...
|
|
@@ -11656,7 +11997,7 @@ const result = R.takeLastWhile(x => x > 2)([1, 2, 3, 4])
|
|
|
11656
11997
|
// => [3, 4]
|
|
11657
11998
|
```
|
|
11658
11999
|
|
|
11659
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12000
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.takeLastWhile(x%20%3D%3E%20x%20%3E%202)(%5B1%2C%202%2C%203%2C%204%5D)%0A%2F%2F%20%3D%3E%20%5B3%2C%204%5D">Try this <strong>R.takeLastWhile</strong> example in Rambda REPL</a>
|
|
11660
12001
|
|
|
11661
12002
|
<details>
|
|
11662
12003
|
|
|
@@ -11745,7 +12086,7 @@ const result = R.takeWhile(predicate)(list)
|
|
|
11745
12086
|
// => [1, 2]
|
|
11746
12087
|
```
|
|
11747
12088
|
|
|
11748
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12089
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%2C%204%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3C%203%0A%0Aconst%20result%20%3D%20R.takeWhile(predicate)(list)%0A%2F%2F%20%3D%3E%20%5B1%2C%202%5D">Try this <strong>R.takeWhile</strong> example in Rambda REPL</a>
|
|
11749
12090
|
|
|
11750
12091
|
<details>
|
|
11751
12092
|
|
|
@@ -11855,7 +12196,7 @@ const result = R.pipe(
|
|
|
11855
12196
|
// => `2` and `3` will be logged
|
|
11856
12197
|
```
|
|
11857
12198
|
|
|
11858
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12199
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%202%2C%203%5D%0A%0Aconst%20result%20%3D%20R.pipe(%0A%09list%2C%0A%20%20R.filter(x%20%3D%3E%20x%20%3E%201)%2C%0A%20%20R.tap(console.log)%2C%0A%20%20R.map(x%20%3D%3E%20x%20*%202)%0A)%0A%2F%2F%20%3D%3E%20%602%60%20and%20%603%60%20will%20be%20logged">Try this <strong>R.tap</strong> example in Rambda REPL</a>
|
|
11859
12200
|
|
|
11860
12201
|
<details>
|
|
11861
12202
|
|
|
@@ -11899,7 +12240,7 @@ R.test(/^f/)('foo')
|
|
|
11899
12240
|
// => true
|
|
11900
12241
|
```
|
|
11901
12242
|
|
|
11902
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12243
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.test(%2F%5Ef%2F)('foo')%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.test</strong> example in Rambda REPL</a>
|
|
11903
12244
|
|
|
11904
12245
|
<details>
|
|
11905
12246
|
|
|
@@ -11977,7 +12318,7 @@ const result = R.transformPropObject(fn, 'a')(obj)
|
|
|
11977
12318
|
// => {a: false, b: 2}
|
|
11978
12319
|
```
|
|
11979
12320
|
|
|
11980
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12321
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20fn%20%3D%20(x)%20%3D%3E%20x%20%3E%202%0Aconst%20obj%20%3D%20%7Ba%3A%201%2C%20b%3A%202%7D%0A%0Aconst%20result%20%3D%20R.transformPropObject(fn%2C%20'a')(obj)%0A%2F%2F%20%3D%3E%20%7Ba%3A%20false%2C%20b%3A%202%7D">Try this <strong>R.transformPropObject</strong> example in Rambda REPL</a>
|
|
11981
12322
|
|
|
11982
12323
|
<details>
|
|
11983
12324
|
|
|
@@ -12038,7 +12379,7 @@ const result = [
|
|
|
12038
12379
|
// => [false, 'bar']
|
|
12039
12380
|
```
|
|
12040
12381
|
|
|
12041
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12382
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20fn%20%3D%20x%20%3D%3E%20x.foo%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.tryCatch(fn%2C%20false)(null)%2C%0A%20%20R.tryCatch(fn%2C%20false)(%7Bfoo%3A%20'bar'%7D)%0A%5D%0A%2F%2F%20%3D%3E%20%5Bfalse%2C%20'bar'%5D">Try this <strong>R.tryCatch</strong> example in Rambda REPL</a>
|
|
12042
12383
|
|
|
12043
12384
|
<details>
|
|
12044
12385
|
|
|
@@ -12169,7 +12510,7 @@ const delay = ms => new Promise(resolve => {
|
|
|
12169
12510
|
R.type(delay) // => 'Promise'
|
|
12170
12511
|
```
|
|
12171
12512
|
|
|
12172
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12513
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.type(()%20%3D%3E%20%7B%7D)%20%2F%2F%20%3D%3E%20'Function'%0AR.type(async%20()%20%3D%3E%20%7B%7D)%20%2F%2F%20%3D%3E%20'Async'%0AR.type(%5B%5D)%20%2F%2F%20%3D%3E%20'Array'%0AR.type(%7B%7D)%20%2F%2F%20%3D%3E%20'Object'%0AR.type('foo')%20%2F%2F%20%3D%3E%20'String'%0AR.type(1)%20%2F%2F%20%3D%3E%20'Number'%0AR.type(true)%20%2F%2F%20%3D%3E%20'Boolean'%0AR.type(null)%20%2F%2F%20%3D%3E%20'Null'%0AR.type(%2F%5BA-z%5D%2F)%20%2F%2F%20%3D%3E%20'RegExp'%0AR.type('foo'*1)%20%2F%2F%20%3D%3E%20'NaN'%0A%0Aconst%20delay%20%3D%20ms%20%3D%3E%20new%20Promise(resolve%20%3D%3E%20%7B%0A%20%20setTimeout(function%20()%20%7B%0A%20%20%20%20resolve()%0A%20%20%7D%2C%20ms)%0A%7D)%0AR.type(delay)%20%2F%2F%20%3D%3E%20'Promise'">Try this <strong>R.type</strong> example in Rambda REPL</a>
|
|
12173
12514
|
|
|
12174
12515
|
<details>
|
|
12175
12516
|
|
|
@@ -12419,7 +12760,7 @@ const result = R.union([1,2,3])([3,4,5]);
|
|
|
12419
12760
|
// => [1, 2, 3, 4, 5]
|
|
12420
12761
|
```
|
|
12421
12762
|
|
|
12422
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12763
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.union(%5B1%2C2%2C3%5D)(%5B3%2C4%2C5%5D)%3B%0A%2F%2F%20%3D%3E%20%5B1%2C%202%2C%203%2C%204%2C%205%5D">Try this <strong>R.union</strong> example in Rambda REPL</a>
|
|
12423
12764
|
|
|
12424
12765
|
<details>
|
|
12425
12766
|
|
|
@@ -12510,6 +12851,105 @@ describe('R.union', () => {
|
|
|
12510
12851
|
|
|
12511
12852
|
[](#union)
|
|
12512
12853
|
|
|
12854
|
+
### unionWith
|
|
12855
|
+
|
|
12856
|
+
```typescript
|
|
12857
|
+
|
|
12858
|
+
unionWith<T>(predicate: (x: T, y: T) => boolean, x: T[]): (y: T[]) => T[]
|
|
12859
|
+
```
|
|
12860
|
+
|
|
12861
|
+
```javascript
|
|
12862
|
+
const result = R.pipe(
|
|
12863
|
+
[{a: 1, b: 1}, {a: 2, b: 1}],
|
|
12864
|
+
R.unionWith((x, y) => x === y, [{a: 2, b: 2}, {a: 3, b: 2}]),
|
|
12865
|
+
)
|
|
12866
|
+
// => [{a: 1, b: 1}, {a: 2, b: 1}, {a: 3, b: 2}]
|
|
12867
|
+
```
|
|
12868
|
+
|
|
12869
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20result%20%3D%20R.pipe(%0A%09%5B%7Ba%3A%201%2C%20b%3A%201%7D%2C%20%7Ba%3A%202%2C%20b%3A%201%7D%5D%2C%0A%09R.unionWith((x%2C%20y)%20%3D%3E%20x%20%3D%3D%3D%20y%2C%20%5B%7Ba%3A%202%2C%20b%3A%202%7D%2C%20%7Ba%3A%203%2C%20b%3A%202%7D%5D)%2C%0A)%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A%201%2C%20b%3A%201%7D%2C%20%7Ba%3A%202%2C%20b%3A%201%7D%2C%20%7Ba%3A%203%2C%20b%3A%202%7D%5D">Try this <strong>R.unionWith</strong> example in Rambda REPL</a>
|
|
12870
|
+
|
|
12871
|
+
<details>
|
|
12872
|
+
|
|
12873
|
+
<summary>All TypeScript definitions</summary>
|
|
12874
|
+
|
|
12875
|
+
```typescript
|
|
12876
|
+
unionWith<T>(predicate: (x: T, y: T) => boolean, x: T[]): (y: T[]) => T[];
|
|
12877
|
+
```
|
|
12878
|
+
|
|
12879
|
+
</details>
|
|
12880
|
+
|
|
12881
|
+
<details>
|
|
12882
|
+
|
|
12883
|
+
<summary><strong>R.unionWith</strong> source</summary>
|
|
12884
|
+
|
|
12885
|
+
```javascript
|
|
12886
|
+
export function unionWith(predicate, x) {
|
|
12887
|
+
return y => {
|
|
12888
|
+
const filtered = y.filter(yInstance => {
|
|
12889
|
+
return x.every(xInstance => {
|
|
12890
|
+
return !predicate(xInstance, yInstance)
|
|
12891
|
+
})
|
|
12892
|
+
})
|
|
12893
|
+
|
|
12894
|
+
return [...x, ...filtered]
|
|
12895
|
+
}
|
|
12896
|
+
}
|
|
12897
|
+
```
|
|
12898
|
+
|
|
12899
|
+
</details>
|
|
12900
|
+
|
|
12901
|
+
<details>
|
|
12902
|
+
|
|
12903
|
+
<summary><strong>Tests</strong></summary>
|
|
12904
|
+
|
|
12905
|
+
```javascript
|
|
12906
|
+
import { unionWith } from './unionWith.js'
|
|
12907
|
+
import { pipe } from './pipe.js'
|
|
12908
|
+
|
|
12909
|
+
test('happy', () => {
|
|
12910
|
+
const list1 = [{a: 1, b: 1}, {a: 2, b: 1}]
|
|
12911
|
+
const list2 = [{a: 2, b: 2}, {a: 3, b: 2}]
|
|
12912
|
+
const result = pipe(
|
|
12913
|
+
list2,
|
|
12914
|
+
unionWith((x, y) => {
|
|
12915
|
+
return x.a === y.a
|
|
12916
|
+
}, list1),
|
|
12917
|
+
)
|
|
12918
|
+
expect(result).toEqual([{a: 1, b: 1}, {a: 2, b: 1}, {a: 3, b: 2}])
|
|
12919
|
+
})
|
|
12920
|
+
```
|
|
12921
|
+
|
|
12922
|
+
</details>
|
|
12923
|
+
|
|
12924
|
+
<details>
|
|
12925
|
+
|
|
12926
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
12927
|
+
|
|
12928
|
+
```typescript
|
|
12929
|
+
import { pipe, unionWith } from 'rambda'
|
|
12930
|
+
|
|
12931
|
+
describe('R.unionWith', () => {
|
|
12932
|
+
it('happy', () => {
|
|
12933
|
+
const list = [{a: 1, b: 1}, {a: 2, b: 1}]
|
|
12934
|
+
const result = pipe(
|
|
12935
|
+
list,
|
|
12936
|
+
unionWith((x, y) => {
|
|
12937
|
+
x.a // $ExpectType number
|
|
12938
|
+
y.b // $ExpectType number
|
|
12939
|
+
return x.a === y.a
|
|
12940
|
+
}, [{a: 2, b: 2}, {a: 3, b: 2}]),
|
|
12941
|
+
)
|
|
12942
|
+
|
|
12943
|
+
result[0].a // $ExpectType number
|
|
12944
|
+
result[0].b // $ExpectType number
|
|
12945
|
+
})
|
|
12946
|
+
})
|
|
12947
|
+
```
|
|
12948
|
+
|
|
12949
|
+
</details>
|
|
12950
|
+
|
|
12951
|
+
[](#unionWith)
|
|
12952
|
+
|
|
12513
12953
|
### uniq
|
|
12514
12954
|
|
|
12515
12955
|
```typescript
|
|
@@ -12528,7 +12968,7 @@ R.uniq(list)
|
|
|
12528
12968
|
// => [1, {a: 1}, {a: 2}]
|
|
12529
12969
|
```
|
|
12530
12970
|
|
|
12531
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
12971
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B1%2C%201%2C%20%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%2C%20%7Ba%3A1%7D%5D%0A%0Aconst%20result%20%3D%20R.uniq(list)%0A%2F%2F%20%3D%3E%20%5B1%2C%20%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%5D">Try this <strong>R.uniq</strong> example in Rambda REPL</a>
|
|
12532
12972
|
|
|
12533
12973
|
<details>
|
|
12534
12974
|
|
|
@@ -12635,7 +13075,7 @@ const result = R.uniqBy(x => x)(list)
|
|
|
12635
13075
|
// => [{a:1}, {a:2}]
|
|
12636
13076
|
```
|
|
12637
13077
|
|
|
12638
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
13078
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%7Ba%3A1%7D%2C%20%7Ba%3A2%7D%2C%20%7Ba%3A1%7D%5D%0Aconst%20result%20%3D%20R.uniqBy(x%20%3D%3E%20x)(list)%0A%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A1%7D%2C%20%7Ba%3A2%7D%5D">Try this <strong>R.uniqBy</strong> example in Rambda REPL</a>
|
|
12639
13079
|
|
|
12640
13080
|
<details>
|
|
12641
13081
|
|
|
@@ -12741,7 +13181,7 @@ const result = R.uniqWith(predicate)(list)
|
|
|
12741
13181
|
// => `result` is equal to `expected`
|
|
12742
13182
|
```
|
|
12743
13183
|
|
|
12744
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
13184
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list%20%3D%20%5B%0A%20%20%7Bid%3A%200%2C%20title%3A'foo'%7D%2C%0A%20%20%7Bid%3A%201%2C%20title%3A'bar'%7D%2C%0A%20%20%7Bid%3A%202%2C%20title%3A'baz'%7D%2C%0A%20%20%7Bid%3A%203%2C%20title%3A'foo'%7D%2C%0A%20%20%7Bid%3A%204%2C%20title%3A'bar'%7D%2C%0A%5D%0A%0Aconst%20expected%20%3D%20%5B%0A%20%20%7Bid%3A%200%2C%20title%3A'foo'%7D%2C%0A%20%20%7Bid%3A%201%2C%20title%3A'bar'%7D%2C%0A%20%20%7Bid%3A%202%2C%20title%3A'baz'%7D%2C%0A%5D%0A%0Aconst%20predicate%20%3D%20(x%2Cy)%20%3D%3E%20x.title%20%3D%3D%3D%20y.title%0A%0Aconst%20result%20%3D%20R.uniqWith(predicate)(list)%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.uniqWith</strong> example in Rambda REPL</a>
|
|
12745
13185
|
|
|
12746
13186
|
<details>
|
|
12747
13187
|
|
|
@@ -12892,7 +13332,7 @@ const result = [
|
|
|
12892
13332
|
// => [11, 5]
|
|
12893
13333
|
```
|
|
12894
13334
|
|
|
12895
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
13335
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20fn%20%3D%20R.unless(%0A%20%20x%20%3D%3E%20x%20%3E%202%2C%0A%20%20x%20%3D%3E%20x%20%2B%2010%0A)%0A%0Aconst%20result%20%3D%20%5B%0A%20%20fn(1)%2C%0A%20%20fn(5)%0A%5D%0A%2F%2F%20%3D%3E%20%5B11%2C%205%5D">Try this <strong>R.unless</strong> example in Rambda REPL</a>
|
|
12896
13336
|
|
|
12897
13337
|
<details>
|
|
12898
13338
|
|
|
@@ -13007,7 +13447,7 @@ const expected = [{a:1, b:2}, {a:1, b:3}]
|
|
|
13007
13447
|
// => `result` is equal to `expected`
|
|
13008
13448
|
```
|
|
13009
13449
|
|
|
13010
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
13450
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20obj%20%3D%20%7B%0A%20%20a%3A%201%2C%0A%20%20b%3A%20%5B2%2C%203%5D%2C%0A%7D%0Aconst%20result%20%3D%20R.unwind('b')(obj)%0Aconst%20expected%20%3D%20%5B%7Ba%3A1%2C%20b%3A2%7D%2C%20%7Ba%3A1%2C%20b%3A3%7D%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.unwind</strong> example in Rambda REPL</a>
|
|
13011
13451
|
|
|
13012
13452
|
<details>
|
|
13013
13453
|
|
|
@@ -13116,7 +13556,7 @@ const result = R.update(index, newValue)(list)
|
|
|
13116
13556
|
// => [1, 2, 88, 4, 5]
|
|
13117
13557
|
```
|
|
13118
13558
|
|
|
13119
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
13559
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20index%20%3D%202%0Aconst%20newValue%20%3D%2088%0Aconst%20list%20%3D%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%0A%0Aconst%20result%20%3D%20R.update(index%2C%20newValue)(list)%0A%2F%2F%20%3D%3E%20%5B1%2C%202%2C%2088%2C%204%2C%205%5D">Try this <strong>R.update</strong> example in Rambda REPL</a>
|
|
13120
13560
|
|
|
13121
13561
|
<details>
|
|
13122
13562
|
|
|
@@ -13217,7 +13657,7 @@ const expected = [
|
|
|
13217
13657
|
// => `result` is equal to `expected`
|
|
13218
13658
|
```
|
|
13219
13659
|
|
|
13220
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
13660
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20typeof%20x%20%3D%3D%3D%20'number'%0Aconst%20fn%20%3D%20R.when(predicate)(x%20%3D%3E%20x%20%2B%201)%0A%0Aconst%20positiveInput%20%3D%2088%0Aconst%20negativeInput%20%3D%20'foo'%0A%0Aconst%20result%20%3D%20%5B%0A%20%20fn(positiveInput)%2C%0A%20%20fn(negativeInput)%2C%0A%5D%0A%0Aconst%20expected%20%3D%20%5B%0A%20%2089%2C%0A%20%20'foo1'%2C%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.when</strong> example in Rambda REPL</a>
|
|
13221
13661
|
|
|
13222
13662
|
<details>
|
|
13223
13663
|
|
|
@@ -13335,7 +13775,7 @@ R.zip([...x, 3])(['A', 'B'])
|
|
|
13335
13775
|
// => [[1, 'A'], [2, 'B']]
|
|
13336
13776
|
```
|
|
13337
13777
|
|
|
13338
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
13778
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20x%20%3D%20%5B1%2C%202%5D%0Aconst%20y%20%3D%20%5B'A'%2C%20'B'%5D%0AR.zip(x)(y)%0A%2F%2F%20%3D%3E%20%5B%5B1%2C%20'A'%5D%2C%20%5B2%2C%20'B'%5D%5D%0A%0A%2F%2F%20truncates%20to%20shortest%20list%0Aconst%20result%20%3D%20R.zip(%5B...x%2C%203%5D)(%5B'A'%2C%20'B'%5D)%0A%2F%2F%20%3D%3E%20%5B%5B1%2C%20'A'%5D%2C%20%5B2%2C%20'B'%5D%5D">Try this <strong>R.zip</strong> example in Rambda REPL</a>
|
|
13339
13779
|
|
|
13340
13780
|
<details>
|
|
13341
13781
|
|
|
@@ -13453,7 +13893,7 @@ const result = R.zipWith((x, y) => x + y, list1)(list2)
|
|
|
13453
13893
|
// => [110, 220]
|
|
13454
13894
|
```
|
|
13455
13895
|
|
|
13456
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.
|
|
13896
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20list1%20%3D%20%5B%2010%2C%2020%2C%2030%2C%2040%20%5D%0Aconst%20list2%20%3D%20%5B%20100%2C%20200%20%5D%0A%0Aconst%20result%20%3D%20R.zipWith((x%2C%20y)%20%3D%3E%20x%20%2B%20y%2C%20list1)(list2)%0A%2F%2F%20%3D%3E%20%5B110%2C%20220%5D">Try this <strong>R.zipWith</strong> example in Rambda REPL</a>
|
|
13457
13897
|
|
|
13458
13898
|
<details>
|
|
13459
13899
|
|
|
@@ -13542,6 +13982,42 @@ describe('R.zipWith', () => {
|
|
|
13542
13982
|
|
|
13543
13983
|
## ❯ CHANGELOG
|
|
13544
13984
|
|
|
13985
|
+
11.0.0
|
|
13986
|
+
|
|
13987
|
+
- Breaking change: `R.includes` and `R.excludes` now accept list as first argument and value to search as second argument. This makes it more useful when used with `R.filter` and `R.reject`.
|
|
13988
|
+
|
|
13989
|
+
- Rename `R.innerJoin` to `R.intersectionWith`
|
|
13990
|
+
|
|
13991
|
+
- Add `R.unionWith`
|
|
13992
|
+
|
|
13993
|
+
- Add `R.exists`
|
|
13994
|
+
|
|
13995
|
+
- Add `R.symmetricDifference`
|
|
13996
|
+
|
|
13997
|
+
- Add `R.difference`
|
|
13998
|
+
|
|
13999
|
+
- `R.range` now works similar to Ruby's `Range` - both start and end values are inclusive.
|
|
14000
|
+
|
|
14001
|
+
- Add `R.rangeDescending` as now `R.range` works only in ascending order.
|
|
14002
|
+
|
|
14003
|
+
- `R.range` - it accepts one or two arguments. If one argument is passed, it is considered as end value, and start is 0.
|
|
14004
|
+
|
|
14005
|
+
- R.rangeDescending - it accepts one or two arguments. If one argument is passed, it is considered as start value, and end is 0.
|
|
14006
|
+
|
|
14007
|
+
- Fix `R.filter(Boolean)` to handle filter of `false`, not only nullable values.
|
|
14008
|
+
|
|
14009
|
+
10.3.4
|
|
14010
|
+
|
|
14011
|
+
- Fix wrong typing for `R.sortByDescending` - [Issue #797](https://github.com/selfrefactor/rambda/issues/797)
|
|
14012
|
+
|
|
14013
|
+
- Improve `R.mapParallelAsync` typings to allow optional `batchSize` parameter.
|
|
14014
|
+
|
|
14015
|
+
- Change order of inputs in `R.mapPropObject`
|
|
14016
|
+
|
|
14017
|
+
- Change REPL links in documentation
|
|
14018
|
+
|
|
14019
|
+
- Remove `jsr.json`
|
|
14020
|
+
|
|
13545
14021
|
10.3.3
|
|
13546
14022
|
|
|
13547
14023
|
- Fix wrong typing for `R.reject` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
|