rambda 10.2.0 → 10.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +134 -773
- package/README.md +941 -511
- package/dist/rambda.cjs +107 -42
- package/dist/rambda.js +103 -43
- package/dist/rambda.umd.js +107 -42
- package/index.d.cts +65 -47
- package/index.d.ts +65 -47
- package/package.json +8 -8
- package/rambda.js +5 -0
- package/src/duplicateBy.js +9 -0
- package/src/filterAsync.js +14 -0
- package/src/indexBy.js +14 -0
- package/src/mapAsync.js +2 -2
- package/src/mapPropObject.js +10 -0
- package/src/propOr.js +1 -1
- package/src/replaceAll.js +10 -0
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Rambda
|
|
2
2
|
|
|
3
|
-
`Rambda` is TypeScript-focused utility library similar to `Remeda`, `Ramda` and `Radashi`.
|
|
4
|
-
|
|
5
|
-
Initially it started as faster alternative to functional programming library `Ramda`, but in order to address many TypeScript issues, now `Rambda` takes a separate path. - [Documentation](https://selfrefactor.github.io/rambda/#/)
|
|
3
|
+
`Rambda` is TypeScript-focused utility library similar to `Remeda`, `Ramda` and `Radashi`. - [Documentation site](https://selfrefactor.github.io/rambda/#/)
|
|
6
4
|
|
|
7
5
|

|
|
8
6
|

|
|
@@ -13,17 +11,17 @@ Initially it started as faster alternative to functional programming library `Ra
|
|
|
13
11
|
## ❯ Example use
|
|
14
12
|
|
|
15
13
|
```javascript
|
|
16
|
-
import { pipe,
|
|
14
|
+
import { pipe, filter, map } from 'rambda'
|
|
17
15
|
|
|
18
16
|
const result = pipe(
|
|
19
|
-
|
|
17
|
+
[1, 2, 3, 4],
|
|
20
18
|
filter(x => x > 2),
|
|
21
19
|
map(x => x * 2),
|
|
22
20
|
)
|
|
23
|
-
|
|
21
|
+
//=> [6, 8]
|
|
24
22
|
```
|
|
25
23
|
|
|
26
|
-
You can test this example in <a href="https://rambda.now.sh
|
|
24
|
+
You can test this example in <a href="https://rambda.now.sh/?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>
|
|
27
25
|
|
|
28
26
|
* [API](#api)
|
|
29
27
|
* [Changelog](#-changelog)
|
|
@@ -78,6 +76,29 @@ it('within Ramda.pipe requires explicit types', () => {
|
|
|
78
76
|
});
|
|
79
77
|
```
|
|
80
78
|
|
|
79
|
+
:exclamation: IMPORTANT - all methods are tested to deliver correct types when they are part of `R.pipe/R.pipeAsync` chains.
|
|
80
|
+
|
|
81
|
+
In other words:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
R.filter(x => x > 1)([1,2,3])
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
might trigger TS error as it not the same as
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
|
|
91
|
+
R.pipe([1,2,3], R.filter(x => x > 1)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### :exclamation: All methods are curried
|
|
95
|
+
|
|
96
|
+
There is one way to use `Rambda` methods and it is with currying, i.e. using `R.filter(fn, list)` will not work as it is inteded to be `R.filter(fn)(list)`.
|
|
97
|
+
|
|
98
|
+
The reason is that all methods are supposed to be used inside `R.pipe`. After all, building chains is the very base of functional programming.
|
|
99
|
+
|
|
100
|
+
Of course, there is value in supporting the case where you can pass all inputs at once, but I find that the price in terms of maintainability is not worth it.
|
|
101
|
+
|
|
81
102
|
### Keep only the most useful methods
|
|
82
103
|
|
|
83
104
|
The idea is to give `TypeScript` users only the most useful methods and let them implement the rest. No magic logic methods that are hard to remember. You shouldn't need to read the documentation to understand what a method does. Its name and signature should be enough.
|
|
@@ -130,38 +151,13 @@ R.pick('a,b', {a: 1 , b: 2, c: 3} })
|
|
|
130
151
|
// No space allowed between properties
|
|
131
152
|
```
|
|
132
153
|
|
|
133
|
-
### Fast performance compared to Ramda
|
|
134
|
-
|
|
135
|
-
Since `Rambda` methods doesn't use so many internals, it is faster than `Ramda`.
|
|
136
|
-
Prior to version `10`, benchmark summary was included, but now the main selling point is the TypeScript focus, not performance so this is no longer included.
|
|
137
|
-
|
|
138
154
|
### Differences between Rambda and Ramda
|
|
139
155
|
|
|
140
156
|
Up until version `9.4.2`, the aim of Rambda was to match as much as possible the Ramda API.
|
|
141
157
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
From version `10.0.0` onwards, Rambda will start to diverge from Ramda in order to address some of the issues that Ramda has.
|
|
145
|
-
|
|
146
|
-
Currently, `Rambda` includes 32 methods that differ from `Ramda` and shares 83 methods with it.
|
|
147
|
-
|
|
148
|
-
<details>
|
|
149
|
-
<summary>
|
|
150
|
-
Ramda issues
|
|
151
|
-
</summary>
|
|
152
|
-
|
|
153
|
-
-- Typescript support - this is the main reason for the divergence. Most of design decisions in Rambda are made with Typescript in mind.
|
|
154
|
-
|
|
155
|
-
-- Methods that imply side-effect, which is not FP oriented, e.g. `R.forEach`.
|
|
158
|
+
You can find documentation site of **Rambda** version **9.4.2** is [here](https://selfrefactor.github.io/rambda-v9/).
|
|
156
159
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
-- Naming of methods is sometimes too generic to be remembered such as `R.update`, `R.modify`, `R.where`.
|
|
160
|
-
|
|
161
|
-
-- Methods that are already present in standard JavaScript, such as `R.toLower`, `R.length`.
|
|
162
|
-
|
|
163
|
-
-- `R.compose` doesn't have the best possible TypeScript support.
|
|
164
|
-
</details>
|
|
160
|
+
From version `10.0.0` onwards, **Rambda** is no longer aiming to be drop-in replacement for *Ramda*.
|
|
165
161
|
|
|
166
162
|
[](#-rambdas-features)
|
|
167
163
|
|
|
@@ -181,13 +177,13 @@ It adds new key-value pair to the object.
|
|
|
181
177
|
|
|
182
178
|
```javascript
|
|
183
179
|
const result = R.pipe(
|
|
184
|
-
{ a: 1, b: 'foo' },
|
|
180
|
+
{ a: 1, b: 'foo' },
|
|
185
181
|
R.addProp('c', 3)
|
|
186
182
|
)
|
|
187
183
|
// => { a: 1, b: 'foo', c: 3 }
|
|
188
184
|
```
|
|
189
185
|
|
|
190
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.pipe(%0A%09%7B%20a%3A%201%2C%20b%3A%20'foo'%20%7D%2C%
|
|
186
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
191
187
|
|
|
192
188
|
<details>
|
|
193
189
|
|
|
@@ -264,7 +260,7 @@ addPropToObjects<
|
|
|
264
260
|
): (list: T[]) => MergeTypes<T & { [P in K]: R }>[]
|
|
265
261
|
```
|
|
266
262
|
|
|
267
|
-
It receives list of objects and add new property to each item.
|
|
263
|
+
It receives list of objects and add new property to each item.
|
|
268
264
|
|
|
269
265
|
The value is based on result of `fn` function, which receives the current object as argument.
|
|
270
266
|
|
|
@@ -591,11 +587,11 @@ It returns `true`, if at least one member of `list` returns true, when passed to
|
|
|
591
587
|
```javascript
|
|
592
588
|
const list = [1, 2, 3]
|
|
593
589
|
const predicate = x => x * x > 8
|
|
594
|
-
R.any(
|
|
590
|
+
R.any(predicate)(list)
|
|
595
591
|
// => true
|
|
596
592
|
```
|
|
597
593
|
|
|
598
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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(
|
|
594
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
599
595
|
|
|
600
596
|
<details>
|
|
601
597
|
|
|
@@ -688,11 +684,11 @@ const fn = R.anyPass(
|
|
|
688
684
|
[isBig, isOdd]
|
|
689
685
|
)
|
|
690
686
|
|
|
691
|
-
const result = fn(input)
|
|
687
|
+
const result = fn(input)
|
|
692
688
|
// => true
|
|
693
689
|
```
|
|
694
690
|
|
|
695
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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)%
|
|
691
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
696
692
|
|
|
697
693
|
<details>
|
|
698
694
|
|
|
@@ -1138,11 +1134,11 @@ const input = {
|
|
|
1138
1134
|
c : 11,
|
|
1139
1135
|
}
|
|
1140
1136
|
|
|
1141
|
-
const result = condition(input)
|
|
1137
|
+
const result = condition(input)
|
|
1142
1138
|
// => true
|
|
1143
1139
|
```
|
|
1144
1140
|
|
|
1145
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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)%
|
|
1141
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
1146
1142
|
|
|
1147
1143
|
<details>
|
|
1148
1144
|
|
|
@@ -2386,6 +2382,76 @@ describe('R.dropWhile', () => {
|
|
|
2386
2382
|
|
|
2387
2383
|
[](#dropWhile)
|
|
2388
2384
|
|
|
2385
|
+
### duplicateBy
|
|
2386
|
+
|
|
2387
|
+
```typescript
|
|
2388
|
+
|
|
2389
|
+
duplicateBy<T, U>(fn: (x: T) => U): (list: T[]) => T[]
|
|
2390
|
+
```
|
|
2391
|
+
|
|
2392
|
+
```javascript
|
|
2393
|
+
const list = [{a:1}, {a:2}, {a:1}]
|
|
2394
|
+
const result = R.duplicateBy(x => x, list)
|
|
2395
|
+
|
|
2396
|
+
// => [{a:1}]
|
|
2397
|
+
```
|
|
2398
|
+
|
|
2399
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
2400
|
+
|
|
2401
|
+
<details>
|
|
2402
|
+
|
|
2403
|
+
<summary>All TypeScript definitions</summary>
|
|
2404
|
+
|
|
2405
|
+
```typescript
|
|
2406
|
+
duplicateBy<T, U>(fn: (x: T) => U): (list: T[]) => T[];
|
|
2407
|
+
```
|
|
2408
|
+
|
|
2409
|
+
</details>
|
|
2410
|
+
|
|
2411
|
+
<details>
|
|
2412
|
+
|
|
2413
|
+
<summary><strong>R.duplicateBy</strong> source</summary>
|
|
2414
|
+
|
|
2415
|
+
```javascript
|
|
2416
|
+
import { _Set } from '../src/_internals/set.js'
|
|
2417
|
+
|
|
2418
|
+
export function duplicateBy(fn) {
|
|
2419
|
+
return list => {
|
|
2420
|
+
const set = new _Set()
|
|
2421
|
+
|
|
2422
|
+
return list.filter(item => !set.checkUniqueness(fn(item)))
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
```
|
|
2426
|
+
|
|
2427
|
+
</details>
|
|
2428
|
+
|
|
2429
|
+
<details>
|
|
2430
|
+
|
|
2431
|
+
<summary><strong>Tests</strong></summary>
|
|
2432
|
+
|
|
2433
|
+
```javascript
|
|
2434
|
+
import { duplicateBy } from './duplicateBy.js'
|
|
2435
|
+
|
|
2436
|
+
test('happy', () => {
|
|
2437
|
+
expect(duplicateBy(Math.abs)([-2, -1, 0, 1, 2])).toEqual([1,2])
|
|
2438
|
+
})
|
|
2439
|
+
|
|
2440
|
+
test('returns an empty array for an empty array', () => {
|
|
2441
|
+
expect(duplicateBy(Math.abs)([])).toEqual([])
|
|
2442
|
+
})
|
|
2443
|
+
|
|
2444
|
+
test('uses R.uniq', () => {
|
|
2445
|
+
const list = [{ a: 1 }, { a: 2 }, { a: 1 }]
|
|
2446
|
+
const expected = [{ a: 1 }]
|
|
2447
|
+
expect(duplicateBy(x => x)(list)).toEqual(expected)
|
|
2448
|
+
})
|
|
2449
|
+
```
|
|
2450
|
+
|
|
2451
|
+
</details>
|
|
2452
|
+
|
|
2453
|
+
[](#duplicateBy)
|
|
2454
|
+
|
|
2389
2455
|
### eqBy
|
|
2390
2456
|
|
|
2391
2457
|
```typescript
|
|
@@ -3050,7 +3116,7 @@ const input = {
|
|
|
3050
3116
|
baz: 'baz',
|
|
3051
3117
|
}
|
|
3052
3118
|
const result = R.pipe(
|
|
3053
|
-
input,
|
|
3119
|
+
input,
|
|
3054
3120
|
evolve({
|
|
3055
3121
|
foo: x => x + 1,
|
|
3056
3122
|
})
|
|
@@ -3058,7 +3124,7 @@ const result = R.pipe(
|
|
|
3058
3124
|
// => result is { foo: 3, baz: 'baz' }
|
|
3059
3125
|
```
|
|
3060
3126
|
|
|
3061
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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%
|
|
3127
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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%09evolve(%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>
|
|
3062
3128
|
|
|
3063
3129
|
<details>
|
|
3064
3130
|
|
|
@@ -3323,6 +3389,10 @@ test('happy', () => {
|
|
|
3323
3389
|
|
|
3324
3390
|
expect(filter(isEven)([1, 2, 3, 4])).toEqual([2, 4])
|
|
3325
3391
|
})
|
|
3392
|
+
|
|
3393
|
+
test('using Boolean', () => {
|
|
3394
|
+
expect(filter(Boolean)([null, 0, 1, 2])).toEqual([1,2])
|
|
3395
|
+
})
|
|
3326
3396
|
```
|
|
3327
3397
|
|
|
3328
3398
|
</details>
|
|
@@ -3332,7 +3402,7 @@ test('happy', () => {
|
|
|
3332
3402
|
<summary><strong>TypeScript</strong> test</summary>
|
|
3333
3403
|
|
|
3334
3404
|
```typescript
|
|
3335
|
-
import { filter,
|
|
3405
|
+
import { filter, pipe } from 'rambda'
|
|
3336
3406
|
|
|
3337
3407
|
const list = [1, 2, 3]
|
|
3338
3408
|
|
|
@@ -3406,6 +3476,93 @@ describe('R.filter with array', () => {
|
|
|
3406
3476
|
|
|
3407
3477
|
[](#filter)
|
|
3408
3478
|
|
|
3479
|
+
### filterAsync
|
|
3480
|
+
|
|
3481
|
+
```typescript
|
|
3482
|
+
|
|
3483
|
+
filterAsync<T>(
|
|
3484
|
+
predicate: (value: T) => Promise<boolean>,
|
|
3485
|
+
): (list: T[]) => Promise<T[]>
|
|
3486
|
+
```
|
|
3487
|
+
|
|
3488
|
+
<details>
|
|
3489
|
+
|
|
3490
|
+
<summary>All TypeScript definitions</summary>
|
|
3491
|
+
|
|
3492
|
+
```typescript
|
|
3493
|
+
filterAsync<T>(
|
|
3494
|
+
predicate: (value: T) => Promise<boolean>,
|
|
3495
|
+
): (list: T[]) => Promise<T[]>;
|
|
3496
|
+
```
|
|
3497
|
+
|
|
3498
|
+
</details>
|
|
3499
|
+
|
|
3500
|
+
<details>
|
|
3501
|
+
|
|
3502
|
+
<summary><strong>R.filterAsync</strong> source</summary>
|
|
3503
|
+
|
|
3504
|
+
```javascript
|
|
3505
|
+
export function filterAsync(predicate) {
|
|
3506
|
+
return async list => {
|
|
3507
|
+
const willReturn = []
|
|
3508
|
+
let index = 0
|
|
3509
|
+
for (const x of list) {
|
|
3510
|
+
if (await predicate(x, index)) {
|
|
3511
|
+
willReturn.push(list[index])
|
|
3512
|
+
}
|
|
3513
|
+
index++
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
return willReturn
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
```
|
|
3520
|
+
|
|
3521
|
+
</details>
|
|
3522
|
+
|
|
3523
|
+
<details>
|
|
3524
|
+
|
|
3525
|
+
<summary><strong>Tests</strong></summary>
|
|
3526
|
+
|
|
3527
|
+
```javascript
|
|
3528
|
+
import { filterAsync } from './filterAsync.js'
|
|
3529
|
+
|
|
3530
|
+
test('happy', async () => {
|
|
3531
|
+
const isEven = async n => n % 2 === 0
|
|
3532
|
+
|
|
3533
|
+
expect(await filterAsync(isEven)([1, 2, 3, 4])).toEqual([2, 4])
|
|
3534
|
+
})
|
|
3535
|
+
```
|
|
3536
|
+
|
|
3537
|
+
</details>
|
|
3538
|
+
|
|
3539
|
+
<details>
|
|
3540
|
+
|
|
3541
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
3542
|
+
|
|
3543
|
+
```typescript
|
|
3544
|
+
import { filterAsync, pipeAsync } from 'rambda'
|
|
3545
|
+
|
|
3546
|
+
const list = [1, 2, 3]
|
|
3547
|
+
|
|
3548
|
+
describe('R.filter with array', () => {
|
|
3549
|
+
it('within pipe', async () => {
|
|
3550
|
+
const result = await pipeAsync(
|
|
3551
|
+
list,
|
|
3552
|
+
filterAsync(async x => {
|
|
3553
|
+
x // $ExpectType number
|
|
3554
|
+
return x > 1
|
|
3555
|
+
}),
|
|
3556
|
+
)
|
|
3557
|
+
result // $ExpectType number[]
|
|
3558
|
+
})
|
|
3559
|
+
})
|
|
3560
|
+
```
|
|
3561
|
+
|
|
3562
|
+
</details>
|
|
3563
|
+
|
|
3564
|
+
[](#filterAsync)
|
|
3565
|
+
|
|
3409
3566
|
### filterObject
|
|
3410
3567
|
|
|
3411
3568
|
```typescript
|
|
@@ -4070,15 +4227,15 @@ You must pass expected output type as a type argument.
|
|
|
4070
4227
|
|
|
4071
4228
|
```javascript
|
|
4072
4229
|
const result = R.flatten<number>([
|
|
4073
|
-
1,
|
|
4074
|
-
2,
|
|
4075
|
-
[3, 30, [300]],
|
|
4230
|
+
1,
|
|
4231
|
+
2,
|
|
4232
|
+
[3, 30, [300]],
|
|
4076
4233
|
[4]
|
|
4077
4234
|
])
|
|
4078
4235
|
// => [ 1, 2, 3, 30, 300, 4 ]
|
|
4079
4236
|
```
|
|
4080
4237
|
|
|
4081
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.flatten%3Cnumber%3E(%5B%0A%20%201%2C%
|
|
4238
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
4082
4239
|
|
|
4083
4240
|
<details>
|
|
4084
4241
|
|
|
@@ -4497,13 +4654,13 @@ describe('R.groupBy', () => {
|
|
|
4497
4654
|
|
|
4498
4655
|
```typescript
|
|
4499
4656
|
|
|
4500
|
-
head<T>(listOrString: T): T extends string ? string :
|
|
4501
|
-
T extends [] ? undefined:
|
|
4502
|
-
T extends readonly [infer F, ...infer R] ? F :
|
|
4657
|
+
head<T>(listOrString: T): T extends string ? string :
|
|
4658
|
+
T extends [] ? undefined:
|
|
4659
|
+
T extends readonly [infer F, ...infer R] ? F :
|
|
4503
4660
|
T extends readonly [infer F] ? F :
|
|
4504
4661
|
T extends [infer F] ? F :
|
|
4505
|
-
T extends [infer F, ...infer R] ? F :
|
|
4506
|
-
T extends unknown[] ? T[number] :
|
|
4662
|
+
T extends [infer F, ...infer R] ? F :
|
|
4663
|
+
T extends unknown[] ? T[number] :
|
|
4507
4664
|
undefined
|
|
4508
4665
|
```
|
|
4509
4666
|
|
|
@@ -4512,25 +4669,25 @@ It returns the first element of list or string `input`. It returns `undefined` i
|
|
|
4512
4669
|
```javascript
|
|
4513
4670
|
const result = [
|
|
4514
4671
|
R.head([1, 2, 3]),
|
|
4515
|
-
R.head('foo')
|
|
4672
|
+
R.head('foo')
|
|
4516
4673
|
]
|
|
4517
4674
|
// => [1, 'f']
|
|
4518
4675
|
```
|
|
4519
4676
|
|
|
4520
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.head(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.head('foo')%
|
|
4677
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
4521
4678
|
|
|
4522
4679
|
<details>
|
|
4523
4680
|
|
|
4524
4681
|
<summary>All TypeScript definitions</summary>
|
|
4525
4682
|
|
|
4526
4683
|
```typescript
|
|
4527
|
-
head<T>(listOrString: T): T extends string ? string :
|
|
4528
|
-
T extends [] ? undefined:
|
|
4529
|
-
T extends readonly [infer F, ...infer R] ? F :
|
|
4684
|
+
head<T>(listOrString: T): T extends string ? string :
|
|
4685
|
+
T extends [] ? undefined:
|
|
4686
|
+
T extends readonly [infer F, ...infer R] ? F :
|
|
4530
4687
|
T extends readonly [infer F] ? F :
|
|
4531
4688
|
T extends [infer F] ? F :
|
|
4532
|
-
T extends [infer F, ...infer R] ? F :
|
|
4533
|
-
T extends unknown[] ? T[number] :
|
|
4689
|
+
T extends [infer F, ...infer R] ? F :
|
|
4690
|
+
T extends unknown[] ? T[number] :
|
|
4534
4691
|
undefined;
|
|
4535
4692
|
```
|
|
4536
4693
|
|
|
@@ -4625,7 +4782,7 @@ describe('R.head', () => {
|
|
|
4625
4782
|
|
|
4626
4783
|
```typescript
|
|
4627
4784
|
|
|
4628
|
-
includes
|
|
4785
|
+
includes(s: string): (list: readonly string[] | string) => boolean
|
|
4629
4786
|
```
|
|
4630
4787
|
|
|
4631
4788
|
If `input` is string, then this method work as native `String.includes`.
|
|
@@ -4647,8 +4804,8 @@ const result = [
|
|
|
4647
4804
|
<summary>All TypeScript definitions</summary>
|
|
4648
4805
|
|
|
4649
4806
|
```typescript
|
|
4650
|
-
includes
|
|
4651
|
-
includes<T>(
|
|
4807
|
+
includes(s: string): (list: readonly string[] | string) => boolean;
|
|
4808
|
+
includes<T>(target: T): (list: readonly T[]) => boolean;
|
|
4652
4809
|
```
|
|
4653
4810
|
|
|
4654
4811
|
</details>
|
|
@@ -4725,7 +4882,7 @@ test('with wrong input that does not throw', () => {
|
|
|
4725
4882
|
<summary><strong>TypeScript</strong> test</summary>
|
|
4726
4883
|
|
|
4727
4884
|
```typescript
|
|
4728
|
-
import {
|
|
4885
|
+
import { pipe, includes } from 'rambda'
|
|
4729
4886
|
|
|
4730
4887
|
describe('R.includes', () => {
|
|
4731
4888
|
it('happy', () => {
|
|
@@ -4737,6 +4894,16 @@ describe('R.includes', () => {
|
|
|
4737
4894
|
const result = pipe('foo', includes('bar'))
|
|
4738
4895
|
result // $ExpectType boolean
|
|
4739
4896
|
})
|
|
4897
|
+
it('with array of strings', () => {
|
|
4898
|
+
const result = pipe(['1','2'], includes('1'))
|
|
4899
|
+
result // $ExpectType boolean
|
|
4900
|
+
})
|
|
4901
|
+
it('without R.pipe', () => {
|
|
4902
|
+
const result1 = includes('1')(['1', '2'])
|
|
4903
|
+
const result2 = includes(1)([1, 2])
|
|
4904
|
+
result1 // $ExpectType boolean
|
|
4905
|
+
result2 // $ExpectType boolean
|
|
4906
|
+
})
|
|
4740
4907
|
})
|
|
4741
4908
|
```
|
|
4742
4909
|
|
|
@@ -4744,6 +4911,109 @@ describe('R.includes', () => {
|
|
|
4744
4911
|
|
|
4745
4912
|
[](#includes)
|
|
4746
4913
|
|
|
4914
|
+
### indexBy
|
|
4915
|
+
|
|
4916
|
+
```typescript
|
|
4917
|
+
|
|
4918
|
+
indexBy<T, K extends keyof T>(
|
|
4919
|
+
property: K
|
|
4920
|
+
): (list: readonly T[]) => Record<string, T>
|
|
4921
|
+
```
|
|
4922
|
+
|
|
4923
|
+
It transforms list of objects to object using specified property as the base for the returned object.
|
|
4924
|
+
|
|
4925
|
+
```javascript
|
|
4926
|
+
const result = R.indexBy(
|
|
4927
|
+
'id'
|
|
4928
|
+
)([{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}])
|
|
4929
|
+
// => {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
|
|
4930
|
+
```
|
|
4931
|
+
|
|
4932
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
4933
|
+
|
|
4934
|
+
<details>
|
|
4935
|
+
|
|
4936
|
+
<summary>All TypeScript definitions</summary>
|
|
4937
|
+
|
|
4938
|
+
```typescript
|
|
4939
|
+
indexBy<T, K extends keyof T>(
|
|
4940
|
+
property: K
|
|
4941
|
+
): (list: readonly T[]) => Record<string, T>;
|
|
4942
|
+
indexBy<T, K extends keyof T>(
|
|
4943
|
+
property: K
|
|
4944
|
+
): (list: T[]) => Record<string, T>;
|
|
4945
|
+
|
|
4946
|
+
// API_MARKER_END
|
|
4947
|
+
// ============================================
|
|
4948
|
+
```
|
|
4949
|
+
|
|
4950
|
+
</details>
|
|
4951
|
+
|
|
4952
|
+
<details>
|
|
4953
|
+
|
|
4954
|
+
<summary><strong>R.indexBy</strong> source</summary>
|
|
4955
|
+
|
|
4956
|
+
```javascript
|
|
4957
|
+
export function indexBy(property){
|
|
4958
|
+
return list => {
|
|
4959
|
+
const toReturn = {}
|
|
4960
|
+
for (let i = 0; i < list.length; i++){
|
|
4961
|
+
const item = list[ i ]
|
|
4962
|
+
const key = item[property]
|
|
4963
|
+
if(key !== undefined){
|
|
4964
|
+
toReturn[ key ] = item
|
|
4965
|
+
}
|
|
4966
|
+
}
|
|
4967
|
+
|
|
4968
|
+
return toReturn
|
|
4969
|
+
}
|
|
4970
|
+
}
|
|
4971
|
+
```
|
|
4972
|
+
|
|
4973
|
+
</details>
|
|
4974
|
+
|
|
4975
|
+
<details>
|
|
4976
|
+
|
|
4977
|
+
<summary><strong>Tests</strong></summary>
|
|
4978
|
+
|
|
4979
|
+
```javascript
|
|
4980
|
+
import { indexBy } from './indexBy.js'
|
|
4981
|
+
|
|
4982
|
+
test('happy', () => {
|
|
4983
|
+
const list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}]
|
|
4984
|
+
|
|
4985
|
+
expect(
|
|
4986
|
+
indexBy('id')(list)
|
|
4987
|
+
).toEqual(
|
|
4988
|
+
{abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
|
|
4989
|
+
)
|
|
4990
|
+
})
|
|
4991
|
+
```
|
|
4992
|
+
|
|
4993
|
+
</details>
|
|
4994
|
+
|
|
4995
|
+
<details>
|
|
4996
|
+
|
|
4997
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
4998
|
+
|
|
4999
|
+
```typescript
|
|
5000
|
+
import { pipe, indexBy } from 'rambda'
|
|
5001
|
+
|
|
5002
|
+
it('R.indexBy', () => {
|
|
5003
|
+
const list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}]
|
|
5004
|
+
const result = pipe(
|
|
5005
|
+
list,
|
|
5006
|
+
indexBy('id')
|
|
5007
|
+
)
|
|
5008
|
+
result.abc // $ExpectType { id: string; title: string; }
|
|
5009
|
+
result.foo // $ExpectType { id: string; title: string; }
|
|
5010
|
+
})
|
|
5011
|
+
```
|
|
5012
|
+
|
|
5013
|
+
</details>
|
|
5014
|
+
|
|
5015
|
+
[](#indexBy)
|
|
5016
|
+
|
|
4747
5017
|
### indexOf
|
|
4748
5018
|
|
|
4749
5019
|
```typescript
|
|
@@ -4802,18 +5072,18 @@ test('will throw with bad input', () => {
|
|
|
4802
5072
|
expect(() => indexOf([])(true)).toThrow()
|
|
4803
5073
|
})
|
|
4804
5074
|
|
|
4805
|
-
test('
|
|
5075
|
+
test('with numbers', () => {
|
|
4806
5076
|
expect(indexOf(3)([1, 2, 3, 4])).toBe(2)
|
|
4807
5077
|
expect(indexOf(10)([1, 2, 3, 4])).toBe(-1)
|
|
4808
5078
|
})
|
|
4809
5079
|
|
|
4810
|
-
test('list of objects
|
|
5080
|
+
test('list of objects use R.equals', () => {
|
|
4811
5081
|
const listOfObjects = [{ a: 1 }, { b: 2 }, { c: 3 }]
|
|
4812
5082
|
expect(indexOf({ c: 4 })(listOfObjects)).toBe(-1)
|
|
4813
5083
|
expect(indexOf({ c: 3 })(listOfObjects)).toBe(2)
|
|
4814
5084
|
})
|
|
4815
5085
|
|
|
4816
|
-
test('list of arrays
|
|
5086
|
+
test('list of arrays use R.equals', () => {
|
|
4817
5087
|
const listOfLists = [[1], [2, 3], [2, 3, 4], [2, 3], [1], []]
|
|
4818
5088
|
expect(indexOf([])(listOfLists)).toBe(5)
|
|
4819
5089
|
expect(indexOf([1])(listOfLists)).toBe(0)
|
|
@@ -4855,13 +5125,13 @@ It returns all but the last element of list or string `input`.
|
|
|
4855
5125
|
|
|
4856
5126
|
```javascript
|
|
4857
5127
|
const result = [
|
|
4858
|
-
R.init([1, 2, 3]) ,
|
|
5128
|
+
R.init([1, 2, 3]) ,
|
|
4859
5129
|
R.init('foo') // => 'fo'
|
|
4860
5130
|
]
|
|
4861
5131
|
// => [[1, 2], 'fo']
|
|
4862
5132
|
```
|
|
4863
5133
|
|
|
4864
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.init(%5B1%2C%202%2C%203%5D)%20%2C%
|
|
5134
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
4865
5135
|
|
|
4866
5136
|
<details>
|
|
4867
5137
|
|
|
@@ -5097,9 +5367,6 @@ const expected = 'foo is BAR even 1 more'
|
|
|
5097
5367
|
|
|
5098
5368
|
```typescript
|
|
5099
5369
|
interpolate(inputWithTags: string): (templateArguments: object) => string;
|
|
5100
|
-
|
|
5101
|
-
// API_MARKER_END
|
|
5102
|
-
// ===========================================
|
|
5103
5370
|
```
|
|
5104
5371
|
|
|
5105
5372
|
</details>
|
|
@@ -5436,13 +5703,13 @@ it('R.join', () => {
|
|
|
5436
5703
|
|
|
5437
5704
|
```typescript
|
|
5438
5705
|
|
|
5439
|
-
last<T>(listOrString: T): T extends string ? string :
|
|
5440
|
-
T extends [] ? undefined :
|
|
5441
|
-
T extends readonly [...infer R, infer L] ? L :
|
|
5706
|
+
last<T>(listOrString: T): T extends string ? string :
|
|
5707
|
+
T extends [] ? undefined :
|
|
5708
|
+
T extends readonly [...infer R, infer L] ? L :
|
|
5442
5709
|
T extends readonly [infer L] ? L :
|
|
5443
5710
|
T extends [infer L] ? L :
|
|
5444
|
-
T extends [...infer R, infer L] ? L :
|
|
5445
|
-
T extends unknown[] ? T[number] :
|
|
5711
|
+
T extends [...infer R, infer L] ? L :
|
|
5712
|
+
T extends unknown[] ? T[number] :
|
|
5446
5713
|
undefined
|
|
5447
5714
|
```
|
|
5448
5715
|
|
|
@@ -5463,13 +5730,13 @@ const result = [
|
|
|
5463
5730
|
<summary>All TypeScript definitions</summary>
|
|
5464
5731
|
|
|
5465
5732
|
```typescript
|
|
5466
|
-
last<T>(listOrString: T): T extends string ? string :
|
|
5467
|
-
T extends [] ? undefined :
|
|
5468
|
-
T extends readonly [...infer R, infer L] ? L :
|
|
5733
|
+
last<T>(listOrString: T): T extends string ? string :
|
|
5734
|
+
T extends [] ? undefined :
|
|
5735
|
+
T extends readonly [...infer R, infer L] ? L :
|
|
5469
5736
|
T extends readonly [infer L] ? L :
|
|
5470
5737
|
T extends [infer L] ? L :
|
|
5471
|
-
T extends [...infer R, infer L] ? L :
|
|
5472
|
-
T extends unknown[] ? T[number] :
|
|
5738
|
+
T extends [...infer R, infer L] ? L :
|
|
5739
|
+
T extends unknown[] ? T[number] :
|
|
5473
5740
|
undefined;
|
|
5474
5741
|
```
|
|
5475
5742
|
|
|
@@ -5766,16 +6033,6 @@ mapAsync<T extends IterableContainer, U>(
|
|
|
5766
6033
|
mapAsync<T extends IterableContainer, U>(
|
|
5767
6034
|
fn: (value: T[number]) => Promise<U>,
|
|
5768
6035
|
): (data: T) => Promise<Mapped<T, U>>;
|
|
5769
|
-
mapAsync<T extends IterableContainer, U>(
|
|
5770
|
-
fn: (value: T[number], index: number) => Promise<U>,
|
|
5771
|
-
data: T
|
|
5772
|
-
): Promise<Mapped<T, U>>;
|
|
5773
|
-
mapAsync<T extends IterableContainer, U>(
|
|
5774
|
-
fn: (value: T[number]) => Promise<U>,
|
|
5775
|
-
data: T
|
|
5776
|
-
): Promise<Mapped<T, U>>;
|
|
5777
|
-
...
|
|
5778
|
-
...
|
|
5779
6036
|
```
|
|
5780
6037
|
|
|
5781
6038
|
</details>
|
|
@@ -5789,8 +6046,8 @@ export function mapAsync(fn) {
|
|
|
5789
6046
|
return async list => {
|
|
5790
6047
|
const willReturn = []
|
|
5791
6048
|
let i = 0
|
|
5792
|
-
for (const
|
|
5793
|
-
willReturn.push(await fn(
|
|
6049
|
+
for (const x of list) {
|
|
6050
|
+
willReturn.push(await fn(x, i++))
|
|
5794
6051
|
}
|
|
5795
6052
|
|
|
5796
6053
|
return willReturn
|
|
@@ -5861,14 +6118,12 @@ test('error', async () => {
|
|
|
5861
6118
|
<summary><strong>TypeScript</strong> test</summary>
|
|
5862
6119
|
|
|
5863
6120
|
```typescript
|
|
5864
|
-
import { mapAsync, pipeAsync } from 'rambda'
|
|
5865
|
-
import { delay } from 'rambdax'
|
|
6121
|
+
import { mapAsync, pipeAsync, map } from 'rambda'
|
|
5866
6122
|
|
|
5867
6123
|
const list = ['a', 'bc', 'def']
|
|
6124
|
+
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
|
|
5868
6125
|
|
|
5869
6126
|
it('R.mapAsync', async () => {
|
|
5870
|
-
const fn = async (x:unknown) => x as number + 1
|
|
5871
|
-
|
|
5872
6127
|
const result = await pipeAsync(
|
|
5873
6128
|
list,
|
|
5874
6129
|
mapAsync(async x => {
|
|
@@ -5877,7 +6132,7 @@ it('R.mapAsync', async () => {
|
|
|
5877
6132
|
return x.length % 2 ? x.length + 1 : x.length + 10
|
|
5878
6133
|
}),
|
|
5879
6134
|
x => x,
|
|
5880
|
-
|
|
6135
|
+
map(x => x +1),
|
|
5881
6136
|
mapAsync(async x => {
|
|
5882
6137
|
await delay(100)
|
|
5883
6138
|
return x + 1
|
|
@@ -6080,7 +6335,18 @@ describe('R.mapObject', () => {
|
|
|
6080
6335
|
|
|
6081
6336
|
result // $ExpectType { a: string; }
|
|
6082
6337
|
})
|
|
6083
|
-
it('iterable with
|
|
6338
|
+
it('iterable with one arguments', () => {
|
|
6339
|
+
const result = pipe(
|
|
6340
|
+
{ a: [1,2,3], b: 'foo' },
|
|
6341
|
+
mapObject(a => {
|
|
6342
|
+
a // $ExpectType string | number[]
|
|
6343
|
+
return typeof a as string
|
|
6344
|
+
}),
|
|
6345
|
+
)
|
|
6346
|
+
|
|
6347
|
+
result // $ExpectType { a: string; b: string; }
|
|
6348
|
+
})
|
|
6349
|
+
it('iterable with two arguments', () => {
|
|
6084
6350
|
const result = pipe(
|
|
6085
6351
|
{ a: 1, b: 'foo' },
|
|
6086
6352
|
mapObject((a, b) => {
|
|
@@ -6242,16 +6508,6 @@ mapParallelAsync<T extends IterableContainer, U>(
|
|
|
6242
6508
|
mapParallelAsync<T extends IterableContainer, U>(
|
|
6243
6509
|
fn: (value: T[number]) => Promise<U>,
|
|
6244
6510
|
): (data: T) => Promise<Mapped<T, U>>;
|
|
6245
|
-
mapParallelAsync<T extends IterableContainer, U>(
|
|
6246
|
-
fn: (value: T[number], index: number) => Promise<U>,
|
|
6247
|
-
data: T
|
|
6248
|
-
): Promise<Mapped<T, U>>;
|
|
6249
|
-
mapParallelAsync<T extends IterableContainer, U>(
|
|
6250
|
-
fn: (value: T[number]) => Promise<U>,
|
|
6251
|
-
data: T
|
|
6252
|
-
): Promise<Mapped<T, U>>;
|
|
6253
|
-
...
|
|
6254
|
-
...
|
|
6255
6511
|
```
|
|
6256
6512
|
|
|
6257
6513
|
</details>
|
|
@@ -6304,19 +6560,146 @@ test('pipeAsync', async () => {
|
|
|
6304
6560
|
|
|
6305
6561
|
[](#mapParallelAsync)
|
|
6306
6562
|
|
|
6307
|
-
###
|
|
6563
|
+
### mapPropObject
|
|
6308
6564
|
|
|
6309
6565
|
```typescript
|
|
6310
6566
|
|
|
6311
|
-
|
|
6567
|
+
mapPropObject<T extends object, K extends keyof T, Value>(
|
|
6568
|
+
valueMapper: (
|
|
6569
|
+
value: T[K] extends ReadonlyArray<infer ElementType> ? ElementType : never,
|
|
6570
|
+
data: T[K],
|
|
6571
|
+
) => Value,
|
|
6572
|
+
prop: K,
|
|
6573
|
+
): (data: T) => T[K] extends ReadonlyArray<any>
|
|
6574
|
+
? MergeTypes<Omit<T, K> & { [P in K]: Value[] }>
|
|
6575
|
+
: never
|
|
6312
6576
|
```
|
|
6313
6577
|
|
|
6314
|
-
|
|
6578
|
+
It maps over a property of object that is a list.
|
|
6315
6579
|
|
|
6316
6580
|
```javascript
|
|
6317
|
-
const result =
|
|
6318
|
-
|
|
6319
|
-
|
|
6581
|
+
const result = pipe(
|
|
6582
|
+
{ a: [1,2,3], b: 'foo' },
|
|
6583
|
+
mapPropObject(x => {
|
|
6584
|
+
x // $ExpectType { a: number; b: string; }
|
|
6585
|
+
return {
|
|
6586
|
+
a: x,
|
|
6587
|
+
flag: x > 2,
|
|
6588
|
+
}
|
|
6589
|
+
}, 'a'),
|
|
6590
|
+
)
|
|
6591
|
+
// => { a: [{ a: 1, flag: false },{ a: 2, flag: false }, { a: 3, flag: true }], b: 'foo' }
|
|
6592
|
+
```
|
|
6593
|
+
|
|
6594
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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(x%20%3D%3E%20%7B%0A%09%09x%20%2F%2F%20%24ExpectType%20%7B%20a%3A%20number%3B%20b%3A%20string%3B%20%7D%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%20'a')%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>
|
|
6595
|
+
|
|
6596
|
+
<details>
|
|
6597
|
+
|
|
6598
|
+
<summary>All TypeScript definitions</summary>
|
|
6599
|
+
|
|
6600
|
+
```typescript
|
|
6601
|
+
mapPropObject<T extends object, K extends keyof T, Value>(
|
|
6602
|
+
valueMapper: (
|
|
6603
|
+
value: T[K] extends ReadonlyArray<infer ElementType> ? ElementType : never,
|
|
6604
|
+
data: T[K],
|
|
6605
|
+
) => Value,
|
|
6606
|
+
prop: K,
|
|
6607
|
+
): (data: T) => T[K] extends ReadonlyArray<any>
|
|
6608
|
+
? MergeTypes<Omit<T, K> & { [P in K]: Value[] }>
|
|
6609
|
+
: never;
|
|
6610
|
+
```
|
|
6611
|
+
|
|
6612
|
+
</details>
|
|
6613
|
+
|
|
6614
|
+
<details>
|
|
6615
|
+
|
|
6616
|
+
<summary><strong>R.mapPropObject</strong> source</summary>
|
|
6617
|
+
|
|
6618
|
+
```javascript
|
|
6619
|
+
export function mapPropObject(fn, prop) {
|
|
6620
|
+
return obj => {
|
|
6621
|
+
if (!Array.isArray(obj[prop])) return obj
|
|
6622
|
+
|
|
6623
|
+
return {
|
|
6624
|
+
...obj,
|
|
6625
|
+
[prop]: obj[prop].map(fn)
|
|
6626
|
+
}
|
|
6627
|
+
}
|
|
6628
|
+
}
|
|
6629
|
+
```
|
|
6630
|
+
|
|
6631
|
+
</details>
|
|
6632
|
+
|
|
6633
|
+
<details>
|
|
6634
|
+
|
|
6635
|
+
<summary><strong>Tests</strong></summary>
|
|
6636
|
+
|
|
6637
|
+
```javascript
|
|
6638
|
+
import { mapPropObject } from './mapPropObject.js'
|
|
6639
|
+
import { pipe } from './pipe.js'
|
|
6640
|
+
|
|
6641
|
+
it('happy', () => {
|
|
6642
|
+
const result = pipe(
|
|
6643
|
+
{ a: [1, 2, 3], b: 'foo' },
|
|
6644
|
+
mapPropObject(x => ({ a: x, flag: x > 2 }), 'a'),
|
|
6645
|
+
)
|
|
6646
|
+
|
|
6647
|
+
expect(result).toEqual({
|
|
6648
|
+
a: [
|
|
6649
|
+
{ a: 1, flag: false },
|
|
6650
|
+
{ a: 2, flag: false },
|
|
6651
|
+
{ a: 3, flag: true },
|
|
6652
|
+
],
|
|
6653
|
+
b: 'foo',
|
|
6654
|
+
})
|
|
6655
|
+
})
|
|
6656
|
+
```
|
|
6657
|
+
|
|
6658
|
+
</details>
|
|
6659
|
+
|
|
6660
|
+
<details>
|
|
6661
|
+
|
|
6662
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
6663
|
+
|
|
6664
|
+
```typescript
|
|
6665
|
+
import { mapPropObject, pipe } from 'rambda'
|
|
6666
|
+
|
|
6667
|
+
describe('R.mapPropObject', () => {
|
|
6668
|
+
it('iterable with one arguments', () => {
|
|
6669
|
+
const result = pipe(
|
|
6670
|
+
{ a: [1,2,3], b: 'foo' },
|
|
6671
|
+
mapPropObject(x => {
|
|
6672
|
+
x // $ExpectType number
|
|
6673
|
+
return {
|
|
6674
|
+
a: x,
|
|
6675
|
+
flag: x > 2,
|
|
6676
|
+
}
|
|
6677
|
+
}, 'a'),
|
|
6678
|
+
)
|
|
6679
|
+
|
|
6680
|
+
result.a // $ExpectType { a: number; flag: boolean; }[]
|
|
6681
|
+
result.b // $ExpectType string
|
|
6682
|
+
})
|
|
6683
|
+
})
|
|
6684
|
+
```
|
|
6685
|
+
|
|
6686
|
+
</details>
|
|
6687
|
+
|
|
6688
|
+
[](#mapPropObject)
|
|
6689
|
+
|
|
6690
|
+
### match
|
|
6691
|
+
|
|
6692
|
+
```typescript
|
|
6693
|
+
|
|
6694
|
+
match(regExpression: RegExp): (str: string) => string[]
|
|
6695
|
+
```
|
|
6696
|
+
|
|
6697
|
+
Curried version of `String.prototype.match` which returns empty array, when there is no match.
|
|
6698
|
+
|
|
6699
|
+
```javascript
|
|
6700
|
+
const result = [
|
|
6701
|
+
R.match('a', 'foo'),
|
|
6702
|
+
R.match(/([a-z]a)/g, 'bananas')
|
|
6320
6703
|
]
|
|
6321
6704
|
// => [[], ['ba', 'na', 'na']]
|
|
6322
6705
|
```
|
|
@@ -6643,11 +7026,11 @@ It replaces `index` in array `list` with the result of `replaceFn(list[i])`.
|
|
|
6643
7026
|
```javascript
|
|
6644
7027
|
const result = R.pipe(
|
|
6645
7028
|
[1, 2, 3],
|
|
6646
|
-
R.modifyItemAtIndex(1,
|
|
7029
|
+
R.modifyItemAtIndex(1, x => x + 1)
|
|
6647
7030
|
) // => [1, 3, 3]
|
|
6648
7031
|
```
|
|
6649
7032
|
|
|
6650
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.pipe(%0A%09%5B1%2C%202%2C%203%5D%2C%0A%09R.modifyItemAtIndex(1%2C%
|
|
7033
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
6651
7034
|
|
|
6652
7035
|
<details>
|
|
6653
7036
|
|
|
@@ -6804,10 +7187,17 @@ export function modifyPath(pathInput, fn) {
|
|
|
6804
7187
|
```javascript
|
|
6805
7188
|
import { modifyPath } from './modifyPath.js'
|
|
6806
7189
|
|
|
7190
|
+
const obj = { a: { b: { c: 1 } } }
|
|
7191
|
+
|
|
6807
7192
|
test('happy', () => {
|
|
6808
|
-
const result = modifyPath('a.b.c', x => x + 1)(
|
|
7193
|
+
const result = modifyPath('a.b.c', x => x + 1)(obj)
|
|
6809
7194
|
expect(result).toEqual({ a: { b: { c: 2 } } })
|
|
6810
7195
|
})
|
|
7196
|
+
|
|
7197
|
+
test('works only on existing paths', () => {
|
|
7198
|
+
const result = modifyPath('a.b.d', x => x + 1)(obj)
|
|
7199
|
+
expect(result).toEqual(obj)
|
|
7200
|
+
})
|
|
6811
7201
|
```
|
|
6812
7202
|
|
|
6813
7203
|
</details>
|
|
@@ -6860,11 +7250,11 @@ const person = {
|
|
|
6860
7250
|
name : 'foo',
|
|
6861
7251
|
age : 20,
|
|
6862
7252
|
}
|
|
6863
|
-
const result = R.modifyProp('age', x => x + 1)(person)
|
|
7253
|
+
const result = R.modifyProp('age', x => x + 1)(person)
|
|
6864
7254
|
// => {name: 'foo', age: 21}
|
|
6865
7255
|
```
|
|
6866
7256
|
|
|
6867
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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)%
|
|
7257
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
6868
7258
|
|
|
6869
7259
|
<details>
|
|
6870
7260
|
|
|
@@ -7287,13 +7677,13 @@ const propsToOmit = 'a,c,d'
|
|
|
7287
7677
|
const propsToOmitList = ['a', 'c', 'd']
|
|
7288
7678
|
|
|
7289
7679
|
const result = [
|
|
7290
|
-
R.omit(propsToOmit, obj),
|
|
7291
|
-
R.omit(propsToOmitList, obj)
|
|
7680
|
+
R.omit(propsToOmit, obj),
|
|
7681
|
+
R.omit(propsToOmitList, obj)
|
|
7292
7682
|
]
|
|
7293
7683
|
// => [{b: 2}, {b: 2}]
|
|
7294
7684
|
```
|
|
7295
7685
|
|
|
7296
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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%
|
|
7686
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
7297
7687
|
|
|
7298
7688
|
<details>
|
|
7299
7689
|
|
|
@@ -8370,8 +8760,8 @@ test('happy', () => {
|
|
|
8370
8760
|
```typescript
|
|
8371
8761
|
import {
|
|
8372
8762
|
type MergeTypes,
|
|
8373
|
-
allPass,
|
|
8374
8763
|
append,
|
|
8764
|
+
assertType,
|
|
8375
8765
|
defaultTo,
|
|
8376
8766
|
drop,
|
|
8377
8767
|
dropLast,
|
|
@@ -8380,12 +8770,9 @@ import {
|
|
|
8380
8770
|
find,
|
|
8381
8771
|
head,
|
|
8382
8772
|
map,
|
|
8383
|
-
mapObject,
|
|
8384
|
-
path,
|
|
8385
8773
|
pick,
|
|
8386
8774
|
pipe,
|
|
8387
8775
|
split,
|
|
8388
|
-
tap,
|
|
8389
8776
|
union,
|
|
8390
8777
|
} from 'rambda'
|
|
8391
8778
|
type IsNotNever<T> = [T] extends [never] ? false : true
|
|
@@ -8404,12 +8791,6 @@ interface Book extends BaseBook {
|
|
|
8404
8791
|
}
|
|
8405
8792
|
status?: Status
|
|
8406
8793
|
}
|
|
8407
|
-
interface MustReadBook extends Book {
|
|
8408
|
-
status: 'must-read'
|
|
8409
|
-
}
|
|
8410
|
-
interface FamousBook extends Book {
|
|
8411
|
-
status: 'famous'
|
|
8412
|
-
}
|
|
8413
8794
|
interface BookWithBookmarkStatus extends Book {
|
|
8414
8795
|
bookmarkFlag: boolean
|
|
8415
8796
|
}
|
|
@@ -8417,14 +8798,13 @@ interface BookWithReadStatus extends Book {
|
|
|
8417
8798
|
readFlag: boolean
|
|
8418
8799
|
}
|
|
8419
8800
|
type BookToRead = BookWithBookmarkStatus & BookWithReadStatus
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
}
|
|
8423
|
-
interface BookWithUserRating extends Book {
|
|
8424
|
-
userRating: number
|
|
8801
|
+
type FamousBook = Book & {
|
|
8802
|
+
status: 'famous'
|
|
8425
8803
|
}
|
|
8426
|
-
type BookWithDetails = BookWithDescription & BookWithUserRating
|
|
8427
8804
|
|
|
8805
|
+
const checkIfFamous = (x: Book): x is FamousBook => {
|
|
8806
|
+
return x.status === 'famous'
|
|
8807
|
+
}
|
|
8428
8808
|
const zaratustra: BaseBook = {
|
|
8429
8809
|
title: 'Zaratustra',
|
|
8430
8810
|
year: 1956,
|
|
@@ -8448,11 +8828,6 @@ const awardedBrothersKaramazov: Book = {
|
|
|
8448
8828
|
years: [1869, 1870],
|
|
8449
8829
|
},
|
|
8450
8830
|
}
|
|
8451
|
-
const awardedBrothersKaramazovToRead: BookToRead = {
|
|
8452
|
-
...awardedBrothersKaramazov,
|
|
8453
|
-
readFlag: true,
|
|
8454
|
-
bookmarkFlag: true,
|
|
8455
|
-
}
|
|
8456
8831
|
const awardedZaratustraToRead: BookToRead = {
|
|
8457
8832
|
...awardedZaratustra,
|
|
8458
8833
|
readFlag: true,
|
|
@@ -8469,40 +8844,9 @@ const awardedBaseValue: Book = {
|
|
|
8469
8844
|
|
|
8470
8845
|
type Status = 'famous' | 'can be skipped' | 'must-read'
|
|
8471
8846
|
|
|
8472
|
-
function checkIfMustRead(x: Book): x is MustReadBook {
|
|
8473
|
-
return (x as MustReadBook).status === 'must-read'
|
|
8474
|
-
}
|
|
8475
|
-
function checkIfFamous(x: Book): x is FamousBook {
|
|
8476
|
-
return (x as FamousBook).status === 'famous'
|
|
8477
|
-
}
|
|
8478
|
-
function checkReadStatus(x: Book): x is BookWithReadStatus {
|
|
8479
|
-
return (x as BookWithReadStatus).readFlag
|
|
8480
|
-
}
|
|
8481
|
-
function checkBookmarkStatus(x: Book): x is BookWithBookmarkStatus {
|
|
8482
|
-
return (x as BookWithBookmarkStatus).bookmarkFlag
|
|
8483
|
-
}
|
|
8484
8847
|
function checkBookToRead(x: Book): x is BookToRead {
|
|
8485
8848
|
return (x as BookToRead).readFlag && (x as BookToRead).bookmarkFlag
|
|
8486
8849
|
}
|
|
8487
|
-
function checkHasDescription(x: Book): x is BookWithDescription {
|
|
8488
|
-
return (x as BookWithDescription).description !== undefined
|
|
8489
|
-
}
|
|
8490
|
-
function checkHasUserRating(x: Book): x is BookWithUserRating {
|
|
8491
|
-
return (x as BookWithUserRating).userRating !== undefined
|
|
8492
|
-
}
|
|
8493
|
-
|
|
8494
|
-
function assertType<T, U extends T>(fn: (x: T) => x is U) {
|
|
8495
|
-
return (x: T) => {
|
|
8496
|
-
if (fn(x)) {
|
|
8497
|
-
return x
|
|
8498
|
-
}
|
|
8499
|
-
throw new Error('type assertion failed')
|
|
8500
|
-
}
|
|
8501
|
-
}
|
|
8502
|
-
function convertToType<T>() {
|
|
8503
|
-
return <U>(x: U) => x as unknown as T
|
|
8504
|
-
}
|
|
8505
|
-
// const convertToType = <T>(x: unknown)=> x as unknown as T
|
|
8506
8850
|
|
|
8507
8851
|
function tapFn<T, U>(
|
|
8508
8852
|
transformFn: (x: T) => U,
|
|
@@ -8552,17 +8896,10 @@ describe('real use cases - books', () => {
|
|
|
8552
8896
|
evolve({
|
|
8553
8897
|
year: x => x + 1,
|
|
8554
8898
|
}),
|
|
8555
|
-
// convertToType<BookWithDescription>(),
|
|
8556
|
-
// dissocPath<Book>('description'),
|
|
8557
|
-
// convertToType<Record<string, string>>(),
|
|
8558
|
-
// mapObject((x) => {
|
|
8559
|
-
// return x as unknown as number;
|
|
8560
|
-
// }),
|
|
8561
8899
|
simplify,
|
|
8562
8900
|
pick('year'),
|
|
8563
8901
|
)
|
|
8564
8902
|
const result = getResult(zaratustra)
|
|
8565
|
-
type Foo = MergeTypes<typeof result>
|
|
8566
8903
|
const final: Expect<IsNotNever<typeof result>> = true
|
|
8567
8904
|
})
|
|
8568
8905
|
it('case 3', () => {
|
|
@@ -8615,7 +8952,7 @@ const result = await R.pipeAsync(
|
|
|
8615
8952
|
await R.delay(100)
|
|
8616
8953
|
return x + 2
|
|
8617
8954
|
},
|
|
8618
|
-
|
|
8955
|
+
x => x +2,
|
|
8619
8956
|
async x => {
|
|
8620
8957
|
const delayed = await R.delay(100)
|
|
8621
8958
|
return delayed + x
|
|
@@ -8624,7 +8961,7 @@ const result = await R.pipeAsync(
|
|
|
8624
8961
|
// `result` resolves to `RAMBDAX_DELAY104`
|
|
8625
8962
|
```
|
|
8626
8963
|
|
|
8627
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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%
|
|
8964
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
8628
8965
|
|
|
8629
8966
|
<details>
|
|
8630
8967
|
|
|
@@ -8736,11 +9073,11 @@ Basically, this is `R.map(R.prop(property))`.
|
|
|
8736
9073
|
const list = [{a: 1}, {a: 2}, {b: 3}]
|
|
8737
9074
|
const property = 'a'
|
|
8738
9075
|
|
|
8739
|
-
const result = R.pluck(property)(list)
|
|
9076
|
+
const result = R.pluck(property)(list)
|
|
8740
9077
|
// => [1, 2]
|
|
8741
9078
|
```
|
|
8742
9079
|
|
|
8743
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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)%
|
|
9080
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
8744
9081
|
|
|
8745
9082
|
<details>
|
|
8746
9083
|
|
|
@@ -8748,6 +9085,12 @@ const result = R.pluck(property)(list)
|
|
|
8748
9085
|
|
|
8749
9086
|
```typescript
|
|
8750
9087
|
pluck<T, K extends keyof T>(property: K): (list: T[]) => T[K][];
|
|
9088
|
+
pluck<K extends PropertyKey>(prop: K): {
|
|
9089
|
+
<U extends O[keyof O], UK extends keyof U, O extends Record<string, any>>(obj: K extends UK ? O : never): { [OK in keyof O]: O[OK][K] };
|
|
9090
|
+
<U extends readonly unknown[] | Record<K, any>>(list: readonly U[]): U extends readonly (infer T)[] ? T[] : U extends Record<K, infer T> ? T[] : never;
|
|
9091
|
+
};
|
|
9092
|
+
...
|
|
9093
|
+
...
|
|
8751
9094
|
```
|
|
8752
9095
|
|
|
8753
9096
|
</details>
|
|
@@ -8797,16 +9140,29 @@ test('with undefined', () => {
|
|
|
8797
9140
|
<summary><strong>TypeScript</strong> test</summary>
|
|
8798
9141
|
|
|
8799
9142
|
```typescript
|
|
8800
|
-
import { pipe, pluck } from
|
|
9143
|
+
import { pipe, pluck } from "rambda";
|
|
8801
9144
|
|
|
8802
|
-
it(
|
|
9145
|
+
it("R.pluck", () => {
|
|
8803
9146
|
const input = [
|
|
8804
|
-
{ a: 1, b:
|
|
8805
|
-
{ a: 2, b:
|
|
8806
|
-
]
|
|
8807
|
-
const result = pipe(input, pluck(
|
|
8808
|
-
result // $ExpectType string[]
|
|
8809
|
-
})
|
|
9147
|
+
{ a: 1, b: "foo" },
|
|
9148
|
+
{ a: 2, b: "bar" },
|
|
9149
|
+
];
|
|
9150
|
+
const result = pipe(input, pluck("b"));
|
|
9151
|
+
result; // $ExpectType string[]
|
|
9152
|
+
});
|
|
9153
|
+
|
|
9154
|
+
it("R.pluck without R.pipe", () => {
|
|
9155
|
+
interface Content {
|
|
9156
|
+
text: string;
|
|
9157
|
+
}
|
|
9158
|
+
const content: Content[] = [
|
|
9159
|
+
{
|
|
9160
|
+
text: "foo",
|
|
9161
|
+
},
|
|
9162
|
+
];
|
|
9163
|
+
const sentences = pluck("text")(content);
|
|
9164
|
+
sentences; // $ExpectType string[]
|
|
9165
|
+
});
|
|
8810
9166
|
```
|
|
8811
9167
|
|
|
8812
9168
|
</details>
|
|
@@ -8885,13 +9241,13 @@ If there is no such property, it returns `undefined`.
|
|
|
8885
9241
|
|
|
8886
9242
|
```javascript
|
|
8887
9243
|
const result = [
|
|
8888
|
-
R.prop('x')({x: 100}),
|
|
8889
|
-
R.prop('x')({a: 1})
|
|
9244
|
+
R.prop('x')({x: 100}),
|
|
9245
|
+
R.prop('x')({a: 1})
|
|
8890
9246
|
]
|
|
8891
9247
|
// => [100, undefined]
|
|
8892
9248
|
```
|
|
8893
9249
|
|
|
8894
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.prop('x')(%7Bx%3A%20100%7D)%2C%
|
|
9250
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
8895
9251
|
|
|
8896
9252
|
<details>
|
|
8897
9253
|
|
|
@@ -9034,7 +9390,7 @@ test('returns false if called with a null or undefined object', () => {
|
|
|
9034
9390
|
|
|
9035
9391
|
```typescript
|
|
9036
9392
|
|
|
9037
|
-
propOr<T, P extends string>(
|
|
9393
|
+
propOr<T, P extends string>(property: P, defaultValue: T): (obj: Partial<Record<P, T>>) => T
|
|
9038
9394
|
```
|
|
9039
9395
|
|
|
9040
9396
|
It returns either `defaultValue` or the value of `property` in `obj`.
|
|
@@ -9058,7 +9414,7 @@ const result = [
|
|
|
9058
9414
|
<summary>All TypeScript definitions</summary>
|
|
9059
9415
|
|
|
9060
9416
|
```typescript
|
|
9061
|
-
propOr<T, P extends string>(
|
|
9417
|
+
propOr<T, P extends string>(property: P, defaultValue: T): (obj: Partial<Record<P, T>>) => T;
|
|
9062
9418
|
```
|
|
9063
9419
|
|
|
9064
9420
|
</details>
|
|
@@ -9070,7 +9426,7 @@ propOr<T, P extends string>(defaultValue: T, property: P): (obj: Partial<Record<
|
|
|
9070
9426
|
```javascript
|
|
9071
9427
|
import { defaultTo } from './defaultTo.js'
|
|
9072
9428
|
|
|
9073
|
-
export function propOr(
|
|
9429
|
+
export function propOr(property, defaultValue) {
|
|
9074
9430
|
return obj => {
|
|
9075
9431
|
if (!obj) {
|
|
9076
9432
|
return defaultValue
|
|
@@ -9092,9 +9448,9 @@ import { propOr } from './propOr.js'
|
|
|
9092
9448
|
|
|
9093
9449
|
test('propOr', () => {
|
|
9094
9450
|
const obj = { a: 1 }
|
|
9095
|
-
expect(propOr('
|
|
9096
|
-
expect(propOr('
|
|
9097
|
-
expect(propOr('
|
|
9451
|
+
expect(propOr('a', 'default', )(obj)).toBe(1)
|
|
9452
|
+
expect(propOr('notExist', 'default')(obj)).toBe('default')
|
|
9453
|
+
expect(propOr('notExist', 'default')(null)).toBe('default')
|
|
9098
9454
|
})
|
|
9099
9455
|
```
|
|
9100
9456
|
|
|
@@ -9111,11 +9467,9 @@ const obj = { foo: 'bar' }
|
|
|
9111
9467
|
const property = 'foo'
|
|
9112
9468
|
const fallback = 'fallback'
|
|
9113
9469
|
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
result // $ExpectType string
|
|
9118
|
-
})
|
|
9470
|
+
it('R.propOr', () => {
|
|
9471
|
+
const result = propOr(property, fallback)(obj)
|
|
9472
|
+
result // $ExpectType string
|
|
9119
9473
|
})
|
|
9120
9474
|
```
|
|
9121
9475
|
|
|
@@ -9789,6 +10143,98 @@ describe('R.replace', () => {
|
|
|
9789
10143
|
|
|
9790
10144
|
[](#replace)
|
|
9791
10145
|
|
|
10146
|
+
### replaceAll
|
|
10147
|
+
|
|
10148
|
+
```typescript
|
|
10149
|
+
|
|
10150
|
+
replaceAll(patterns: (RegExp | string)[], replacer: string): (input: string) => string
|
|
10151
|
+
```
|
|
10152
|
+
|
|
10153
|
+
Same as `R.replace` but it accepts array of string and regular expressions instead of a single value.
|
|
10154
|
+
|
|
10155
|
+
```javascript
|
|
10156
|
+
const result = [
|
|
10157
|
+
R.replaceAll(['o', /a/g], '|1|')('foa'),
|
|
10158
|
+
]
|
|
10159
|
+
// => 'f|1||1|'
|
|
10160
|
+
```
|
|
10161
|
+
|
|
10162
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
10163
|
+
|
|
10164
|
+
<details>
|
|
10165
|
+
|
|
10166
|
+
<summary>All TypeScript definitions</summary>
|
|
10167
|
+
|
|
10168
|
+
```typescript
|
|
10169
|
+
replaceAll(patterns: (RegExp | string)[], replacer: string): (input: string) => string;
|
|
10170
|
+
```
|
|
10171
|
+
|
|
10172
|
+
</details>
|
|
10173
|
+
|
|
10174
|
+
<details>
|
|
10175
|
+
|
|
10176
|
+
<summary><strong>R.replaceAll</strong> source</summary>
|
|
10177
|
+
|
|
10178
|
+
```javascript
|
|
10179
|
+
export function replaceAll(patterns, replacer) {
|
|
10180
|
+
return input => {
|
|
10181
|
+
let text = input
|
|
10182
|
+
patterns.forEach(singlePattern => {
|
|
10183
|
+
text = text.replace(singlePattern, replacer)
|
|
10184
|
+
})
|
|
10185
|
+
|
|
10186
|
+
return text
|
|
10187
|
+
}
|
|
10188
|
+
}
|
|
10189
|
+
```
|
|
10190
|
+
|
|
10191
|
+
</details>
|
|
10192
|
+
|
|
10193
|
+
<details>
|
|
10194
|
+
|
|
10195
|
+
<summary><strong>Tests</strong></summary>
|
|
10196
|
+
|
|
10197
|
+
```javascript
|
|
10198
|
+
import { replaceAll } from './replaceAll.js'
|
|
10199
|
+
|
|
10200
|
+
const replacer = '|'
|
|
10201
|
+
const patterns = [/foo/g, 'bar']
|
|
10202
|
+
const input = 'foo bar baz foo bar'
|
|
10203
|
+
|
|
10204
|
+
test('happy', () => {
|
|
10205
|
+
const result = replaceAll(patterns, replacer)(input)
|
|
10206
|
+
const expected = '| | baz | bar'
|
|
10207
|
+
|
|
10208
|
+
expect(result).toEqual(expected)
|
|
10209
|
+
})
|
|
10210
|
+
```
|
|
10211
|
+
|
|
10212
|
+
</details>
|
|
10213
|
+
|
|
10214
|
+
<details>
|
|
10215
|
+
|
|
10216
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
10217
|
+
|
|
10218
|
+
```typescript
|
|
10219
|
+
import { pipe, replaceAll } from 'rambda'
|
|
10220
|
+
|
|
10221
|
+
const str = 'foo bar foo'
|
|
10222
|
+
const replacer = 'bar'
|
|
10223
|
+
const patterns = [/foo/g, 'bar']
|
|
10224
|
+
|
|
10225
|
+
describe('R.replaceAll', () => {
|
|
10226
|
+
it('happy', () => {
|
|
10227
|
+
const result = pipe(str, replaceAll(patterns, replacer))
|
|
10228
|
+
|
|
10229
|
+
result // $ExpectType string
|
|
10230
|
+
})
|
|
10231
|
+
})
|
|
10232
|
+
```
|
|
10233
|
+
|
|
10234
|
+
</details>
|
|
10235
|
+
|
|
10236
|
+
[](#replaceAll)
|
|
10237
|
+
|
|
9792
10238
|
### shuffle
|
|
9793
10239
|
|
|
9794
10240
|
```typescript
|
|
@@ -10100,6 +10546,25 @@ describe('R.sortBy', () => {
|
|
|
10100
10546
|
sortByDescending<T>(sortFn: (a: T, b: T) => number): (list: T[]) => T[]
|
|
10101
10547
|
```
|
|
10102
10548
|
|
|
10549
|
+
```javascript
|
|
10550
|
+
const list = [
|
|
10551
|
+
{a: 2},
|
|
10552
|
+
{a: 3},
|
|
10553
|
+
{a: 1}
|
|
10554
|
+
]
|
|
10555
|
+
const sortFn = x => x.a
|
|
10556
|
+
|
|
10557
|
+
const result = R.sortByDescending(sortFn)(list)
|
|
10558
|
+
const expected = [
|
|
10559
|
+
{a: 3},
|
|
10560
|
+
{a: 2},
|
|
10561
|
+
{a: 1}
|
|
10562
|
+
]
|
|
10563
|
+
// => `result` is equal to `expected`
|
|
10564
|
+
```
|
|
10565
|
+
|
|
10566
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
10567
|
+
|
|
10103
10568
|
<details>
|
|
10104
10569
|
|
|
10105
10570
|
<summary>All TypeScript definitions</summary>
|
|
@@ -10137,6 +10602,23 @@ sortByPath<S, K0 extends string & keyof S>(
|
|
|
10137
10602
|
|
|
10138
10603
|
It sorts `list` by the value of `path` property.
|
|
10139
10604
|
|
|
10605
|
+
```javascript
|
|
10606
|
+
const list = [
|
|
10607
|
+
{a: {b: 2}, id:1},
|
|
10608
|
+
{a: {b: 1}, id:2},
|
|
10609
|
+
{a: {b: 3}, id:3},
|
|
10610
|
+
]
|
|
10611
|
+
const result = R.sortByPath('a.b')(list)
|
|
10612
|
+
const expected = [
|
|
10613
|
+
{a: {b: 1}, id:2},
|
|
10614
|
+
{a: {b: 2}, id:1},
|
|
10615
|
+
{a: {b: 3}, id:3}
|
|
10616
|
+
]
|
|
10617
|
+
// => `result` is equal to `expected`
|
|
10618
|
+
```
|
|
10619
|
+
|
|
10620
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
10621
|
+
|
|
10140
10622
|
<details>
|
|
10141
10623
|
|
|
10142
10624
|
<summary>All TypeScript definitions</summary>
|
|
@@ -10241,6 +10723,23 @@ sortByPathDescending<S, K0 extends string & keyof S>(
|
|
|
10241
10723
|
): (list: S[]) => S[]
|
|
10242
10724
|
```
|
|
10243
10725
|
|
|
10726
|
+
```javascript
|
|
10727
|
+
const list = [
|
|
10728
|
+
{a: {b: 2}, id:1},
|
|
10729
|
+
{a: {b: 1}, id:2},
|
|
10730
|
+
{a: {b: 3}, id:3},
|
|
10731
|
+
]
|
|
10732
|
+
const result = R.sortByPathDescending('a.b')(list)
|
|
10733
|
+
const expected = [
|
|
10734
|
+
{a: {b: 3}, id:3}
|
|
10735
|
+
{a: {b: 2}, id:1},
|
|
10736
|
+
{a: {b: 1}, id:2},
|
|
10737
|
+
]
|
|
10738
|
+
// => `result` is equal to `expected`
|
|
10739
|
+
```
|
|
10740
|
+
|
|
10741
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
10742
|
+
|
|
10244
10743
|
<details>
|
|
10245
10744
|
|
|
10246
10745
|
<summary>All TypeScript definitions</summary>
|
|
@@ -10314,11 +10813,11 @@ It returns a sorted version of `input` object.
|
|
|
10314
10813
|
```javascript
|
|
10315
10814
|
const predicate = (propA, propB, valueA, valueB) => valueA > valueB ? -1 : 1
|
|
10316
10815
|
|
|
10317
|
-
const result = R.sortObject(predicate
|
|
10816
|
+
const result = R.sortObject(predicate)({a:1, b: 4, c: 2})
|
|
10318
10817
|
// => {b: 4, c: 2, a: 1}
|
|
10319
10818
|
```
|
|
10320
10819
|
|
|
10321
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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%
|
|
10820
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
10322
10821
|
|
|
10323
10822
|
<details>
|
|
10324
10823
|
|
|
@@ -10679,8 +11178,8 @@ It splits `input` into slices of `sliceLength`.
|
|
|
10679
11178
|
|
|
10680
11179
|
```javascript
|
|
10681
11180
|
const result = [
|
|
10682
|
-
R.splitEvery(2
|
|
10683
|
-
R.splitEvery(3
|
|
11181
|
+
R.splitEvery(2)([1, 2, 3]),
|
|
11182
|
+
R.splitEvery(3)('foobar')
|
|
10684
11183
|
]
|
|
10685
11184
|
|
|
10686
11185
|
const expected = [
|
|
@@ -10690,7 +11189,7 @@ const expected = [
|
|
|
10690
11189
|
// => `result` is equal to `expected`
|
|
10691
11190
|
```
|
|
10692
11191
|
|
|
10693
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.splitEvery(2%
|
|
11192
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
10694
11193
|
|
|
10695
11194
|
<details>
|
|
10696
11195
|
|
|
@@ -10777,11 +11276,11 @@ It returns a merged list of `x` and `y` with all equal elements removed.
|
|
|
10777
11276
|
const x = [ 1, 2, 3, 4 ]
|
|
10778
11277
|
const y = [ 3, 4, 5, 6 ]
|
|
10779
11278
|
|
|
10780
|
-
const result = R.symmetricDifference(x
|
|
11279
|
+
const result = R.symmetricDifference(x)(y)
|
|
10781
11280
|
// => [ 1, 2, 5, 6 ]
|
|
10782
11281
|
```
|
|
10783
11282
|
|
|
10784
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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
|
|
11283
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
10785
11284
|
|
|
10786
11285
|
<details>
|
|
10787
11286
|
|
|
@@ -10872,13 +11371,13 @@ It returns all but the first element of `input`.
|
|
|
10872
11371
|
|
|
10873
11372
|
```javascript
|
|
10874
11373
|
const result = [
|
|
10875
|
-
R.tail([1, 2, 3]),
|
|
10876
|
-
R.tail('foo')
|
|
11374
|
+
R.tail([1, 2, 3]),
|
|
11375
|
+
R.tail('foo')
|
|
10877
11376
|
]
|
|
10878
11377
|
// => [[2, 3], 'oo']
|
|
10879
11378
|
```
|
|
10880
11379
|
|
|
10881
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.tail(%5B1%2C%202%2C%203%5D)%2C%
|
|
11380
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
10882
11381
|
|
|
10883
11382
|
<details>
|
|
10884
11383
|
|
|
@@ -11341,23 +11840,23 @@ it('R.takeWhile', () => {
|
|
|
11341
11840
|
tap<T>(fn: (x: T) => void): (input: T) => T
|
|
11342
11841
|
```
|
|
11343
11842
|
|
|
11344
|
-
It applies function `fn` to input `x` and returns `x`.
|
|
11843
|
+
It applies function `fn` to input `x` and returns `x`.
|
|
11345
11844
|
|
|
11346
11845
|
One use case is debugging in the middle of `R.pipe` chain.
|
|
11347
11846
|
|
|
11348
11847
|
```javascript
|
|
11349
11848
|
const list = [1, 2, 3]
|
|
11350
11849
|
|
|
11351
|
-
R.pipe(
|
|
11850
|
+
const result = R.pipe(
|
|
11352
11851
|
list,
|
|
11353
|
-
R.
|
|
11852
|
+
R.filter(x => x > 1),
|
|
11354
11853
|
R.tap(console.log),
|
|
11355
|
-
R.
|
|
11854
|
+
R.map(x => x * 2)
|
|
11356
11855
|
)
|
|
11357
11856
|
// => `2` and `3` will be logged
|
|
11358
11857
|
```
|
|
11359
11858
|
|
|
11360
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20list%20%3D%20%5B1%2C%202%2C%203%5D%0A%
|
|
11859
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
11361
11860
|
|
|
11362
11861
|
<details>
|
|
11363
11862
|
|
|
@@ -11461,6 +11960,63 @@ it('R.test', () => {
|
|
|
11461
11960
|
|
|
11462
11961
|
[](#test)
|
|
11463
11962
|
|
|
11963
|
+
### transformPropObject
|
|
11964
|
+
|
|
11965
|
+
```typescript
|
|
11966
|
+
|
|
11967
|
+
transformPropObject<T extends object, K extends keyof T, Value>(
|
|
11968
|
+
valueMapper: (value: T[K]) => Value,
|
|
11969
|
+
prop: K,
|
|
11970
|
+
): (data: T) => MergeTypes<Omit<T, K> & { [P in K]: Value }>
|
|
11971
|
+
```
|
|
11972
|
+
|
|
11973
|
+
```javascript
|
|
11974
|
+
const fn = (x) => x > 2
|
|
11975
|
+
const obj = {a: 1, b: 2}
|
|
11976
|
+
|
|
11977
|
+
const result = R.transformPropObject(fn, 'a')(obj)
|
|
11978
|
+
// => {a: false, b: 2}
|
|
11979
|
+
```
|
|
11980
|
+
|
|
11981
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
11982
|
+
|
|
11983
|
+
<details>
|
|
11984
|
+
|
|
11985
|
+
<summary>All TypeScript definitions</summary>
|
|
11986
|
+
|
|
11987
|
+
```typescript
|
|
11988
|
+
transformPropObject<T extends object, K extends keyof T, Value>(
|
|
11989
|
+
valueMapper: (value: T[K]) => Value,
|
|
11990
|
+
prop: K,
|
|
11991
|
+
): (data: T) => MergeTypes<Omit<T, K> & { [P in K]: Value }>;
|
|
11992
|
+
```
|
|
11993
|
+
|
|
11994
|
+
</details>
|
|
11995
|
+
|
|
11996
|
+
<details>
|
|
11997
|
+
|
|
11998
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
11999
|
+
|
|
12000
|
+
```typescript
|
|
12001
|
+
import { transformPropObject, pipe } from 'rambda'
|
|
12002
|
+
|
|
12003
|
+
it('R.transformPropObject', () => {
|
|
12004
|
+
const result = pipe(
|
|
12005
|
+
{ a: 1, b: 'foo' },
|
|
12006
|
+
transformPropObject(x => {
|
|
12007
|
+
x // $ExpectType number
|
|
12008
|
+
return x > 2
|
|
12009
|
+
}, 'a'),
|
|
12010
|
+
)
|
|
12011
|
+
|
|
12012
|
+
result // $ExpectType { b: string; a: boolean; }
|
|
12013
|
+
})
|
|
12014
|
+
```
|
|
12015
|
+
|
|
12016
|
+
</details>
|
|
12017
|
+
|
|
12018
|
+
[](#transformPropObject)
|
|
12019
|
+
|
|
11464
12020
|
### tryCatch
|
|
11465
12021
|
|
|
11466
12022
|
```typescript
|
|
@@ -11855,16 +12411,16 @@ describe('R.type', () => {
|
|
|
11855
12411
|
union<T>(x: T[]): (y: T[]) => T[]
|
|
11856
12412
|
```
|
|
11857
12413
|
|
|
11858
|
-
It takes two lists and return a new list containing a merger of both list with removed duplicates.
|
|
12414
|
+
It takes two lists and return a new list containing a merger of both list with removed duplicates.
|
|
11859
12415
|
|
|
11860
12416
|
`R.equals` is used to compare for duplication.
|
|
11861
12417
|
|
|
11862
12418
|
```javascript
|
|
11863
|
-
const result = R.union([1,2,3]
|
|
12419
|
+
const result = R.union([1,2,3])([3,4,5]);
|
|
11864
12420
|
// => [1, 2, 3, 4, 5]
|
|
11865
12421
|
```
|
|
11866
12422
|
|
|
11867
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.union(%5B1%2C2%2C3%5D%
|
|
12423
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
11868
12424
|
|
|
11869
12425
|
<details>
|
|
11870
12426
|
|
|
@@ -12075,12 +12631,12 @@ It applies uniqueness to input list based on function that defines what to be us
|
|
|
12075
12631
|
|
|
12076
12632
|
```javascript
|
|
12077
12633
|
const list = [{a:1}, {a:2}, {a:1}]
|
|
12078
|
-
const result = R.uniqBy(x => x
|
|
12634
|
+
const result = R.uniqBy(x => x)(list)
|
|
12079
12635
|
|
|
12080
12636
|
// => [{a:1}, {a:2}]
|
|
12081
12637
|
```
|
|
12082
12638
|
|
|
12083
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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
|
|
12639
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
12084
12640
|
|
|
12085
12641
|
<details>
|
|
12086
12642
|
|
|
@@ -12557,11 +13113,11 @@ const index = 2
|
|
|
12557
13113
|
const newValue = 88
|
|
12558
13114
|
const list = [1, 2, 3, 4, 5]
|
|
12559
13115
|
|
|
12560
|
-
const result = R.update(index, newValue
|
|
13116
|
+
const result = R.update(index, newValue)(list)
|
|
12561
13117
|
// => [1, 2, 88, 4, 5]
|
|
12562
13118
|
```
|
|
12563
13119
|
|
|
12564
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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
|
|
13120
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
12565
13121
|
|
|
12566
13122
|
<details>
|
|
12567
13123
|
|
|
@@ -12640,31 +13196,29 @@ test('with negative index', () => {
|
|
|
12640
13196
|
when<T, U extends T>(predicate: (x: T) => x is U, whenTrueFn: (x: U) => T): (input: T) => T
|
|
12641
13197
|
```
|
|
12642
13198
|
|
|
12643
|
-
It pass `input` to `predicate` function and if the result is `true`, it will return the result of `whenTrueFn(input)`.
|
|
13199
|
+
It pass `input` to `predicate` function and if the result is `true`, it will return the result of `whenTrueFn(input)`.
|
|
12644
13200
|
If the `predicate` returns `false`, then it will simply return `input`.
|
|
12645
13201
|
|
|
12646
13202
|
```javascript
|
|
12647
13203
|
const predicate = x => typeof x === 'number'
|
|
12648
|
-
const
|
|
12649
|
-
|
|
12650
|
-
const fn = when(predicate, whenTrueResult)
|
|
13204
|
+
const fn = R.when(predicate)(x => x + 1)
|
|
12651
13205
|
|
|
12652
13206
|
const positiveInput = 88
|
|
12653
13207
|
const negativeInput = 'foo'
|
|
12654
13208
|
|
|
12655
13209
|
const result = [
|
|
12656
13210
|
fn(positiveInput),
|
|
12657
|
-
fn(
|
|
13211
|
+
fn(negativeInput),
|
|
12658
13212
|
]
|
|
12659
13213
|
|
|
12660
13214
|
const expected = [
|
|
12661
|
-
|
|
12662
|
-
'
|
|
13215
|
+
89,
|
|
13216
|
+
'foo1',
|
|
12663
13217
|
]
|
|
12664
13218
|
// => `result` is equal to `expected`
|
|
12665
13219
|
```
|
|
12666
13220
|
|
|
12667
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20predicate%20%3D%20x%20%3D%3E%20typeof%20x%20%3D%3D%3D%20'number'%0Aconst%
|
|
13221
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
12668
13222
|
|
|
12669
13223
|
<details>
|
|
12670
13224
|
|
|
@@ -12767,7 +13321,7 @@ describe('R.when', () => {
|
|
|
12767
13321
|
zip<K>(x: K[]): <V>(y: V[]) => KeyValuePair<K, V>[]
|
|
12768
13322
|
```
|
|
12769
13323
|
|
|
12770
|
-
It will return a new array containing tuples of equally positions items from both `x` and `y` lists.
|
|
13324
|
+
It will return a new array containing tuples of equally positions items from both `x` and `y` lists.
|
|
12771
13325
|
|
|
12772
13326
|
The returned list will be truncated to match the length of the shortest supplied list.
|
|
12773
13327
|
|
|
@@ -12896,11 +13450,11 @@ zipWith<T, U, TResult>(
|
|
|
12896
13450
|
const list1 = [ 10, 20, 30, 40 ]
|
|
12897
13451
|
const list2 = [ 100, 200 ]
|
|
12898
13452
|
|
|
12899
|
-
const result = R.zipWith(
|
|
13453
|
+
const result = R.zipWith((x, y) => x + y, list1)(list2)
|
|
12900
13454
|
// => [110, 220]
|
|
12901
13455
|
```
|
|
12902
13456
|
|
|
12903
|
-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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(
|
|
13457
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?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>
|
|
12904
13458
|
|
|
12905
13459
|
<details>
|
|
12906
13460
|
|
|
@@ -12989,6 +13543,39 @@ describe('R.zipWith', () => {
|
|
|
12989
13543
|
|
|
12990
13544
|
## ❯ CHANGELOG
|
|
12991
13545
|
|
|
13546
|
+
10.3.1
|
|
13547
|
+
|
|
13548
|
+
- Fix issue with wrong order of inputs in `R.propOr` - [Issue #779](https://github.com/selfrefactor/rambda/issues/779)
|
|
13549
|
+
|
|
13550
|
+
- Fix issue with TypeScript definitions for `R.includes`- [Issue #781](https://github.com/selfrefactor/rambda/issues/781)
|
|
13551
|
+
|
|
13552
|
+
10.3.0
|
|
13553
|
+
|
|
13554
|
+
- Add `R.mapPropObject`
|
|
13555
|
+
|
|
13556
|
+
- Add `R.duplicateBy`
|
|
13557
|
+
- Add `R.duplicateBy`
|
|
13558
|
+
|
|
13559
|
+
- Add `R.filterAsync`
|
|
13560
|
+
- Add `R.filterAsync`
|
|
13561
|
+
|
|
13562
|
+
- Add `R.indexBy`
|
|
13563
|
+
- Add `R.indexBy`
|
|
13564
|
+
|
|
13565
|
+
- Restore `R.replaceAll`
|
|
13566
|
+
- Restore `R.replaceAll`
|
|
13567
|
+
|
|
13568
|
+
- Remove option for `R.mapAsync` to be called outside of `R.pipeAsync`. This is done for consistency as all other methods follow this rule, i.e. they are all curried.
|
|
13569
|
+
|
|
13570
|
+
- Fix `R.pluck` to work without `R.pipe`
|
|
13571
|
+
- Remove option for `R.mapAsync` to be called outside of `R.pipeAsync`. This is done for consistency as all other methods follow this rule, i.e. they are all curried.
|
|
13572
|
+
|
|
13573
|
+
- Fix `R.pluck` to work without `R.pipe`
|
|
13574
|
+
|
|
13575
|
+
10.2.0
|
|
13576
|
+
|
|
13577
|
+
Add `R.modifyPath`
|
|
13578
|
+
|
|
12992
13579
|
10.1.0
|
|
12993
13580
|
|
|
12994
13581
|
- Add `R.assertType` and `R.convertToType` methods
|
|
@@ -13013,7 +13600,7 @@ This is major revamp of `Rambda` library:
|
|
|
13013
13600
|
|
|
13014
13601
|
- Confusing methods are removed. For example, `R.cond` and `R.ifElse` are removed as their usage inside `R.piped` makes the whole chain less readable. Such logic should be part of your codebase, not part of external library.
|
|
13015
13602
|
|
|
13016
|
-
- All methods that expect more than 1 input, will have to be called with `R.methodName(input1)(input2)` or `R.methodName(input1, input2)(input3)`. This is to make TypeScript definitions easier to maintain.
|
|
13603
|
+
- All methods that expect more than 1 input, will have to be called with `R.methodName(input1)(input2)` or `R.methodName(input1, input2)(input3)`. This is to make TypeScript definitions easier to maintain.
|
|
13017
13604
|
|
|
13018
13605
|
- Optimize many methods to better work in TypeScript context with `R.pipe`. The focus was passing objects through the `R.pipe` chain.
|
|
13019
13606
|
|
|
@@ -13025,83 +13612,149 @@ This is major revamp of `Rambda` library:
|
|
|
13025
13612
|
- Remove following methods:
|
|
13026
13613
|
|
|
13027
13614
|
-- Lenses - `R.lens`, `R.lensProp`, `R.lensPath`, `R.view`, `R.set`, `R.over`
|
|
13615
|
+
|
|
13028
13616
|
-- T, F
|
|
13617
|
+
|
|
13029
13618
|
-- add
|
|
13619
|
+
|
|
13030
13620
|
-- addIndex, addIndexRight
|
|
13621
|
+
|
|
13031
13622
|
-- always
|
|
13623
|
+
|
|
13032
13624
|
-- ap
|
|
13625
|
+
|
|
13033
13626
|
-- applySpec
|
|
13627
|
+
|
|
13034
13628
|
-- applyTo
|
|
13629
|
+
|
|
13035
13630
|
-- assoc, assocPath, dissoc, dissocPath
|
|
13631
|
+
|
|
13036
13632
|
-- binary
|
|
13633
|
+
|
|
13037
13634
|
-- bind
|
|
13635
|
+
|
|
13038
13636
|
-- call
|
|
13637
|
+
|
|
13039
13638
|
-- collectBy
|
|
13639
|
+
|
|
13040
13640
|
-- compose
|
|
13641
|
+
|
|
13041
13642
|
-- composeWith
|
|
13643
|
+
|
|
13042
13644
|
-- cond
|
|
13645
|
+
|
|
13043
13646
|
-- converge
|
|
13647
|
+
|
|
13044
13648
|
-- curry
|
|
13649
|
+
|
|
13045
13650
|
-- difference, differenceWith
|
|
13651
|
+
|
|
13046
13652
|
-- divide, multiply, subtract
|
|
13653
|
+
|
|
13047
13654
|
-- endsWith/startsWith
|
|
13655
|
+
|
|
13048
13656
|
-- flip
|
|
13657
|
+
|
|
13049
13658
|
-- forEachObjIndexed
|
|
13659
|
+
|
|
13050
13660
|
-- fromPairs
|
|
13661
|
+
|
|
13051
13662
|
-- gte, lte, lt, gt
|
|
13663
|
+
|
|
13052
13664
|
-- identical
|
|
13665
|
+
|
|
13053
13666
|
-- ifElse
|
|
13667
|
+
|
|
13054
13668
|
-- insert
|
|
13669
|
+
|
|
13055
13670
|
-- juxt
|
|
13671
|
+
|
|
13056
13672
|
-- length
|
|
13673
|
+
|
|
13057
13674
|
-- mapObjIndexed
|
|
13675
|
+
|
|
13058
13676
|
-- mergeAll, mergeLeft, mergeDeepLeft, mergeDeepRight
|
|
13677
|
+
|
|
13059
13678
|
-- move
|
|
13679
|
+
|
|
13060
13680
|
-- partitionIndexed
|
|
13681
|
+
|
|
13061
13682
|
-- pickAll
|
|
13683
|
+
|
|
13062
13684
|
-- pickBy
|
|
13685
|
+
|
|
13063
13686
|
-- repeat
|
|
13687
|
+
|
|
13064
13688
|
-- splitWhen
|
|
13689
|
+
|
|
13065
13690
|
-- toLower/toUpper
|
|
13691
|
+
|
|
13066
13692
|
-- unapply
|
|
13693
|
+
|
|
13067
13694
|
-- unnest
|
|
13695
|
+
|
|
13068
13696
|
-- update
|
|
13697
|
+
|
|
13069
13698
|
-- without
|
|
13070
13699
|
|
|
13071
13700
|
- Add following methods:
|
|
13072
13701
|
|
|
13073
13702
|
-- R.pipeAsync
|
|
13703
|
+
|
|
13074
13704
|
-- R.addProp
|
|
13705
|
+
|
|
13075
13706
|
-- R.createObjectFromKeys
|
|
13707
|
+
|
|
13076
13708
|
-- R.mapAsync
|
|
13709
|
+
|
|
13077
13710
|
-- R.mapParallelAsync
|
|
13711
|
+
|
|
13078
13712
|
-- R.ascend/R.descend
|
|
13713
|
+
|
|
13079
13714
|
-- R.shuffle
|
|
13715
|
+
|
|
13080
13716
|
-- R.permutations
|
|
13717
|
+
|
|
13081
13718
|
-- R.compact
|
|
13719
|
+
|
|
13082
13720
|
-- R.rejectObject
|
|
13721
|
+
|
|
13083
13722
|
-- R.findNth
|
|
13723
|
+
|
|
13084
13724
|
-- R.combinations
|
|
13725
|
+
|
|
13085
13726
|
-- R.sortByPath
|
|
13727
|
+
|
|
13086
13728
|
-- R.sortByPathDescending
|
|
13729
|
+
|
|
13087
13730
|
-- R.sortByDescending
|
|
13731
|
+
|
|
13088
13732
|
-- R.flattenObject
|
|
13733
|
+
|
|
13089
13734
|
-- R.addPropToObjects
|
|
13090
13735
|
|
|
13091
13736
|
- Rename following methods:
|
|
13092
13737
|
|
|
13093
13738
|
-- modifyItemAtIndex -> adjust
|
|
13094
|
-
|
|
13739
|
+
|
|
13740
|
+
-- checkObjectWithSpec -> where
|
|
13741
|
+
|
|
13095
13742
|
-- objectIncludes -> whereEq
|
|
13743
|
+
|
|
13096
13744
|
-- modify -> modifyProp
|
|
13745
|
+
|
|
13097
13746
|
-- chain -> flatMap
|
|
13747
|
+
|
|
13098
13748
|
-- mapObjIndexed -> mapObject
|
|
13099
13749
|
|
|
13100
13750
|
_ Regarding using object as input with TypeScript in methods such as `R.map/filter` - this feature is no longer supported in TypeScript as it has multiple issues when using inside pipes. In JS, it still works as before. Following methods are affected:
|
|
13101
13751
|
|
|
13102
13752
|
-- R.map
|
|
13753
|
+
|
|
13103
13754
|
-- R.mapIndexed
|
|
13755
|
+
|
|
13104
13756
|
-- R.filter
|
|
13757
|
+
|
|
13105
13758
|
-- R.reject
|
|
13106
13759
|
|
|
13107
13760
|
- Regarding using string as path input in `R.omit`, `R.pick` and `R.path` with TypeScript - now it require explicit definition of expected return type.
|
|
@@ -13130,36 +13783,63 @@ _ Regarding using object as input with TypeScript in methods such as `R.map/filt
|
|
|
13130
13783
|
- Sync with typing of `@types/ramda`:
|
|
13131
13784
|
|
|
13132
13785
|
-- allPass
|
|
13786
|
+
|
|
13133
13787
|
-- anyPass
|
|
13788
|
+
|
|
13134
13789
|
-- append
|
|
13790
|
+
|
|
13135
13791
|
-- both
|
|
13792
|
+
|
|
13136
13793
|
-- countBy
|
|
13794
|
+
|
|
13137
13795
|
-- drop
|
|
13796
|
+
|
|
13138
13797
|
-- dropLast
|
|
13798
|
+
|
|
13139
13799
|
-- dropRepeatsBy
|
|
13800
|
+
|
|
13140
13801
|
-- either
|
|
13802
|
+
|
|
13141
13803
|
-- filter
|
|
13804
|
+
|
|
13142
13805
|
-- forEach
|
|
13806
|
+
|
|
13143
13807
|
-- keys
|
|
13808
|
+
|
|
13144
13809
|
-- map
|
|
13810
|
+
|
|
13145
13811
|
-- mergeAll
|
|
13812
|
+
|
|
13146
13813
|
-- modify
|
|
13814
|
+
|
|
13147
13815
|
-- modifyPath
|
|
13816
|
+
|
|
13148
13817
|
-- omit
|
|
13818
|
+
|
|
13149
13819
|
-- partition
|
|
13820
|
+
|
|
13150
13821
|
-- pluck
|
|
13822
|
+
|
|
13151
13823
|
-- prepend
|
|
13824
|
+
|
|
13152
13825
|
-- propEq
|
|
13826
|
+
|
|
13153
13827
|
-- where
|
|
13828
|
+
|
|
13154
13829
|
-- whereAny
|
|
13155
13830
|
|
|
13156
13831
|
- Sync with typing of `remeda`:
|
|
13157
13832
|
|
|
13158
13833
|
-- filter
|
|
13834
|
+
|
|
13159
13835
|
-- reject
|
|
13836
|
+
|
|
13160
13837
|
-- map
|
|
13838
|
+
|
|
13161
13839
|
-- mapObject
|
|
13840
|
+
|
|
13162
13841
|
-- toPairs
|
|
13842
|
+
|
|
13163
13843
|
-- partition
|
|
13164
13844
|
|
|
13165
13845
|
- Publish to JSR registry - https://jsr.io/@rambda/rambda
|
|
@@ -13169,7 +13849,9 @@ _ Regarding using object as input with TypeScript in methods such as `R.map/filt
|
|
|
13169
13849
|
- Improve TypeScript definitions of:
|
|
13170
13850
|
|
|
13171
13851
|
-- objOf
|
|
13852
|
+
|
|
13172
13853
|
-- pluck
|
|
13854
|
+
|
|
13173
13855
|
-- mergeWith
|
|
13174
13856
|
|
|
13175
13857
|
- Change `Jest` with `Vitest`.
|
|
@@ -13215,7 +13897,7 @@ const result = piped(
|
|
|
13215
13897
|
|
|
13216
13898
|
- Add `R.isNotEmpty` as it is new method in `Ramda`
|
|
13217
13899
|
|
|
13218
|
-
- Fix `R.head`/`R.last` TS definition - It returns `undefined` if array has length of 0. Before
|
|
13900
|
+
- Fix `R.head`/`R.last` TS definition - It returns `undefined` if array has length of 0. Before
|
|
13219
13901
|
|
|
13220
13902
|
9.2.1
|
|
13221
13903
|
|
|
@@ -13225,7 +13907,7 @@ const result = piped(
|
|
|
13225
13907
|
|
|
13226
13908
|
- `R.once` TS type definition miss to context argument and its type - [Issue #728](https://github.com/selfrefactor/rambda/issues/728)
|
|
13227
13909
|
|
|
13228
|
-
- Fix implementation of `R.unless` function - https://github.com/selfrefactor/rambda/pull/726
|
|
13910
|
+
- Fix implementation of `R.unless` function - https://github.com/selfrefactor/rambda/pull/726
|
|
13229
13911
|
|
|
13230
13912
|
9.1.1
|
|
13231
13913
|
|
|
@@ -13301,7 +13983,7 @@ Breaking change in TS definitions of `lenses` as now they are synced to `Ramda`
|
|
|
13301
13983
|
|
|
13302
13984
|
- Fix cannot compare errors in `Deno` with `R.equals` - [Issue #704](https://github.com/selfrefactor/rambda/issues/704).
|
|
13303
13985
|
|
|
13304
|
-
- Fix cannot compare `BigInt` with `R.equals`
|
|
13986
|
+
- Fix cannot compare `BigInt` with `R.equals`
|
|
13305
13987
|
|
|
13306
13988
|
8.3.0
|
|
13307
13989
|
|
|
@@ -13351,258 +14033,6 @@ Add the following methods:
|
|
|
13351
14033
|
|
|
13352
14034
|
- change order of `R.propEq` - [Ramda MR](https://github.com/ramda/ramda/pull/2938/files)
|
|
13353
14035
|
|
|
13354
|
-
7.5.0
|
|
13355
|
-
|
|
13356
|
-
- IMPORTANT: Remove `export` property in `package.json` in order to allow `Rambda` support for projects with `"type": "module"` in `package.json` - [Issue #667](https://github.com/selfrefactor/rambda/issues/657)
|
|
13357
|
-
|
|
13358
|
-
- Add `R.unnest` - [Rambdax issue 89](https://github.com/selfrefactor/rambdax/issues/89)
|
|
13359
|
-
|
|
13360
|
-
- `R.uniq` is not using `R.equals` as Ramda does - [Issue #88](https://github.com/selfrefactor/rambdax/issues/88)
|
|
13361
|
-
|
|
13362
|
-
- Fix `R.path(['non','existing','path'], obj)` TS definition as 7.4.0 release caused TS errors - [Issue #668](https://github.com/selfrefactor/rambda/issues/668)
|
|
13363
|
-
|
|
13364
|
-
7.4.0
|
|
13365
|
-
|
|
13366
|
-
- Synchronize with `@types/ramda` - `R.prop`, `R.path`, `R.pickAll`
|
|
13367
|
-
|
|
13368
|
-
- Remove `esm` Rollup output due to tree-shaking issues.
|
|
13369
|
-
|
|
13370
|
-
- Upgrade all dev dependencies.
|
|
13371
|
-
|
|
13372
|
-
7.3.0
|
|
13373
|
-
|
|
13374
|
-
- Important - changing import declaration in `package.json` in order to fix tree-shaking issue - [Issue #647](https://github.com/selfrefactor/rambda/issues/647)
|
|
13375
|
-
|
|
13376
|
-
- Add `R.modify`
|
|
13377
|
-
|
|
13378
|
-
- Allow multiple inputs in TypeScript versions of `R.anyPass` and `R.allPass` - [Issue #642](https://github.com/selfrefactor/rambda/issues/604)
|
|
13379
|
-
|
|
13380
|
-
- Using wrong clone of object in `R.mergeDeepRight` - [Issue #650](https://github.com/selfrefactor/rambda/issues/650)
|
|
13381
|
-
|
|
13382
|
-
- Missing early return in `R.where` - [Issue #648](https://github.com/selfrefactor/rambda/issues/648)
|
|
13383
|
-
|
|
13384
|
-
- `R.allPass` doesn't accept more than 1 parameters for function predicates- [Issue #604](https://github.com/selfrefactor/rambda/issues/604)
|
|
13385
|
-
|
|
13386
|
-
7.2.1
|
|
13387
|
-
|
|
13388
|
-
- Remove bad typings of `R.propIs` which caused the library to cannot be build with TypeScript.
|
|
13389
|
-
|
|
13390
|
-
- Drop support for `Wallaby` as per [https://github.com/wallabyjs/public/issues/3037](https://github.com/wallabyjs/public/issues/3037)
|
|
13391
|
-
|
|
13392
|
-
7.2.0
|
|
13393
|
-
|
|
13394
|
-
- Wrong `R.update` if index is `-1` - [PR #593](https://github.com/selfrefactor/rambda/pull/593)
|
|
13395
|
-
|
|
13396
|
-
- Wrong curried typings in `R.anyPass` - [Issue #642](https://github.com/selfrefactor/rambda/issues/642)
|
|
13397
|
-
|
|
13398
|
-
- `R.modifyPath` not exported - [Issue #640](https://github.com/selfrefactor/rambda/issues/640)
|
|
13399
|
-
|
|
13400
|
-
- Add new method `R.uniqBy`. Implementation is coming from [Ramda MR#2641](https://github.com/ramda/ramda/pull/2641)
|
|
13401
|
-
|
|
13402
|
-
- Apply the following changes from `@types/rambda`:
|
|
13403
|
-
|
|
13404
|
-
-- [https://github.com/DefinitelyTyped/DefinitelyTyped/commit/bab47272d52fc7bb81e85da36dbe9c905a04d067](add `AnyFunction` and `AnyConstructor`)
|
|
13405
|
-
|
|
13406
|
-
-- Improve `R.ifElse` typings - https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59291
|
|
13407
|
-
|
|
13408
|
-
-- Make `R.propEq` safe for `null/undefined` arguments - https://github.com/ramda/ramda/pull/2594/files
|
|
13409
|
-
|
|
13410
|
-
7.1.4
|
|
13411
|
-
|
|
13412
|
-
- `R.mergeRight` not found on `Deno` import - [Issue #633](https://github.com/selfrefactor/rambda/issues/633)
|
|
13413
|
-
|
|
13414
|
-
7.1.0
|
|
13415
|
-
|
|
13416
|
-
- Add `R.mergeRight` - introduced by Ramda's latest release. While Ramda renames `R.merge`, Rambda will keep `R.merge`.
|
|
13417
|
-
|
|
13418
|
-
- Rambda's `pipe/compose` doesn't return proper length of composed function which leads to issue with `R.applySpec`. It was fixed by using Ramda's `pipe/compose` logic - [Issue #627](https://github.com/selfrefactor/rambda/issues/627)
|
|
13419
|
-
|
|
13420
|
-
- Replace `Async` with `Promise` as return type of `R.type`.
|
|
13421
|
-
|
|
13422
|
-
- Add new types as TypeScript output for `R.type` - "Map", "WeakMap", "Generator", "GeneratorFunction", "BigInt", "ArrayBuffer"
|
|
13423
|
-
|
|
13424
|
-
- Add `R.juxt` method
|
|
13425
|
-
|
|
13426
|
-
- Add `R.propSatisfies` method
|
|
13427
|
-
|
|
13428
|
-
- Add new methods after `Ramda` version upgrade to `0.28.0`:
|
|
13429
|
-
|
|
13430
|
-
-- R.count
|
|
13431
|
-
-- R.modifyPath
|
|
13432
|
-
-- R.on
|
|
13433
|
-
-- R.whereAny
|
|
13434
|
-
-- R.partialObject
|
|
13435
|
-
|
|
13436
|
-
7.0.3
|
|
13437
|
-
|
|
13438
|
-
Rambda.none has wrong logic introduced in version `7.0.0` - [Issue #625](https://github.com/selfrefactor/rambda/issues/625)
|
|
13439
|
-
|
|
13440
|
-
7.0.2
|
|
13441
|
-
|
|
13442
|
-
Rambda doesn't work with `pnpm` due to wrong export configuration - [Issue #619](https://github.com/selfrefactor/rambda/issues/619)
|
|
13443
|
-
|
|
13444
|
-
7.0.1
|
|
13445
|
-
|
|
13446
|
-
- Wrong ESM export configuration in `package.json` - [Issue #614](https://github.com/selfrefactor/rambda/issues/614)
|
|
13447
|
-
|
|
13448
|
-
7.0.0
|
|
13449
|
-
|
|
13450
|
-
- Breaking change - sync `R.compose`/`R.pipe` with `@types/ramda`. That is significant change so as safeguard, it will lead a major bump. Important - this lead to raising required TypeScript version to `4.2.2`. In other words, to use `Rambda` you'll need TypeScript version `4.2.2` or newer.
|
|
13451
|
-
|
|
13452
|
-
Related commit in `@types/ramda` - https://github.com/DefinitelyTyped/DefinitelyTyped/commit/286eff4f76d41eb8f091e7437eabd8a60d97fc1f#diff-4f74803fa83a81e47cb17a7d8a4e46a7e451f4d9e5ce2f1bd7a70a72d91f4bc1
|
|
13453
|
-
|
|
13454
|
-
There are several other changes in `@types/ramda` as stated in [this comment](https://github.com/ramda/ramda/issues/2976#issuecomment-990408945). This leads to change of typings for the following methods in **Rambda**:
|
|
13455
|
-
|
|
13456
|
-
-- R.unless
|
|
13457
|
-
|
|
13458
|
-
-- R.toString
|
|
13459
|
-
|
|
13460
|
-
-- R.ifElse
|
|
13461
|
-
|
|
13462
|
-
-- R.always
|
|
13463
|
-
|
|
13464
|
-
-- R.complement
|
|
13465
|
-
|
|
13466
|
-
-- R.cond
|
|
13467
|
-
|
|
13468
|
-
-- R.is
|
|
13469
|
-
|
|
13470
|
-
-- R.sortBy
|
|
13471
|
-
|
|
13472
|
-
-- R.dissoc
|
|
13473
|
-
|
|
13474
|
-
-- R.toPairs
|
|
13475
|
-
|
|
13476
|
-
-- R.assoc
|
|
13477
|
-
|
|
13478
|
-
-- R.toLower
|
|
13479
|
-
|
|
13480
|
-
-- R.toUpper
|
|
13481
|
-
|
|
13482
|
-
- One more reason for the breaking change is changing of export declarations in `package.json` based on [this blog post](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#packagejson-exports-imports-and-self-referencing) and [this merged Ramda's PR](https://github.com/ramda/ramda/pull/2999). This also led to renaming of `babel.config.js` to `babel.config.cjs`.
|
|
13483
|
-
|
|
13484
|
-
- Add `R.apply`, `R.bind` and `R.unapply`
|
|
13485
|
-
|
|
13486
|
-
- `R.startsWith/R.endsWith` now support lists as inputs. This way, it matches current Ramda behavior.
|
|
13487
|
-
|
|
13488
|
-
- Remove unused typing for `R.chain`.
|
|
13489
|
-
|
|
13490
|
-
- `R.map`/`R.filter` no longer accept bad inputs as iterable. This way, Rambda behaves more like Ramda, which also throws.
|
|
13491
|
-
|
|
13492
|
-
- Make `R.lastIndexOf` follow the logic of `R.indexOf`.
|
|
13493
|
-
|
|
13494
|
-
- Change `R.type` logic to Ramda logic. This way, `R.type` can return `Error` and `Set` as results.
|
|
13495
|
-
|
|
13496
|
-
- Add missing logic in `R.equals` to compare sets - [Issue #599](https://github.com/selfrefactor/rambda/issues/599)
|
|
13497
|
-
|
|
13498
|
-
- Improve list cloning - [Issue #595](https://github.com/selfrefactor/rambda/issues/595)
|
|
13499
|
-
|
|
13500
|
-
- Handle multiple inputs with `R.allPass` and `R.anyPass` - [Issue #604](https://github.com/selfrefactor/rambda/issues/604)
|
|
13501
|
-
|
|
13502
|
-
- Fix `R.length` wrong logic with inputs as `{length: 123}` - [Issue #606](https://github.com/selfrefactor/rambda/issues/606).
|
|
13503
|
-
|
|
13504
|
-
- Improve non-curry typings of `R.merge` by using types from [mobily/ts-belt](https://github.com/mobily/ts-belt).
|
|
13505
|
-
|
|
13506
|
-
- Improve performance of `R.uniqWith`.
|
|
13507
|
-
|
|
13508
|
-
- Wrong `R.update` if index is `-1` - [PR #593](https://github.com/selfrefactor/rambda/pull/593)
|
|
13509
|
-
|
|
13510
|
-
- Make `R.eqProps` safe for falsy inputs - based on [this opened Ramda PR](https://github.com/ramda/ramda/pull/2943).
|
|
13511
|
-
|
|
13512
|
-
- Incorrect benchmarks for `R.pipe/R.compose` - [Issue #608](https://github.com/selfrefactor/rambda/issues/608)
|
|
13513
|
-
|
|
13514
|
-
- Fix `R.last/R.head` typings - [Issue #609](https://github.com/selfrefactor/rambda/issues/609)
|
|
13515
|
-
|
|
13516
|
-
6.9.0
|
|
13517
|
-
|
|
13518
|
-
- Fix slow `R.uniq` methods - [Issue #581](https://github.com/selfrefactor/rambda/issues/581)
|
|
13519
|
-
|
|
13520
|
-
Fixing `R.uniq` was done by improving `R.indexOf` which has performance implication to all methods importing `R.indexOf`:
|
|
13521
|
-
|
|
13522
|
-
- R.includes
|
|
13523
|
-
- R.intersection
|
|
13524
|
-
- R.difference
|
|
13525
|
-
- R.excludes
|
|
13526
|
-
- R.symmetricDifference
|
|
13527
|
-
- R.union
|
|
13528
|
-
|
|
13529
|
-
- R.without no longer support the following case - `without('0:1', ['0', '0:1']) // => ['0']`. Now it throws as the first argument should be a list, not a string. Ramda, on the other hand, returns an empty list - https://github.com/ramda/ramda/issues/3086.
|
|
13530
|
-
|
|
13531
|
-
6.8.3
|
|
13532
|
-
|
|
13533
|
-
- Fix TypeScript build process with `rambda/immutable` - [Issue #572](https://github.com/selfrefactor/rambda/issues/572)
|
|
13534
|
-
|
|
13535
|
-
- Add `R.objOf` method
|
|
13536
|
-
|
|
13537
|
-
- Add `R.mapObjIndexed` method
|
|
13538
|
-
|
|
13539
|
-
- Publish shorter README.md version to NPM
|
|
13540
|
-
|
|
13541
|
-
6.8.0
|
|
13542
|
-
|
|
13543
|
-
- `R.has` use `Object.prototype.hasOwnProperty`- [Issue #572](https://github.com/selfrefactor/rambda/issues/572)
|
|
13544
|
-
|
|
13545
|
-
- Expose `immutable.ts` typings which are Rambda typings with `readonly` statements - [Issue #565](https://github.com/selfrefactor/rambda/issues/565)
|
|
13546
|
-
|
|
13547
|
-
- Fix `R.intersection` wrong order compared to Ramda.
|
|
13548
|
-
|
|
13549
|
-
- `R.path` wrong return of `null` instead of `undefined` when path value is `null` - [PR #577](https://github.com/selfrefactor/rambda/pull/577)
|
|
13550
|
-
|
|
13551
|
-
6.7.0
|
|
13552
|
-
|
|
13553
|
-
- Remove `ts-toolbelt` types from TypeScript definitions. Most affected are the following methods, which lose one of its curried definitions:
|
|
13554
|
-
|
|
13555
|
-
1. R.maxBy
|
|
13556
|
-
2. R.minBy
|
|
13557
|
-
3. R.pathEq
|
|
13558
|
-
4. R.viewOr
|
|
13559
|
-
5. R.when
|
|
13560
|
-
6. R.merge
|
|
13561
|
-
7. R.mergeDeepRight
|
|
13562
|
-
8. R.mergeLeft
|
|
13563
|
-
|
|
13564
|
-
6.6.0
|
|
13565
|
-
|
|
13566
|
-
- Change `R.piped` typings to mimic that of `R.pipe`. Main difference is that `R.pipe` is focused on unary functions.
|
|
13567
|
-
|
|
13568
|
-
- Fix wrong logic when `R.without` use `R.includes` while it should use array version of `R.includes`.
|
|
13569
|
-
|
|
13570
|
-
- Use uglify plugin for UMD bundle.
|
|
13571
|
-
|
|
13572
|
-
- Remove `dist` folder from `.gitignore` in order to fix `Deno` broken package. [Issue #570](https://github.com/selfrefactor/rambda/issues/570)
|
|
13573
|
-
|
|
13574
|
-
- Improve `R.fromPairs` typings - [Issue #567](https://github.com/selfrefactor/rambda/issues/567)
|
|
13575
|
-
|
|
13576
|
-
6.5.3
|
|
13577
|
-
|
|
13578
|
-
- Wrong logic where `R.without` use `R.includes` while it should use the array version of `R.includes`
|
|
13579
|
-
|
|
13580
|
-
This is Ramda bug, that Rambda also has before this release - https://github.com/ramda/ramda/issues/3086
|
|
13581
|
-
|
|
13582
|
-
6.5.2
|
|
13583
|
-
|
|
13584
|
-
- Wrong `R.defaultTo` typings - changes introduced in v6.5.0 are missing their TS equivalent.
|
|
13585
|
-
|
|
13586
|
-
- Update dependencies
|
|
13587
|
-
|
|
13588
|
-
6.5.1
|
|
13589
|
-
|
|
13590
|
-
Fix wrong versions in changelog
|
|
13591
|
-
|
|
13592
|
-
6.5.0
|
|
13593
|
-
|
|
13594
|
-
- `R.defaultTo` no longer accepts infinite inputs, thus it follows Ramda implementation.
|
|
13595
|
-
|
|
13596
|
-
- `R.equals` supports equality of functions.
|
|
13597
|
-
|
|
13598
|
-
- `R.pipe` doesn't use `R.compose`.
|
|
13599
|
-
|
|
13600
|
-
- Close [Issue #561](https://github.com/selfrefactor/rambda/issues/561) - export several internal TS interfaces and types
|
|
13601
|
-
|
|
13602
|
-
- Close [Issue #559](https://github.com/selfrefactor/rambda/issues/559) - improve `R.propOr` typings
|
|
13603
|
-
|
|
13604
|
-
- Add `CHANGELOG.md` file in release files list
|
|
13605
|
-
|
|
13606
14036
|
> This is only part of the changelog. You can read the full text in [CHANGELOG.md](CHANGELOG.md) file.
|
|
13607
14037
|
|
|
13608
14038
|
[](#-changelog)
|
|
@@ -13611,25 +14041,25 @@ Fix wrong versions in changelog
|
|
|
13611
14041
|
|
|
13612
14042
|
> Most influential contributors(in alphabetical order)
|
|
13613
14043
|
|
|
13614
|
-
-
|
|
14044
|
+
- [@farwayer](https://github.com/farwayer) - improving performance in R.find, R.filter; give the idea how to make benchmarks more reliable;
|
|
13615
14045
|
|
|
13616
|
-
-
|
|
14046
|
+
- [@thejohnfreeman](https://github.com/thejohnfreeman) - add R.assoc, R.chain;
|
|
13617
14047
|
|
|
13618
|
-
-
|
|
14048
|
+
- [@peeja](https://github.com/peeja) - add several methods and fix mutiple issues; provides great MR documentation
|
|
13619
14049
|
|
|
13620
|
-
-
|
|
14050
|
+
- [@helmuthdu](https://github.com/helmuthdu) - add R.clone; help improve code style;
|
|
13621
14051
|
|
|
13622
|
-
-
|
|
14052
|
+
- [@jpgorman](https://github.com/jpgorman) - add R.zip, R.reject, R.without, R.addIndex;
|
|
13623
14053
|
|
|
13624
|
-
-
|
|
14054
|
+
- [@ku8ar](https://github.com/ku8ar) - add R.slice, R.propOr, R.identical, R.propIs and several math related methods; introduce the idea to display missing Ramda methods;
|
|
13625
14055
|
|
|
13626
|
-
-
|
|
14056
|
+
- [@romgrk](https://github.com/romgrk) - add R.groupBy, R.indexBy, R.findLast, R.findLastIndex;
|
|
13627
14057
|
|
|
13628
|
-
-
|
|
14058
|
+
- [@squidfunk](https://github.com/squidfunk) - add R.assocPath, R.symmetricDifference, R.difference, R.intersperse;
|
|
13629
14059
|
|
|
13630
|
-
-
|
|
14060
|
+
- [@synthet1c](https://github.com/synthet1c) - add all lenses methods; add R.applySpec, R.converge;
|
|
13631
14061
|
|
|
13632
|
-
-
|
|
14062
|
+
- [@vlad-zhukov](https://github.com/vlad-zhukov) - help with configuring Rollup, Babel; change export file to use ES module exports;
|
|
13633
14063
|
|
|
13634
14064
|
> Rambda references
|
|
13635
14065
|
|