rambda 8.6.0 → 9.0.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 +12 -2
- package/README.md +192 -355
- package/dist/rambda.js +85 -3
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +115 -29
- package/index.d.ts +115 -29
- package/package.json +1 -1
- package/rambda.js +10 -3
- package/src/forEach.js +1 -26
- package/src/forEachObjIndexed.js +25 -0
- package/src/gt.js +6 -0
- package/src/gte.js +6 -0
- package/src/hasIn.js +9 -0
- package/src/innerJoin.js +41 -0
- package/src/prop.js +8 -4
- package/src/reduceBy.js +29 -0
- package/src/sortWith.js +27 -0
- package/src/values.js +1 -2
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|

|
|
10
10
|
[](https://packagephobia.com/result?p=rambda)
|
|
11
11
|
[](https://nest.land/package/rambda)
|
|
12
|
-
[](https://github.com/selfrefactor/rambda/pulls)
|
|
13
13
|
|
|
14
14
|
## ❯ Example use
|
|
15
15
|
|
|
@@ -41,7 +41,15 @@ Still, you need to be aware that functional programming features in `TypeScript`
|
|
|
41
41
|
|
|
42
42
|
Important - Rambda version `7.1.0`(or higher) requires TypeScript version `4.3.3`(or higher).
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
### Understandable source code due to little usage of internals
|
|
45
|
+
|
|
46
|
+
`Ramda` uses a lot of internals, which hides a lot of logic. Reading the full source code of a method can be challenging.
|
|
47
|
+
|
|
48
|
+
### Better VSCode experience
|
|
49
|
+
|
|
50
|
+
If the project is written in Javascript, then `go to source definition` action will lead you to actual implementation of the method.
|
|
51
|
+
|
|
52
|
+
### Immutable TS definitions
|
|
45
53
|
|
|
46
54
|
You can use immutable version of Rambda definitions, which is linted with ESLint `functional/prefer-readonly-type` plugin.
|
|
47
55
|
|
|
@@ -98,13 +106,9 @@ One of the main issues with `Ramda` is the slow process of releasing new version
|
|
|
98
106
|
|
|
99
107
|
<details>
|
|
100
108
|
<summary>
|
|
101
|
-
Click to see the full list of
|
|
109
|
+
Click to see the full list of 51 Ramda methods not implemented in Rambda and their status.
|
|
102
110
|
</summary>
|
|
103
111
|
|
|
104
|
-
- gt
|
|
105
|
-
- gte
|
|
106
|
-
- hasIn
|
|
107
|
-
- innerJoin
|
|
108
112
|
- insert
|
|
109
113
|
- insertAll
|
|
110
114
|
- into
|
|
@@ -135,14 +139,12 @@ One of the main issues with `Ramda` is the slow process of releasing new version
|
|
|
135
139
|
- pipeWith
|
|
136
140
|
- project
|
|
137
141
|
- promap
|
|
138
|
-
- reduceBy
|
|
139
142
|
- reduceRight
|
|
140
143
|
- reduceWhile
|
|
141
144
|
- reduced
|
|
142
145
|
- remove
|
|
143
146
|
- scan
|
|
144
147
|
- sequence
|
|
145
|
-
- sortWith
|
|
146
148
|
- splitWhenever
|
|
147
149
|
- swap
|
|
148
150
|
- symmetricDifferenceWith
|
|
@@ -329,10 +331,14 @@ It adds `a` and `b`.
|
|
|
329
331
|
|
|
330
332
|
### addIndex
|
|
331
333
|
|
|
334
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.addIndex(R.map)((val%2C%20idx)%20%3D%3E%20val%20%2B%20idx%20%2B%201%2C%20%5B1%2C%202%2C%203%5D)%0A%2F%2F%20%3D%3E%20%5B2%2C%204%2C%206%5D">Try this <strong>R.addIndex</strong> example in Rambda REPL</a>
|
|
335
|
+
|
|
332
336
|
[](#addIndex)
|
|
333
337
|
|
|
334
338
|
### addIndexRight
|
|
335
339
|
|
|
340
|
+
Same as `R.addIndex`, but it will passed indexes are decreasing, instead of increasing.
|
|
341
|
+
|
|
336
342
|
[](#addIndexRight)
|
|
337
343
|
|
|
338
344
|
### adjust
|
|
@@ -953,6 +959,10 @@ describe('anyPass', () => {
|
|
|
953
959
|
ap<T, U>(fns: Array<(a: T) => U>[], vs: T[]): U[]
|
|
954
960
|
```
|
|
955
961
|
|
|
962
|
+
It takes a list of functions and a list of values. Then it returns a list of values obtained by applying each function to each value.
|
|
963
|
+
|
|
964
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.ap(%0A%20%20%5B%0A%20%20%20%20x%20%3D%3E%20x%20%2B%201%2C%0A%20%20%20%20x%20%3D%3E%20x%20%2B%202%2C%0A%20%20%5D%2C%0A%20%20%5B1%2C%202%2C%203%5D%0A)%0A%2F%2F%20%3D%3E%20%5B2%2C%203%2C%204%2C%203%2C%204%2C%205%5D">Try this <strong>R.ap</strong> example in Rambda REPL</a>
|
|
965
|
+
|
|
956
966
|
<details>
|
|
957
967
|
|
|
958
968
|
<summary>All TypeScript definitions</summary>
|
|
@@ -1011,6 +1021,10 @@ test('happy', () => {
|
|
|
1011
1021
|
aperture<N extends number, T>(n: N, list: T[]): Array<Tuple<T, N>> | []
|
|
1012
1022
|
```
|
|
1013
1023
|
|
|
1024
|
+
It returns a new list, composed of consecutive `n`-tuples from a `list`.
|
|
1025
|
+
|
|
1026
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.aperture(2%2C%20%5B1%2C%202%2C%203%2C%204%5D)%0A%2F%2F%20%3D%3E%20%5B%5B1%2C%202%5D%2C%20%5B2%2C%203%5D%2C%20%5B3%2C%204%5D%5D">Try this <strong>R.aperture</strong> example in Rambda REPL</a>
|
|
1027
|
+
|
|
1014
1028
|
<details>
|
|
1015
1029
|
|
|
1016
1030
|
<summary>All TypeScript definitions</summary>
|
|
@@ -1130,8 +1144,7 @@ export function append(x, input){
|
|
|
1130
1144
|
<summary><strong>Tests</strong></summary>
|
|
1131
1145
|
|
|
1132
1146
|
```javascript
|
|
1133
|
-
|
|
1134
|
-
import { append } from 'ramda'
|
|
1147
|
+
import { append } from './append.js'
|
|
1135
1148
|
|
|
1136
1149
|
test('happy', () => {
|
|
1137
1150
|
expect(append('tests', [ 'write', 'more' ])).toEqual([
|
|
@@ -1761,10 +1774,14 @@ describe('applySpec', () => {
|
|
|
1761
1774
|
|
|
1762
1775
|
### applyTo
|
|
1763
1776
|
|
|
1777
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.applyTo(%0A%20%201%2C%0A%20%20x%20%3D%3E%20x%20%2B%201%0A)%0A%2F%2F%20%3D%3E%202">Try this <strong>R.applyTo</strong> example in Rambda REPL</a>
|
|
1778
|
+
|
|
1764
1779
|
[](#applyTo)
|
|
1765
1780
|
|
|
1766
1781
|
### ascend
|
|
1767
1782
|
|
|
1783
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.sort(%0A%20%20R.ascend(x%20%3D%3E%20x)%2C%0A%20%20%5B2%2C%201%5D%0A)%0A%2F%2F%20%3D%3E%20%5B1%2C%202%5D">Try this <strong>R.ascend</strong> example in Rambda REPL</a>
|
|
1784
|
+
|
|
1768
1785
|
[](#ascend)
|
|
1769
1786
|
|
|
1770
1787
|
### assoc
|
|
@@ -2106,6 +2123,8 @@ describe('R.assocPath - curried', () => {
|
|
|
2106
2123
|
|
|
2107
2124
|
### binary
|
|
2108
2125
|
|
|
2126
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.binary(%0A%20%20(a%2C%20b%2C%20c)%20%3D%3E%20a%20%2B%20b%20%2B%20c%2C%0A)(1%2C%202%2C%203%2C%204)%0A%2F%2F%20%3D%3E%203">Try this <strong>R.binary</strong> example in Rambda REPL</a>
|
|
2127
|
+
|
|
2109
2128
|
[](#binary)
|
|
2110
2129
|
|
|
2111
2130
|
### bind
|
|
@@ -2418,6 +2437,8 @@ describe('R.both', () => {
|
|
|
2418
2437
|
|
|
2419
2438
|
### call
|
|
2420
2439
|
|
|
2440
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.call(%0A%20%20(a%2C%20b)%20%3D%3E%20a%20%2B%20b%2C%0A%20%201%2C%0A%20%202%0A)%0A%2F%2F%20%3D%3E%203">Try this <strong>R.call</strong> example in Rambda REPL</a>
|
|
2441
|
+
|
|
2421
2442
|
[](#call)
|
|
2422
2443
|
|
|
2423
2444
|
### chain
|
|
@@ -2577,10 +2598,16 @@ It creates a deep copy of the `input`, which may contain (nested) Arrays and Obj
|
|
|
2577
2598
|
|
|
2578
2599
|
### collectBy
|
|
2579
2600
|
|
|
2601
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.collectBy(%0A%20%20x%20%3D%3E%20x%20%25%202%2C%0A%20%20%5B1%2C%202%2C%203%2C%204%5D%0A)%0A%2F%2F%20%3D%3E%20%5B%5B2%2C%204%5D%2C%20%5B1%2C%203%5D%5D">Try this <strong>R.collectBy</strong> example in Rambda REPL</a>
|
|
2602
|
+
|
|
2580
2603
|
[](#collectBy)
|
|
2581
2604
|
|
|
2582
2605
|
### comparator
|
|
2583
2606
|
|
|
2607
|
+
It returns a comparator function that can be used in `sort` method.
|
|
2608
|
+
|
|
2609
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.sort(%0A%20%20R.comparator((a%2C%20b)%20%3D%3E%20a.x%20%3C%20b.x)%2C%0A%20%20%5B%7Bx%3A%202%7D%2C%20%7Bx%3A%201%7D%5D%0A)%0A%2F%2F%20%3D%3E%20%5B%7Bx%3A%201%7D%2C%20%7Bx%3A%202%7D%5D">Try this <strong>R.comparator</strong> example in Rambda REPL</a>
|
|
2610
|
+
|
|
2584
2611
|
[](#comparator)
|
|
2585
2612
|
|
|
2586
2613
|
### complement
|
|
@@ -2603,6 +2630,8 @@ It performs right-to-left function composition.
|
|
|
2603
2630
|
|
|
2604
2631
|
### composeWith
|
|
2605
2632
|
|
|
2633
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.composeWith(%0A%20%20(fn%2C%20intermediateResult)%20%3D%3E%20fn(intermediateResult)%2C%0A%20%20%5B%0A%20%20%20%20R.map(x%20%3D%3E%20x%20%2B%201)%2C%0A%20%20%20%20R.map(x%20%3D%3E%20x%20*%202)%2C%0A%20%20%5D%0A)(%5B1%2C%202%2C%203%5D)%0A%2F%2F%20%3D%3E%20%5B3%2C%205%2C%207%5D">Try this <strong>R.composeWith</strong> example in Rambda REPL</a>
|
|
2634
|
+
|
|
2606
2635
|
[](#composeWith)
|
|
2607
2636
|
|
|
2608
2637
|
### concat
|
|
@@ -2758,6 +2787,8 @@ It returns a curried equivalent of the provided function, with the specified ari
|
|
|
2758
2787
|
|
|
2759
2788
|
It decrements a number.
|
|
2760
2789
|
|
|
2790
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.dec(2)%20%2F%2F%20%3D%3E%201">Try this <strong>R.dec</strong> example in Rambda REPL</a>
|
|
2791
|
+
|
|
2761
2792
|
[](#dec)
|
|
2762
2793
|
|
|
2763
2794
|
### defaultTo
|
|
@@ -2865,6 +2896,8 @@ describe('R.defaultTo with Ramda spec', () => {
|
|
|
2865
2896
|
|
|
2866
2897
|
### descend
|
|
2867
2898
|
|
|
2899
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?R.sort(%0A%20%20R.descend(x%20%3D%3E%20x)%2C%0A%20%20%5B1%2C%202%5D%0Aconst%20result%20%3D%20)%0A%2F%2F%20%3D%3E%20%5B2%2C%201%5D">Try this <strong>R.descend</strong> example in Rambda REPL</a>
|
|
2900
|
+
|
|
2868
2901
|
[](#descend)
|
|
2869
2902
|
|
|
2870
2903
|
### difference
|
|
@@ -2984,6 +3017,8 @@ differenceWith<T1, T2>(
|
|
|
2984
3017
|
): T1[]
|
|
2985
3018
|
```
|
|
2986
3019
|
|
|
3020
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.differenceWith(%0A%20%20(a%2C%20b)%20%3D%3E%20a.x%20%3D%3D%3D%20b.x%2C%0A%20%20%5B%7Bx%3A%201%7D%2C%20%7Bx%3A%202%7D%5D%2C%0A%20%20%5B%7Bx%3A%201%7D%2C%20%7Bx%3A%203%7D%5D%0A)%0A%2F%2F%20%3D%3E%20%5B%7Bx%3A%202%7D%5D">Try this <strong>R.differenceWith</strong> example in Rambda REPL</a>
|
|
3021
|
+
|
|
2987
3022
|
<details>
|
|
2988
3023
|
|
|
2989
3024
|
<summary>All TypeScript definitions</summary>
|
|
@@ -3068,6 +3103,8 @@ It returns a new object that does not contain property `prop`.
|
|
|
3068
3103
|
|
|
3069
3104
|
### dissocPath
|
|
3070
3105
|
|
|
3106
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.dissocPath(%5B'a'%2C%20'b'%5D%2C%20%7Ba%3A%20%7Bb%3A%201%2C%20c%3A%202%7D%7D)%0A%2F%2F%20%3D%3E%20%7Ba%3A%20%7Bc%3A%202%7D%7D">Try this <strong>R.dissocPath</strong> example in Rambda REPL</a>
|
|
3107
|
+
|
|
3071
3108
|
[](#dissocPath)
|
|
3072
3109
|
|
|
3073
3110
|
### divide
|
|
@@ -3435,6 +3472,8 @@ describe('R.dropRepeats', () => {
|
|
|
3435
3472
|
|
|
3436
3473
|
### dropRepeatsBy
|
|
3437
3474
|
|
|
3475
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.dropRepeatsBy(%0A%20%20Math.abs%2C%0A%20%20%5B1%2C%20-1%2C%202%2C%203%2C%20-3%5D%0A)%0A%2F%2F%20%3D%3E%20%5B1%2C%202%2C%203%5D">Try this <strong>R.dropRepeatsBy</strong> example in Rambda REPL</a>
|
|
3476
|
+
|
|
3438
3477
|
[](#dropRepeatsBy)
|
|
3439
3478
|
|
|
3440
3479
|
### dropRepeatsWith
|
|
@@ -3604,6 +3643,8 @@ describe('R.either', () => {
|
|
|
3604
3643
|
|
|
3605
3644
|
### empty
|
|
3606
3645
|
|
|
3646
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5BR.empty(%5B1%2C2%2C3%5D)%2C%20R.empty('foo')%2C%20R.empty(%7Bx%3A%201%2C%20y%3A%202%7D)%5D%0A%2F%2F%20%3D%3E%20%5B%5B%5D%2C%20''%2C%20%7B%7D%5D">Try this <strong>R.empty</strong> example in Rambda REPL</a>
|
|
3647
|
+
|
|
3607
3648
|
[](#empty)
|
|
3608
3649
|
|
|
3609
3650
|
### endsWith
|
|
@@ -3769,6 +3810,8 @@ describe('R.endsWith - string', () => {
|
|
|
3769
3810
|
|
|
3770
3811
|
### eqBy
|
|
3771
3812
|
|
|
3813
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.eqBy(Math.abs%2C%205%2C%20-5)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.eqBy</strong> example in Rambda REPL</a>
|
|
3814
|
+
|
|
3772
3815
|
[](#eqBy)
|
|
3773
3816
|
|
|
3774
3817
|
### eqProps
|
|
@@ -5427,35 +5470,10 @@ forEach<T, U>(fn: ObjectIterator<T, void>): (list: Dictionary<T>) => Dictionary<
|
|
|
5427
5470
|
|
|
5428
5471
|
```javascript
|
|
5429
5472
|
import { isArray } from './_internals/isArray.js'
|
|
5430
|
-
import {
|
|
5431
|
-
|
|
5432
|
-
export function forEachObjIndexedFn(fn, obj){
|
|
5433
|
-
let index = 0
|
|
5434
|
-
const listKeys = keys(obj)
|
|
5435
|
-
const len = listKeys.length
|
|
5436
|
-
|
|
5437
|
-
while (index < len){
|
|
5438
|
-
const key = listKeys[ index ]
|
|
5439
|
-
fn(
|
|
5440
|
-
obj[ key ], key, obj
|
|
5441
|
-
)
|
|
5442
|
-
index++
|
|
5443
|
-
}
|
|
5444
|
-
|
|
5445
|
-
return obj
|
|
5446
|
-
}
|
|
5447
|
-
|
|
5448
|
-
export function forEachObjIndexed(fn, list){
|
|
5449
|
-
if (arguments.length === 1) return _list => forEachObjIndexed(fn, _list)
|
|
5450
|
-
|
|
5451
|
-
if (list === undefined) return
|
|
5452
|
-
|
|
5453
|
-
return forEachObjIndexedFn(fn, list)
|
|
5454
|
-
}
|
|
5473
|
+
import { forEachObjIndexedFn } from './forEachObjIndexed.js'
|
|
5455
5474
|
|
|
5456
5475
|
export function forEach(fn, iterable){
|
|
5457
5476
|
if (arguments.length === 1) return _list => forEach(fn, _list)
|
|
5458
|
-
|
|
5459
5477
|
if (iterable === undefined) return
|
|
5460
5478
|
|
|
5461
5479
|
if (isArray(iterable)){
|
|
@@ -5627,6 +5645,18 @@ It returns separated version of list or string `input`, where separation is done
|
|
|
5627
5645
|
|
|
5628
5646
|
[](#groupWith)
|
|
5629
5647
|
|
|
5648
|
+
### gt
|
|
5649
|
+
|
|
5650
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5BR.gt(2%2C%201)%2C%20R.gt(2%2C%203)%5D%0A%2F%2F%20%3D%3E%20%5Btrue%2C%20false%5D">Try this <strong>R.gt</strong> example in Rambda REPL</a>
|
|
5651
|
+
|
|
5652
|
+
[](#gt)
|
|
5653
|
+
|
|
5654
|
+
### gte
|
|
5655
|
+
|
|
5656
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5BR.gte(2%2C%201)%2C%20R.gte(2%2C%202)%2C%20R.gte(2%2C%203)%5D%0A%2F%2F%20%3D%3E%20%5Btrue%2C%20true%2C%20false%5D">Try this <strong>R.gte</strong> example in Rambda REPL</a>
|
|
5657
|
+
|
|
5658
|
+
[](#gte)
|
|
5659
|
+
|
|
5630
5660
|
### has
|
|
5631
5661
|
|
|
5632
5662
|
```typescript
|
|
@@ -5709,6 +5739,12 @@ describe('R.has', () => {
|
|
|
5709
5739
|
|
|
5710
5740
|
[](#has)
|
|
5711
5741
|
|
|
5742
|
+
### hasIn
|
|
5743
|
+
|
|
5744
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.hasIn('a'%2C%20%7Ba%3A%201%7D)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.hasIn</strong> example in Rambda REPL</a>
|
|
5745
|
+
|
|
5746
|
+
[](#hasIn)
|
|
5747
|
+
|
|
5712
5748
|
### hasPath
|
|
5713
5749
|
|
|
5714
5750
|
```typescript
|
|
@@ -6487,6 +6523,14 @@ describe('R.init', () => {
|
|
|
6487
6523
|
|
|
6488
6524
|
[](#init)
|
|
6489
6525
|
|
|
6526
|
+
### innerJoin
|
|
6527
|
+
|
|
6528
|
+
It returns a new list by applying a `predicate` function to all elements of `list1` and `list2` and keeping only these elements where `predicate` returns `true`.
|
|
6529
|
+
|
|
6530
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20list1%20%3D%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%0Aconst%20list2%20%3D%20%5B4%2C%205%2C%206%5D%0Aconst%20predicate%20%3D%20(x%2C%20y)%20%3D%3E%20x%20%3E%3D%20y%0Aconst%20result%20%3D%20R.innerJoin(predicate%2C%20list1%2C%20list2)%0A%2F%2F%20%3D%3E%20%5B4%2C%205%5D">Try this <strong>R.innerJoin</strong> example in Rambda REPL</a>
|
|
6531
|
+
|
|
6532
|
+
[](#innerJoin)
|
|
6533
|
+
|
|
6490
6534
|
### intersection
|
|
6491
6535
|
|
|
6492
6536
|
It loops through `listA` and `listB` and returns the intersection of the two according to `R.equals`.
|
|
@@ -7143,7 +7187,7 @@ test('with length as property', () => {
|
|
|
7143
7187
|
|
|
7144
7188
|
```typescript
|
|
7145
7189
|
|
|
7146
|
-
lens<
|
|
7190
|
+
lens<S, A>(getter: (s: S) => A, setter: (a: A, s: S) => S): Lens<S, A>
|
|
7147
7191
|
```
|
|
7148
7192
|
|
|
7149
7193
|
It returns a `lens` for the given `getter` and `setter` functions.
|
|
@@ -7159,7 +7203,7 @@ The setter should not mutate the data structure.
|
|
|
7159
7203
|
<summary>All TypeScript definitions</summary>
|
|
7160
7204
|
|
|
7161
7205
|
```typescript
|
|
7162
|
-
lens<
|
|
7206
|
+
lens<S, A>(getter: (s: S) => A, setter: (a: A, s: S) => S): Lens<S, A>;
|
|
7163
7207
|
```
|
|
7164
7208
|
|
|
7165
7209
|
</details>
|
|
@@ -7185,19 +7229,56 @@ export function lens(getter, setter){
|
|
|
7185
7229
|
<summary><strong>TypeScript</strong> test</summary>
|
|
7186
7230
|
|
|
7187
7231
|
```typescript
|
|
7188
|
-
import {lens, assoc} from 'rambda'
|
|
7232
|
+
import {lens, assoc, lensProp, view, lensIndex, lensPath} from 'rambda'
|
|
7189
7233
|
|
|
7190
7234
|
interface Input {
|
|
7191
7235
|
foo: string,
|
|
7192
7236
|
}
|
|
7237
|
+
const testObject: Input = {
|
|
7238
|
+
foo: 'Jazz',
|
|
7239
|
+
}
|
|
7193
7240
|
|
|
7194
7241
|
describe('R.lens', () => {
|
|
7195
7242
|
it('happy', () => {
|
|
7196
|
-
const fn = lens<Input, string
|
|
7243
|
+
const fn = lens<Input, string>((x: Input) => {
|
|
7197
7244
|
x.foo // $ExpectType string
|
|
7198
7245
|
return x.foo
|
|
7199
7246
|
}, assoc('name'))
|
|
7200
|
-
fn // $ExpectType Lens
|
|
7247
|
+
fn // $ExpectType Lens<Input, string>
|
|
7248
|
+
})
|
|
7249
|
+
})
|
|
7250
|
+
|
|
7251
|
+
describe('R.lensProp', () => {
|
|
7252
|
+
it('happy', () => {
|
|
7253
|
+
const result = view<Input, string>(lensProp('foo'), testObject)
|
|
7254
|
+
result // $ExpectType string
|
|
7255
|
+
})
|
|
7256
|
+
})
|
|
7257
|
+
|
|
7258
|
+
describe('R.lensIndex', () => {
|
|
7259
|
+
const testList: Input[] = [{foo: 'bar'}, {foo: 'baz'}]
|
|
7260
|
+
it('happy', () => {
|
|
7261
|
+
const result = view<Input[], Input>(lensIndex(0), testList)
|
|
7262
|
+
result // $ExpectType Input
|
|
7263
|
+
result.foo // $ExpectType string
|
|
7264
|
+
})
|
|
7265
|
+
})
|
|
7266
|
+
|
|
7267
|
+
describe('R.lensPath', () => {
|
|
7268
|
+
const path = lensPath(['bar', 'a'])
|
|
7269
|
+
it('happy', () => {
|
|
7270
|
+
const result = view<Input, string>(path, testObject)
|
|
7271
|
+
result // $ExpectType string
|
|
7272
|
+
})
|
|
7273
|
+
})
|
|
7274
|
+
|
|
7275
|
+
describe('R.view', () => {
|
|
7276
|
+
const fooLens = lens<Input, string>((x: Input) => {
|
|
7277
|
+
return x.foo
|
|
7278
|
+
}, assoc('foo'))
|
|
7279
|
+
it('happt', () => {
|
|
7280
|
+
const result = view<Input, string>(fooLens, testObject)
|
|
7281
|
+
result // $ExpectType string
|
|
7201
7282
|
})
|
|
7202
7283
|
})
|
|
7203
7284
|
```
|
|
@@ -7210,7 +7291,7 @@ describe('R.lens', () => {
|
|
|
7210
7291
|
|
|
7211
7292
|
```typescript
|
|
7212
7293
|
|
|
7213
|
-
lensIndex(
|
|
7294
|
+
lensIndex<A>(n: number): Lens<A[], A>
|
|
7214
7295
|
```
|
|
7215
7296
|
|
|
7216
7297
|
It returns a lens that focuses on specified `index`.
|
|
@@ -7222,7 +7303,8 @@ It returns a lens that focuses on specified `index`.
|
|
|
7222
7303
|
<summary>All TypeScript definitions</summary>
|
|
7223
7304
|
|
|
7224
7305
|
```typescript
|
|
7225
|
-
lensIndex(
|
|
7306
|
+
lensIndex<A>(n: number): Lens<A[], A>;
|
|
7307
|
+
lensIndex<A extends any[], N extends number>(n: N): Lens<A, A[N]>;
|
|
7226
7308
|
```
|
|
7227
7309
|
|
|
7228
7310
|
</details>
|
|
@@ -7308,250 +7390,21 @@ test('get (set(set s v1) v2) === v2', () => {
|
|
|
7308
7390
|
|
|
7309
7391
|
</details>
|
|
7310
7392
|
|
|
7311
|
-
<details>
|
|
7312
|
-
|
|
7313
|
-
<summary><strong>TypeScript</strong> test</summary>
|
|
7314
|
-
|
|
7315
|
-
```typescript
|
|
7316
|
-
import {view, lensIndex} from 'rambda'
|
|
7317
|
-
|
|
7318
|
-
interface Input {
|
|
7319
|
-
a: number,
|
|
7320
|
-
}
|
|
7321
|
-
const testList: Input[] = [{a: 1}, {a: 2}, {a: 3}]
|
|
7322
|
-
|
|
7323
|
-
describe('R.lensIndex', () => {
|
|
7324
|
-
it('happy', () => {
|
|
7325
|
-
const result = view<Input[], Input>(lensIndex(0), testList)
|
|
7326
|
-
result // $ExpectType Input
|
|
7327
|
-
result.a // $ExpectType number
|
|
7328
|
-
})
|
|
7329
|
-
})
|
|
7330
|
-
```
|
|
7331
|
-
|
|
7332
|
-
</details>
|
|
7333
|
-
|
|
7334
7393
|
[](#lensIndex)
|
|
7335
7394
|
|
|
7336
7395
|
### lensPath
|
|
7337
7396
|
|
|
7338
|
-
```typescript
|
|
7339
|
-
|
|
7340
|
-
lensPath(path: RamdaPath): Lens
|
|
7341
|
-
```
|
|
7342
|
-
|
|
7343
7397
|
It returns a lens that focuses on specified `path`.
|
|
7344
7398
|
|
|
7345
7399
|
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20lensPath%20%3D%20R.lensPath(%5B'x'%2C%200%2C%20'y'%5D)%0Aconst%20input%20%3D%20%7Bx%3A%20%5B%7By%3A%202%2C%20z%3A%203%7D%2C%20%7By%3A%204%2C%20z%3A%205%7D%5D%7D%0A%0AR.view(lensPath%2C%20input)%20%2F%2F%20%3D%3E%202%0A%0AR.set(lensPath%2C%201%2C%20input)%20%0A%2F%2F%20%3D%3E%20%7Bx%3A%20%5B%7By%3A%201%2C%20z%3A%203%7D%2C%20%7By%3A%204%2C%20z%3A%205%7D%5D%7D%0A%0Aconst%20result%20%3D%20R.over(xHeadYLens%2C%20R.negate%2C%20input)%20%0A%2F%2F%20%3D%3E%20%7Bx%3A%20%5B%7By%3A%20-2%2C%20z%3A%203%7D%2C%20%7By%3A%204%2C%20z%3A%205%7D%5D%7D">Try this <strong>R.lensPath</strong> example in Rambda REPL</a>
|
|
7346
7400
|
|
|
7347
|
-
<details>
|
|
7348
|
-
|
|
7349
|
-
<summary>All TypeScript definitions</summary>
|
|
7350
|
-
|
|
7351
|
-
```typescript
|
|
7352
|
-
lensPath(path: RamdaPath): Lens;
|
|
7353
|
-
lensPath(path: string): Lens;
|
|
7354
|
-
```
|
|
7355
|
-
|
|
7356
|
-
</details>
|
|
7357
|
-
|
|
7358
|
-
<details>
|
|
7359
|
-
|
|
7360
|
-
<summary><strong>R.lensPath</strong> source</summary>
|
|
7361
|
-
|
|
7362
|
-
```javascript
|
|
7363
|
-
import { assocPath } from './assocPath.js'
|
|
7364
|
-
import { lens } from './lens.js'
|
|
7365
|
-
import { path } from './path.js'
|
|
7366
|
-
|
|
7367
|
-
export function lensPath(key){
|
|
7368
|
-
return lens(path(key), assocPath(key))
|
|
7369
|
-
}
|
|
7370
|
-
```
|
|
7371
|
-
|
|
7372
|
-
</details>
|
|
7373
|
-
|
|
7374
|
-
<details>
|
|
7375
|
-
|
|
7376
|
-
<summary><strong>Tests</strong></summary>
|
|
7377
|
-
|
|
7378
|
-
```javascript
|
|
7379
|
-
import { compose } from './compose.js'
|
|
7380
|
-
import { identity } from './identity.js'
|
|
7381
|
-
import { inc } from './inc.js'
|
|
7382
|
-
import { lensPath } from './lensPath.js'
|
|
7383
|
-
import { lensProp } from './lensProp.js'
|
|
7384
|
-
import { over } from './over.js'
|
|
7385
|
-
import { set } from './set.js'
|
|
7386
|
-
import { view } from './view.js'
|
|
7387
|
-
|
|
7388
|
-
const testObj = {
|
|
7389
|
-
a : [ { b : 1 }, { b : 2 } ],
|
|
7390
|
-
d : 3,
|
|
7391
|
-
}
|
|
7392
|
-
|
|
7393
|
-
test('view', () => {
|
|
7394
|
-
expect(view(lensPath('d'), testObj)).toBe(3)
|
|
7395
|
-
expect(view(lensPath('a.0.b'), testObj)).toBe(1)
|
|
7396
|
-
// this is different to ramda, as ramda will return a clone of the input object
|
|
7397
|
-
expect(view(lensPath(''), testObj)).toBeUndefined()
|
|
7398
|
-
})
|
|
7399
|
-
|
|
7400
|
-
test('set', () => {
|
|
7401
|
-
expect(set(
|
|
7402
|
-
lensProp('d'), 0, testObj
|
|
7403
|
-
)).toEqual({
|
|
7404
|
-
a : [ { b : 1 }, { b : 2 } ],
|
|
7405
|
-
d : 0,
|
|
7406
|
-
})
|
|
7407
|
-
expect(set(
|
|
7408
|
-
lensPath('a.0.b'), 0, testObj
|
|
7409
|
-
)).toEqual({
|
|
7410
|
-
a : [ { b : 0 }, { b : 2 } ],
|
|
7411
|
-
d : 3,
|
|
7412
|
-
})
|
|
7413
|
-
expect(set(
|
|
7414
|
-
lensPath('a.0.X'), 0, testObj
|
|
7415
|
-
)).toEqual({
|
|
7416
|
-
a : [
|
|
7417
|
-
{
|
|
7418
|
-
b : 1,
|
|
7419
|
-
X : 0,
|
|
7420
|
-
},
|
|
7421
|
-
{ b : 2 },
|
|
7422
|
-
],
|
|
7423
|
-
d : 3,
|
|
7424
|
-
})
|
|
7425
|
-
expect(set(
|
|
7426
|
-
lensPath([]), 0, testObj
|
|
7427
|
-
)).toBe(0)
|
|
7428
|
-
})
|
|
7429
|
-
|
|
7430
|
-
test('over', () => {
|
|
7431
|
-
expect(over(
|
|
7432
|
-
lensPath('d'), inc, testObj
|
|
7433
|
-
)).toEqual({
|
|
7434
|
-
a : [ { b : 1 }, { b : 2 } ],
|
|
7435
|
-
d : 4,
|
|
7436
|
-
})
|
|
7437
|
-
expect(over(
|
|
7438
|
-
lensPath('a.1.b'), inc, testObj
|
|
7439
|
-
)).toEqual({
|
|
7440
|
-
a : [ { b : 1 }, { b : 3 } ],
|
|
7441
|
-
d : 3,
|
|
7442
|
-
})
|
|
7443
|
-
expect(over(
|
|
7444
|
-
lensProp('X'), identity, testObj
|
|
7445
|
-
)).toEqual({
|
|
7446
|
-
a : [ { b : 1 }, { b : 2 } ],
|
|
7447
|
-
d : 3,
|
|
7448
|
-
X : undefined,
|
|
7449
|
-
})
|
|
7450
|
-
expect(over(
|
|
7451
|
-
lensPath('a.0.X'), identity, testObj
|
|
7452
|
-
)).toEqual({
|
|
7453
|
-
a : [
|
|
7454
|
-
{
|
|
7455
|
-
b : 1,
|
|
7456
|
-
X : undefined,
|
|
7457
|
-
},
|
|
7458
|
-
{ b : 2 },
|
|
7459
|
-
],
|
|
7460
|
-
d : 3,
|
|
7461
|
-
})
|
|
7462
|
-
})
|
|
7463
|
-
|
|
7464
|
-
test('compose', () => {
|
|
7465
|
-
const composedLens = compose(lensPath('a'), lensPath('1.b'))
|
|
7466
|
-
expect(view(composedLens, testObj)).toBe(2)
|
|
7467
|
-
})
|
|
7468
|
-
|
|
7469
|
-
test('set s (get s) === s', () => {
|
|
7470
|
-
expect(set(
|
|
7471
|
-
lensPath([ 'd' ]), view(lensPath([ 'd' ]), testObj), testObj
|
|
7472
|
-
)).toEqual(testObj)
|
|
7473
|
-
expect(set(
|
|
7474
|
-
lensPath([ 'a', 0, 'b' ]),
|
|
7475
|
-
view(lensPath([ 'a', 0, 'b' ]), testObj),
|
|
7476
|
-
testObj
|
|
7477
|
-
)).toEqual(testObj)
|
|
7478
|
-
})
|
|
7479
|
-
|
|
7480
|
-
test('get (set s v) === v', () => {
|
|
7481
|
-
expect(view(lensPath([ 'd' ]), set(
|
|
7482
|
-
lensPath([ 'd' ]), 0, testObj
|
|
7483
|
-
))).toBe(0)
|
|
7484
|
-
expect(view(lensPath([ 'a', 0, 'b' ]), set(
|
|
7485
|
-
lensPath([ 'a', 0, 'b' ]), 0, testObj
|
|
7486
|
-
))).toBe(0)
|
|
7487
|
-
})
|
|
7488
|
-
|
|
7489
|
-
test('get (set(set s v1) v2) === v2', () => {
|
|
7490
|
-
const p = [ 'd' ]
|
|
7491
|
-
const q = [ 'a', 0, 'b' ]
|
|
7492
|
-
expect(view(lensPath(p), set(
|
|
7493
|
-
lensPath(p), 11, set(
|
|
7494
|
-
lensPath(p), 10, testObj
|
|
7495
|
-
)
|
|
7496
|
-
))).toBe(11)
|
|
7497
|
-
expect(view(lensPath(q), set(
|
|
7498
|
-
lensPath(q), 11, set(
|
|
7499
|
-
lensPath(q), 10, testObj
|
|
7500
|
-
)
|
|
7501
|
-
))).toBe(11)
|
|
7502
|
-
})
|
|
7503
|
-
```
|
|
7504
|
-
|
|
7505
|
-
</details>
|
|
7506
|
-
|
|
7507
|
-
<details>
|
|
7508
|
-
|
|
7509
|
-
<summary><strong>TypeScript</strong> test</summary>
|
|
7510
|
-
|
|
7511
|
-
```typescript
|
|
7512
|
-
import {lensPath, view} from 'rambda'
|
|
7513
|
-
|
|
7514
|
-
interface Input {
|
|
7515
|
-
foo: number[],
|
|
7516
|
-
bar: {
|
|
7517
|
-
a: string,
|
|
7518
|
-
b: string,
|
|
7519
|
-
},
|
|
7520
|
-
}
|
|
7521
|
-
|
|
7522
|
-
const testObject: Input = {
|
|
7523
|
-
foo: [1, 2],
|
|
7524
|
-
bar: {
|
|
7525
|
-
a: 'x',
|
|
7526
|
-
b: 'y',
|
|
7527
|
-
},
|
|
7528
|
-
}
|
|
7529
|
-
|
|
7530
|
-
const path = lensPath(['bar', 'a'])
|
|
7531
|
-
const pathAsString = lensPath('bar.a')
|
|
7532
|
-
|
|
7533
|
-
describe('R.lensPath', () => {
|
|
7534
|
-
it('happy', () => {
|
|
7535
|
-
const result = view<Input, string>(path, testObject)
|
|
7536
|
-
result // $ExpectType string
|
|
7537
|
-
})
|
|
7538
|
-
it('using string as path input', () => {
|
|
7539
|
-
const result = view<Input, string>(pathAsString, testObject)
|
|
7540
|
-
result // $ExpectType string
|
|
7541
|
-
})
|
|
7542
|
-
})
|
|
7543
|
-
```
|
|
7544
|
-
|
|
7545
|
-
</details>
|
|
7546
|
-
|
|
7547
7401
|
[](#lensPath)
|
|
7548
7402
|
|
|
7549
7403
|
### lensProp
|
|
7550
7404
|
|
|
7551
7405
|
```typescript
|
|
7552
7406
|
|
|
7553
|
-
lensProp(prop:
|
|
7554
|
-
<T, U>(obj: T): U
|
|
7407
|
+
lensProp<S, K extends keyof S = keyof S>(prop: K): Lens<S, S[K]>
|
|
7555
7408
|
```
|
|
7556
7409
|
|
|
7557
7410
|
It returns a lens that focuses on specified property `prop`.
|
|
@@ -7563,10 +7416,7 @@ It returns a lens that focuses on specified property `prop`.
|
|
|
7563
7416
|
<summary>All TypeScript definitions</summary>
|
|
7564
7417
|
|
|
7565
7418
|
```typescript
|
|
7566
|
-
lensProp(prop:
|
|
7567
|
-
<T, U>(obj: T): U;
|
|
7568
|
-
set<T, U, V>(val: T, obj: U): V;
|
|
7569
|
-
};
|
|
7419
|
+
lensProp<S, K extends keyof S = keyof S>(prop: K): Lens<S, S[K]>;
|
|
7570
7420
|
```
|
|
7571
7421
|
|
|
7572
7422
|
</details>
|
|
@@ -7690,33 +7540,6 @@ test('get (set(set s v1) v2) === v2', () => {
|
|
|
7690
7540
|
|
|
7691
7541
|
</details>
|
|
7692
7542
|
|
|
7693
|
-
<details>
|
|
7694
|
-
|
|
7695
|
-
<summary><strong>TypeScript</strong> test</summary>
|
|
7696
|
-
|
|
7697
|
-
```typescript
|
|
7698
|
-
import {lensProp, view} from 'rambda'
|
|
7699
|
-
|
|
7700
|
-
interface Input {
|
|
7701
|
-
foo: string,
|
|
7702
|
-
}
|
|
7703
|
-
|
|
7704
|
-
const testObject: Input = {
|
|
7705
|
-
foo: 'Led Zeppelin',
|
|
7706
|
-
}
|
|
7707
|
-
|
|
7708
|
-
const lens = lensProp('foo')
|
|
7709
|
-
|
|
7710
|
-
describe('R.lensProp', () => {
|
|
7711
|
-
it('happy', () => {
|
|
7712
|
-
const result = view<Input, string>(lens, testObject)
|
|
7713
|
-
result // $ExpectType string
|
|
7714
|
-
})
|
|
7715
|
-
})
|
|
7716
|
-
```
|
|
7717
|
-
|
|
7718
|
-
</details>
|
|
7719
|
-
|
|
7720
7543
|
[](#lensProp)
|
|
7721
7544
|
|
|
7722
7545
|
### map
|
|
@@ -9980,7 +9803,8 @@ Logical OR
|
|
|
9980
9803
|
|
|
9981
9804
|
```typescript
|
|
9982
9805
|
|
|
9983
|
-
over<
|
|
9806
|
+
over<S, A>(lens: Lens<S, A>): {
|
|
9807
|
+
(fn: (a: A) => A): (value: S) => S
|
|
9984
9808
|
```
|
|
9985
9809
|
|
|
9986
9810
|
It returns a copied **Object** or **Array** with modified value received by applying function `fn` to `lens` focus.
|
|
@@ -9992,12 +9816,12 @@ It returns a copied **Object** or **Array** with modified value received by appl
|
|
|
9992
9816
|
<summary>All TypeScript definitions</summary>
|
|
9993
9817
|
|
|
9994
9818
|
```typescript
|
|
9995
|
-
over<
|
|
9996
|
-
|
|
9997
|
-
|
|
9998
|
-
|
|
9999
|
-
over(lens: Lens
|
|
10000
|
-
over(lens: Lens
|
|
9819
|
+
over<S, A>(lens: Lens<S, A>): {
|
|
9820
|
+
(fn: (a: A) => A): (value: S) => S;
|
|
9821
|
+
(fn: (a: A) => A, value: S): S;
|
|
9822
|
+
};
|
|
9823
|
+
over<S, A>(lens: Lens<S, A>, fn: (a: A) => A): (value: S) => S;
|
|
9824
|
+
over<S, A>(lens: Lens<S, A>, fn: (a: A) => A, value: S): S;
|
|
10001
9825
|
```
|
|
10002
9826
|
|
|
10003
9827
|
</details>
|
|
@@ -11690,6 +11514,10 @@ test('happy', () => {
|
|
|
11690
11514
|
expect(pluck('a')([ { a : 1 }, { a : 2 }, { b : 1 } ])).toEqual([ 1, 2 ])
|
|
11691
11515
|
})
|
|
11692
11516
|
|
|
11517
|
+
test('with undefined', () => {
|
|
11518
|
+
expect(pluck(undefined)([ { a : 1 }, { a : 2 }, { b : 1 } ])).toEqual([ ])
|
|
11519
|
+
})
|
|
11520
|
+
|
|
11693
11521
|
test('with number', () => {
|
|
11694
11522
|
const input = [
|
|
11695
11523
|
[ 1, 2 ],
|
|
@@ -11914,12 +11742,16 @@ prop<V>(p: keyof never): (value: unknown) => V;
|
|
|
11914
11742
|
<summary><strong>R.prop</strong> source</summary>
|
|
11915
11743
|
|
|
11916
11744
|
```javascript
|
|
11917
|
-
export function
|
|
11918
|
-
if (arguments.length === 1) return _obj => prop(propToFind, _obj)
|
|
11919
|
-
|
|
11745
|
+
export function propFn(searchProperty, obj){
|
|
11920
11746
|
if (!obj) return undefined
|
|
11921
11747
|
|
|
11922
|
-
return obj[
|
|
11748
|
+
return obj[ searchProperty ]
|
|
11749
|
+
}
|
|
11750
|
+
|
|
11751
|
+
export function prop(searchProperty, obj){
|
|
11752
|
+
if (arguments.length === 1) return _obj => prop(searchProperty, _obj)
|
|
11753
|
+
|
|
11754
|
+
return propFn(searchProperty, obj)
|
|
11923
11755
|
}
|
|
11924
11756
|
```
|
|
11925
11757
|
|
|
@@ -12650,6 +12482,12 @@ describe('R.range', () => {
|
|
|
12650
12482
|
|
|
12651
12483
|
[](#reduce)
|
|
12652
12484
|
|
|
12485
|
+
### reduceBy
|
|
12486
|
+
|
|
12487
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.reduceBy(%0A%20%20(acc%2C%20elem)%20%3D%3E%20acc%20%2B%20elem%2C%0A%20%200%2C%0A%20%20x%20%3D%3E%20x%20%3E%202%20%3F%20'big'%20%3A%20'small'%2C%0A%20%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%0A)%0A%2F%2F%20%3D%3E%20%7B%20big%3A%2012%2C%20small%3A%203%20%7D">Try this <strong>R.reduceBy</strong> example in Rambda REPL</a>
|
|
12488
|
+
|
|
12489
|
+
[](#reduceBy)
|
|
12490
|
+
|
|
12653
12491
|
### reject
|
|
12654
12492
|
|
|
12655
12493
|
```typescript
|
|
@@ -13169,7 +13007,10 @@ describe('R.reverse', () => {
|
|
|
13169
13007
|
|
|
13170
13008
|
```typescript
|
|
13171
13009
|
|
|
13172
|
-
set<
|
|
13010
|
+
set<S, A>(lens: Lens<S, A>): {
|
|
13011
|
+
(a: A): (obj: S) => S
|
|
13012
|
+
(a: A, obj: S): S
|
|
13013
|
+
}
|
|
13173
13014
|
```
|
|
13174
13015
|
|
|
13175
13016
|
It returns a copied **Object** or **Array** with modified `lens` focus set to `replacer` value.
|
|
@@ -13181,9 +13022,12 @@ It returns a copied **Object** or **Array** with modified `lens` focus set to `r
|
|
|
13181
13022
|
<summary>All TypeScript definitions</summary>
|
|
13182
13023
|
|
|
13183
13024
|
```typescript
|
|
13184
|
-
set<
|
|
13185
|
-
|
|
13186
|
-
|
|
13025
|
+
set<S, A>(lens: Lens<S, A>): {
|
|
13026
|
+
(a: A): (obj: S) => S
|
|
13027
|
+
(a: A, obj: S): S
|
|
13028
|
+
};
|
|
13029
|
+
set<S, A>(lens: Lens<S, A>, a: A): (obj: S) => S;
|
|
13030
|
+
set<S, A>(lens: Lens<S, A>, a: A, obj: S): S;
|
|
13187
13031
|
```
|
|
13188
13032
|
|
|
13189
13033
|
</details>
|
|
@@ -13599,6 +13443,12 @@ describe('R.sortBy', () => {
|
|
|
13599
13443
|
|
|
13600
13444
|
[](#sortBy)
|
|
13601
13445
|
|
|
13446
|
+
### sortWith
|
|
13447
|
+
|
|
13448
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.sortWith(%5B%0A%20%20%20%20(a%2C%20b)%20%3D%3E%20a.a%20%3D%3D%3D%20b.a%20%3F%200%20%3A%20a.a%20%3E%20b.a%20%3F%201%20%3A%20-1%2C%0A%20%20%20%20(a%2C%20b)%20%3D%3E%20a.b%20%3D%3D%3D%20b.b%20%3F%200%20%3A%20a.b%20%3E%20b.b%20%3F%201%20%3A%20-1%2C%0A%5D%2C%20%5B%0A%20%20%7Ba%3A%201%2C%20b%3A%202%7D%2C%0A%20%20%7Ba%3A%202%2C%20b%3A%201%7D%2C%0A%20%20%7Ba%3A%202%2C%20b%3A%202%7D%2C%0A%20%20%7Ba%3A%201%2C%20b%3A%201%7D%2C%0A%5D)%0Aconst%20expected%20%3D%20%5B%0A%20%20%7Ba%3A%201%2C%20b%3A%201%7D%2C%0A%20%20%7Ba%3A%201%2C%20b%3A%202%7D%2C%0A%20%20%7Ba%3A%202%2C%20b%3A%201%7D%2C%0A%20%20%7Ba%3A%202%2C%20b%3A%202%7D%2C%0A%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.sortWith</strong> example in Rambda REPL</a>
|
|
13449
|
+
|
|
13450
|
+
[](#sortWith)
|
|
13451
|
+
|
|
13602
13452
|
### split
|
|
13603
13453
|
|
|
13604
13454
|
```typescript
|
|
@@ -16204,6 +16054,8 @@ describe('R.unless - curried', () => {
|
|
|
16204
16054
|
|
|
16205
16055
|
### unnest
|
|
16206
16056
|
|
|
16057
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.unnest(%5B1%2C%20%5B2%5D%2C%20%5B%5B3%5D%5D%5D)%0A%2F%2F%20%3D%3E%20%5B1%2C%202%2C%20%5B3%5D%5D">Try this <strong>R.unnest</strong> example in Rambda REPL</a>
|
|
16058
|
+
|
|
16207
16059
|
[](#unnest)
|
|
16208
16060
|
|
|
16209
16061
|
### unwind
|
|
@@ -16362,7 +16214,6 @@ import { type } from './type.js'
|
|
|
16362
16214
|
|
|
16363
16215
|
export function values(obj){
|
|
16364
16216
|
if (type(obj) !== 'Object') return []
|
|
16365
|
-
|
|
16366
16217
|
return Object.values(obj)
|
|
16367
16218
|
}
|
|
16368
16219
|
```
|
|
@@ -16426,7 +16277,7 @@ describe('R.values', () => {
|
|
|
16426
16277
|
|
|
16427
16278
|
```typescript
|
|
16428
16279
|
|
|
16429
|
-
view<
|
|
16280
|
+
view<S, A>(lens: Lens<S, A>): (obj: S) => A
|
|
16430
16281
|
```
|
|
16431
16282
|
|
|
16432
16283
|
It returns the value of `lens` focus over `target` object.
|
|
@@ -16438,8 +16289,8 @@ It returns the value of `lens` focus over `target` object.
|
|
|
16438
16289
|
<summary>All TypeScript definitions</summary>
|
|
16439
16290
|
|
|
16440
16291
|
```typescript
|
|
16441
|
-
view<
|
|
16442
|
-
view<
|
|
16292
|
+
view<S, A>(lens: Lens<S, A>): (obj: S) => A;
|
|
16293
|
+
view<S, A>(lens: Lens<S, A>, obj: S): A;
|
|
16443
16294
|
```
|
|
16444
16295
|
|
|
16445
16296
|
</details>
|
|
@@ -16483,35 +16334,6 @@ test('happy', () => {
|
|
|
16483
16334
|
|
|
16484
16335
|
</details>
|
|
16485
16336
|
|
|
16486
|
-
<details>
|
|
16487
|
-
|
|
16488
|
-
<summary><strong>TypeScript</strong> test</summary>
|
|
16489
|
-
|
|
16490
|
-
```typescript
|
|
16491
|
-
import {lens, view, assoc} from 'rambda'
|
|
16492
|
-
|
|
16493
|
-
interface Input {
|
|
16494
|
-
foo: string,
|
|
16495
|
-
}
|
|
16496
|
-
|
|
16497
|
-
const testObject: Input = {
|
|
16498
|
-
foo: 'Led Zeppelin',
|
|
16499
|
-
}
|
|
16500
|
-
|
|
16501
|
-
const fooLens = lens<Input, string, string>((x: Input) => {
|
|
16502
|
-
return x.foo
|
|
16503
|
-
}, assoc('foo'))
|
|
16504
|
-
|
|
16505
|
-
describe('R.view', () => {
|
|
16506
|
-
it('happt', () => {
|
|
16507
|
-
const result = view<Input, string>(fooLens, testObject)
|
|
16508
|
-
result // $ExpectType string
|
|
16509
|
-
})
|
|
16510
|
-
})
|
|
16511
|
-
```
|
|
16512
|
-
|
|
16513
|
-
</details>
|
|
16514
|
-
|
|
16515
16337
|
[](#view)
|
|
16516
16338
|
|
|
16517
16339
|
### when
|
|
@@ -16521,6 +16343,11 @@ describe('R.view', () => {
|
|
|
16521
16343
|
when<T, U>(predicate: (x: T) => boolean, whenTrueFn: (a: T) => U, input: T): T | U
|
|
16522
16344
|
```
|
|
16523
16345
|
|
|
16346
|
+
It pass `input` to `predicate` function and if the result is `true`, it will return the result of `whenTrueFn(input)`.
|
|
16347
|
+
If the `predicate` returns `false`, then it will simply return `input`.
|
|
16348
|
+
|
|
16349
|
+
<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%20whenTrueFn%20%3D%20R.add(11)%0A%0Aconst%20fn%20%3D%20when(predicate%2C%20whenTrueResult)%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(positiveInput)%2C%0A%5D%0A%0Aconst%20expected%20%3D%20%5B%0A%20%2099%2C%0A%20%20'foo'%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>
|
|
16350
|
+
|
|
16524
16351
|
<details>
|
|
16525
16352
|
|
|
16526
16353
|
<summary>All TypeScript definitions</summary>
|
|
@@ -17423,12 +17250,22 @@ describe('R.zipWith', () => {
|
|
|
17423
17250
|
|
|
17424
17251
|
## ❯ CHANGELOG
|
|
17425
17252
|
|
|
17253
|
+
9.0.1
|
|
17254
|
+
|
|
17255
|
+
- Fix bad TS typings, due to missing declaration - [Issue #716](https://github.com/selfrefactor/rambda/issues/716)
|
|
17256
|
+
|
|
17257
|
+
9.0.0
|
|
17258
|
+
|
|
17259
|
+
Breaking change in TS definitions of `lenses` as now they are synced to `Ramda` types.
|
|
17260
|
+
|
|
17261
|
+
- Add `R.sortWith` - [Issue #707](https://github.com/selfrefactor/rambda/issues/707)
|
|
17262
|
+
|
|
17263
|
+
- Add `R.innerJoin`, `R.gt`, `R.gte`, `R.reduceBy`, `R.hasIn`
|
|
17264
|
+
|
|
17426
17265
|
8.6.0
|
|
17427
17266
|
|
|
17428
17267
|
- Wrong typing for `R.dissocPath` - [Issue #709](https://github.com/selfrefactor/rambda/issues/709)
|
|
17429
17268
|
|
|
17430
|
-
- Add `R.sortWith` - [Issue #7097](https://github.com/selfrefactor/rambda/issues/707)
|
|
17431
|
-
|
|
17432
17269
|
- Update build dependencies
|
|
17433
17270
|
|
|
17434
17271
|
8.5.0
|