rambda 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -96,7 +96,7 @@ Closing the issue is usually accompanied by publishing a new patch version of `R
96
96
 
97
97
  <details>
98
98
  <summary>
99
- Click to see the full list of 80 Ramda methods not implemented in Rambda
99
+ Click to see the full list of 79 Ramda methods not implemented in Rambda
100
100
  </summary>
101
101
 
102
102
  - __
@@ -114,7 +114,6 @@ Closing the issue is usually accompanied by publishing a new patch version of `R
114
114
  - construct
115
115
  - constructN
116
116
  - descend
117
- - differenceWith
118
117
  - dissocPath
119
118
  - dropRepeatsBy
120
119
  - empty
@@ -350,7 +349,7 @@ adjust<T>(index: number, replaceFn: (x: T) => T, list: T[]): T[]
350
349
 
351
350
  It replaces `index` in array `list` with the result of `replaceFn(list[i])`.
352
351
 
353
- <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?R.adjust(%0A%20%200%2C%0A%20%20a%20%3D%3E%20a%20%2B%201%2C%0A%20%20%5B0%2C%20100%5D%0Aconst%20result%20%3D%20)%20%2F%2F%20%3D%3E%20%5B1%2C%20100%5D">Try this <strong>R.adjust</strong> example in Rambda REPL</a>
352
+ <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.adjust(%0A%20%200%2C%0A%20%20a%20%3D%3E%20a%20%2B%201%2C%0A%20%20%5B0%2C%20100%5D%0A)%20%2F%2F%20%3D%3E%20%5B1%2C%20100%5D">Try this <strong>R.adjust</strong> example in Rambda REPL</a>
354
353
 
355
354
  <details>
356
355
 
@@ -1092,7 +1091,7 @@ test('applies function to argument list', () => {
1092
1091
 
1093
1092
  test('provides no way to specify context', () => {
1094
1093
  const obj = {
1095
- method : function (){
1094
+ method (){
1096
1095
  return this === obj
1097
1096
  },
1098
1097
  }
@@ -1683,6 +1682,22 @@ test('string can be used as path input', () => {
1683
1682
  expect(result).toEqual(expected)
1684
1683
  })
1685
1684
 
1685
+ test('difference with ramda - doesn\'t overwrite primitive values with keys in the path', () => {
1686
+ const obj = { a : 'str' }
1687
+ const result = assocPath(
1688
+ [ 'a', 'b' ], 42, obj
1689
+ )
1690
+
1691
+ expect(result).toEqual({
1692
+ a : {
1693
+ 0 : 's',
1694
+ 1 : 't',
1695
+ 2 : 'r',
1696
+ b : 42,
1697
+ },
1698
+ })
1699
+ })
1700
+
1686
1701
  test('bug', () => {
1687
1702
  /*
1688
1703
  https://github.com/selfrefactor/rambda/issues/524
@@ -2717,6 +2732,91 @@ describe('R.difference', () => {
2717
2732
 
2718
2733
  [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#difference)
2719
2734
 
2735
+ ### differenceWith
2736
+
2737
+ ```typescript
2738
+
2739
+ differenceWith<T1, T2>(
2740
+ pred: (a: T1, b: T2) => boolean,
2741
+ list1: T1[],
2742
+ list2: T2[],
2743
+ ): T1[]
2744
+ ```
2745
+
2746
+ <details>
2747
+
2748
+ <summary>All Typescript definitions</summary>
2749
+
2750
+ ```typescript
2751
+ differenceWith<T1, T2>(
2752
+ pred: (a: T1, b: T2) => boolean,
2753
+ list1: T1[],
2754
+ list2: T2[],
2755
+ ): T1[];
2756
+ differenceWith<T1, T2>(
2757
+ pred: (a: T1, b: T2) => boolean,
2758
+ ): (list1: T1[], list2: T2[]) => T1[];
2759
+ differenceWith<T1, T2>(
2760
+ pred: (a: T1, b: T2) => boolean,
2761
+ list1: T1[],
2762
+ ): (list2: T2[]) => T1[];
2763
+ ```
2764
+
2765
+ </details>
2766
+
2767
+ <details>
2768
+
2769
+ <summary><strong>R.differenceWith</strong> source</summary>
2770
+
2771
+ ```javascript
2772
+ import { curry } from './curry.js'
2773
+ import { _indexOf } from './equals.js'
2774
+
2775
+ export function differenceWithFn(
2776
+ fn, a, b
2777
+ ){
2778
+ const willReturn = []
2779
+ const [ first, second ] = a.length > b.length ? [ a, b ] : [ b, a ]
2780
+
2781
+ first.forEach(item => {
2782
+ const hasItem = second.some(secondItem => fn(item, secondItem))
2783
+ if (!hasItem && _indexOf(item, willReturn) === -1){
2784
+ willReturn.push(item)
2785
+ }
2786
+ })
2787
+
2788
+ return willReturn
2789
+ }
2790
+
2791
+ export const differenceWith = curry(differenceWithFn)
2792
+ ```
2793
+
2794
+ </details>
2795
+
2796
+ <details>
2797
+
2798
+ <summary><strong>Tests</strong></summary>
2799
+
2800
+ ```javascript
2801
+ import { differenceWith } from './differenceWith.js'
2802
+
2803
+ test('happy', () => {
2804
+ const foo = [ { a : 1 }, { a : 2 }, { a : 3 } ]
2805
+ const bar = [ { a : 3 }, { a : 4 } ]
2806
+ const fn = function (r, s){
2807
+ return r.a === s.a
2808
+ }
2809
+ const result = differenceWith(
2810
+ fn, foo, bar
2811
+ )
2812
+ expect(result).toEqual([ { a : 1 }, { a : 2 } ])
2813
+ })
2814
+ ```
2815
+
2816
+ </details>
2817
+
2818
+ [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#differenceWith)
2819
+
2720
2820
  ### dissoc
2721
2821
 
2722
2822
  It returns a new object that does not contain property `prop`.
@@ -3257,7 +3357,7 @@ describe('R.either', () => {
3257
3357
 
3258
3358
  ```typescript
3259
3359
 
3260
- endsWith(target: string, iterable: string): boolean
3360
+ endsWith<T extends string>(question: T, str: string): boolean
3261
3361
  ```
3262
3362
 
3263
3363
  When iterable is a string, then it behaves as `String.prototype.endsWith`.
@@ -3270,10 +3370,10 @@ When iterable is a list, then it uses R.equals to determine if the target list e
3270
3370
  <summary>All Typescript definitions</summary>
3271
3371
 
3272
3372
  ```typescript
3273
- endsWith(target: string, iterable: string): boolean;
3274
- endsWith(target: string): (iterable: string) => boolean;
3275
- endsWith<T>(target: T[], list: T[]): boolean;
3276
- endsWith<T>(target: T[]): (list: T[]) => boolean;
3373
+ endsWith<T extends string>(question: T, str: string): boolean;
3374
+ endsWith<T extends string>(question: T): (str: string) => boolean;
3375
+ endsWith<T>(question: T[], list: T[]): boolean;
3376
+ endsWith<T>(question: T[]): (list: T[]) => boolean;
3277
3377
  ```
3278
3378
 
3279
3379
  </details>
@@ -3383,32 +3483,28 @@ describe('brute force', () => {
3383
3483
  ```typescript
3384
3484
  import {endsWith} from 'rambda'
3385
3485
 
3386
- describe('R.endsWith - array as iterable', () => {
3486
+ describe('R.endsWith - array', () => {
3387
3487
  const target = [{a: 2}]
3388
- const iterable = [{a: 1}, {a: 2}]
3488
+ const input = [{a: 1}, {a: 2}]
3389
3489
  it('happy', () => {
3390
- const result = endsWith(target, iterable)
3391
-
3490
+ const result = endsWith(target, input)
3392
3491
  result // $ExpectType boolean
3393
3492
  })
3394
3493
  it('curried', () => {
3395
- const result = endsWith(target)(iterable)
3396
-
3494
+ const result = endsWith(target)(input)
3397
3495
  result // $ExpectType boolean
3398
3496
  })
3399
3497
  })
3400
3498
 
3401
- describe('R.endsWith - string as iterable', () => {
3499
+ describe('R.endsWith - string', () => {
3402
3500
  const target = 'bar'
3403
- const iterable = 'foo bar'
3501
+ const input = 'foo bar'
3404
3502
  it('happy', () => {
3405
- const result = endsWith(target, iterable)
3406
-
3503
+ const result = endsWith(target, input)
3407
3504
  result // $ExpectType boolean
3408
3505
  })
3409
3506
  it('curried', () => {
3410
- const result = endsWith(target)(iterable)
3411
-
3507
+ const result = endsWith(target)(input)
3412
3508
  result // $ExpectType boolean
3413
3509
  })
3414
3510
  })
@@ -4557,12 +4653,12 @@ import { propEq } from './propEq.js'
4557
4653
  const list = [ { a : 1 }, { a : 2 }, { a : 3 } ]
4558
4654
 
4559
4655
  test('happy', () => {
4560
- const fn = propEq('a', 2)
4656
+ const fn = propEq(2, 'a')
4561
4657
  expect(find(fn, list)).toEqual({ a : 2 })
4562
4658
  })
4563
4659
 
4564
4660
  test('with curry', () => {
4565
- const fn = propEq('a', 4)
4661
+ const fn = propEq(4, 'a')
4566
4662
  expect(find(fn)(list)).toBeUndefined()
4567
4663
  })
4568
4664
 
@@ -4658,11 +4754,9 @@ import { propEq } from './propEq.js'
4658
4754
  const list = [ { a : 1 }, { a : 2 }, { a : 3 } ]
4659
4755
 
4660
4756
  test('happy', () => {
4661
- expect(findIndex(propEq('a', 2), list)).toBe(1)
4662
-
4663
- expect(findIndex(propEq('a', 1))(list)).toBe(0)
4664
-
4665
- expect(findIndex(propEq('a', 4))(list)).toEqual(-1)
4757
+ expect(findIndex(propEq(2, 'a'), list)).toBe(1)
4758
+ expect(findIndex(propEq(1, 'a'))(list)).toBe(0)
4759
+ expect(findIndex(propEq(4, 'a'))(list)).toBe(-1)
4666
4760
  })
4667
4761
  ```
4668
4762
 
@@ -4913,7 +5007,7 @@ test('ramda 1', () => {
4913
5007
  })
4914
5008
 
4915
5009
  test('ramda 2', () => {
4916
- expect(findLastIndex(even, [ 'zing' ])).toEqual(-1)
5010
+ expect(findLastIndex(even, [ 'zing' ])).toBe(-1)
4917
5011
  })
4918
5012
 
4919
5013
  test('ramda 3', () => {
@@ -4921,7 +5015,7 @@ test('ramda 3', () => {
4921
5015
  })
4922
5016
 
4923
5017
  test('ramda 4', () => {
4924
- expect(findLastIndex(even, [])).toEqual(-1)
5018
+ expect(findLastIndex(even, [])).toBe(-1)
4925
5019
  })
4926
5020
  ```
4927
5021
 
@@ -5474,7 +5568,7 @@ It returns the first element of list or string `input`.
5474
5568
  ```typescript
5475
5569
  head(input: string): string;
5476
5570
  head(emptyList: []): undefined;
5477
- head<T>(input: T[]): T | undefined;
5571
+ head<T extends readonly unknown[]>(array: T): FirstArrayElement<T>
5478
5572
  ```
5479
5573
 
5480
5574
  </details>
@@ -5515,6 +5609,7 @@ test('head', () => {
5515
5609
  <summary><strong>Typescript</strong> test</summary>
5516
5610
 
5517
5611
  ```typescript
5612
+ import {mixedList, mixedListConst} from '_internals/typescriptTestUtils'
5518
5613
  import {head} from 'rambda'
5519
5614
 
5520
5615
  describe('R.head', () => {
@@ -5522,12 +5617,18 @@ describe('R.head', () => {
5522
5617
  const result = head('foo')
5523
5618
  result // $ExpectType string
5524
5619
  })
5525
-
5526
5620
  it('array', () => {
5527
5621
  const result = head([1, 2, 3])
5528
- result // $ExpectType number | undefined
5622
+ result // $ExpectType number
5623
+ })
5624
+ it('mixed', () => {
5625
+ const result = head(mixedList)
5626
+ result // $ExpectType string | number
5627
+ })
5628
+ it('mixed const', () => {
5629
+ const result = head(mixedListConst)
5630
+ result // $ExpectType 1
5529
5631
  })
5530
-
5531
5632
  it('empty array - case 1', () => {
5532
5633
  const result = head([])
5533
5634
  result // $ExpectType undefined
@@ -5535,7 +5636,7 @@ describe('R.head', () => {
5535
5636
  it('empty array - case 2', () => {
5536
5637
  const list = ['foo', 'bar'].filter(x => x.startsWith('a'))
5537
5638
  const result = head(list)
5538
- result // $ExpectType string | undefined
5639
+ result // $ExpectType string
5539
5640
  })
5540
5641
  })
5541
5642
  ```
@@ -5846,7 +5947,7 @@ It increments a number.
5846
5947
 
5847
5948
  ```typescript
5848
5949
 
5849
- includes(valueToFind: string, input: string[] | string): boolean
5950
+ includes<T extends string>(valueToFind: T, input: string): boolean
5850
5951
  ```
5851
5952
 
5852
5953
  If `input` is string, then this method work as native `String.includes`.
@@ -5860,8 +5961,8 @@ If `input` is array, then `R.equals` is used to define if `valueToFind` belongs
5860
5961
  <summary>All Typescript definitions</summary>
5861
5962
 
5862
5963
  ```typescript
5863
- includes(valueToFind: string, input: string[] | string): boolean;
5864
- includes(valueToFind: string): (input: string[] | string) => boolean;
5964
+ includes<T extends string>(valueToFind: T, input: string): boolean;
5965
+ includes<T extends string>(valueToFind: T): (input: string) => boolean;
5865
5966
  includes<T>(valueToFind: T, input: T[]): boolean;
5866
5967
  includes<T>(valueToFind: T): (input: T[]) => boolean;
5867
5968
  ```
@@ -5969,10 +6070,13 @@ describe('R.includes', () => {
5969
6070
  it('happy', () => {
5970
6071
  const result = includes({a: {b: '1'}}, list)
5971
6072
  result // $ExpectType boolean
6073
+ const result2 = includes('oo', ['f', 'oo'])
6074
+ result2 // $ExpectType boolean
5972
6075
  })
5973
6076
  it('with string', () => {
5974
- const result = includes('oo', 'foo')
5975
- const curriedResult = includes('oo')('foo')
6077
+ const str = 'foo' as 'foo' | 'bar'
6078
+ const result = includes('oo', str)
6079
+ const curriedResult = includes('oo')(str)
5976
6080
 
5977
6081
  result // $ExpectType boolean
5978
6082
  curriedResult // $ExpectType boolean
@@ -6496,7 +6600,7 @@ describe('R.keys', () => {
6496
6600
 
6497
6601
  ```typescript
6498
6602
 
6499
- last(str: string): string
6603
+ last(input: string): string
6500
6604
  ```
6501
6605
 
6502
6606
  It returns the last element of `input`, as the `input` can be either a string or an array.
@@ -6508,9 +6612,9 @@ It returns the last element of `input`, as the `input` can be either a string or
6508
6612
  <summary>All Typescript definitions</summary>
6509
6613
 
6510
6614
  ```typescript
6511
- last(str: string): string;
6615
+ last(input: string): string;
6512
6616
  last(emptyList: []): undefined;
6513
- last<T extends any>(list: T[]): T | undefined;
6617
+ last<T extends readonly unknown[]>(array: T): LastArrayElement<T>
6514
6618
  ```
6515
6619
 
6516
6620
  </details>
@@ -6556,6 +6660,7 @@ test('with string', () => {
6556
6660
  <summary><strong>Typescript</strong> test</summary>
6557
6661
 
6558
6662
  ```typescript
6663
+ import {mixedList, mixedListConst} from '_internals/typescriptTestUtils'
6559
6664
  import {last} from 'rambda'
6560
6665
 
6561
6666
  describe('R.last', () => {
@@ -6563,12 +6668,18 @@ describe('R.last', () => {
6563
6668
  const result = last('foo')
6564
6669
  result // $ExpectType string
6565
6670
  })
6566
-
6567
6671
  it('array', () => {
6568
6672
  const result = last([1, 2, 3])
6569
- result // $ExpectType number | undefined
6673
+ result // $ExpectType number
6674
+ })
6675
+ it('mixed', () => {
6676
+ const result = last(mixedList)
6677
+ result // $ExpectType string | number
6678
+ })
6679
+ it('mixed const', () => {
6680
+ const result = last(mixedListConst)
6681
+ result // $ExpectType "bar"
6570
6682
  })
6571
-
6572
6683
  it('empty array - case 1', () => {
6573
6684
  const result = last([])
6574
6685
  result // $ExpectType undefined
@@ -6576,7 +6687,7 @@ describe('R.last', () => {
6576
6687
  it('empty array - case 2', () => {
6577
6688
  const list = ['foo', 'bar'].filter(x => x.startsWith('a'))
6578
6689
  const result = last(list)
6579
- result // $ExpectType string | undefined
6690
+ result // $ExpectType string
6580
6691
  })
6581
6692
  })
6582
6693
  ```
@@ -6645,13 +6756,13 @@ test('with NaN', () => {
6645
6756
  })
6646
6757
 
6647
6758
  test('will throw with bad input', () => {
6648
- expect(lastIndexOfRamda([], true)).toEqual(-1)
6759
+ expect(lastIndexOfRamda([], true)).toBe(-1)
6649
6760
  expect(() => indexOf([], true)).toThrowErrorMatchingInlineSnapshot('"indexOf is not defined"')
6650
6761
  })
6651
6762
 
6652
6763
  test('without list of objects - no R.equals', () => {
6653
6764
  expect(lastIndexOf(3, [ 1, 2, 3, 4 ])).toBe(2)
6654
- expect(lastIndexOf(10)([ 1, 2, 3, 4 ])).toEqual(-1)
6765
+ expect(lastIndexOf(10)([ 1, 2, 3, 4 ])).toBe(-1)
6655
6766
  })
6656
6767
 
6657
6768
  test('list of objects uses R.equals', () => {
@@ -8053,6 +8164,29 @@ test('case 2', () => {
8053
8164
  baz : 3,
8054
8165
  })
8055
8166
  })
8167
+
8168
+ describe('acts as if nil values are simply empty objects', () => {
8169
+ it('if the first object is nil', () => {
8170
+ expect(mergeAll([ null, { foo : 1 }, { foo : 2 }, { bar : 2 } ])).toEqual({
8171
+ foo : 2,
8172
+ bar : 2,
8173
+ })
8174
+ })
8175
+
8176
+ it('if the last object is nil', () => {
8177
+ expect(mergeAll([ { foo : 1 }, { foo : 2 }, { bar : 2 }, undefined ])).toEqual({
8178
+ foo : 2,
8179
+ bar : 2,
8180
+ })
8181
+ })
8182
+
8183
+ it('if an intermediate object is nil', () => {
8184
+ expect(mergeAll([ { foo : 1 }, { foo : 2 }, null, { bar : 2 } ])).toEqual({
8185
+ foo : 2,
8186
+ bar : 2,
8187
+ })
8188
+ })
8189
+ })
8056
8190
  ```
8057
8191
 
8058
8192
  </details>
@@ -8444,8 +8578,10 @@ mergeWith<Output>(fn: (x: any, z: any) => any): <U, V>(a: U, b: V) => Output;
8444
8578
  import { curry } from './curry.js'
8445
8579
 
8446
8580
  function mergeWithFn(
8447
- mergeFn, a, b
8581
+ mergeFn, aInput, bInput
8448
8582
  ){
8583
+ const a = aInput ?? {}
8584
+ const b = bInput ?? {}
8449
8585
  const willReturn = {}
8450
8586
 
8451
8587
  Object.keys(a).forEach(key => {
@@ -8501,6 +8637,39 @@ test('happy', () => {
8501
8637
  }
8502
8638
  expect(result).toEqual(expected)
8503
8639
  })
8640
+
8641
+ // https://github.com/ramda/ramda/pull/3222/files#diff-d925d9188b478d2f1d4b26012c6dddac374f9e9d7a336604d654b9a113bfc857
8642
+ describe('acts as if nil values are simply empty objects', () => {
8643
+ it('if the first object is nil and the second empty', () => {
8644
+ expect(mergeWith(
8645
+ concat, undefined, {}
8646
+ )).toEqual({})
8647
+ })
8648
+
8649
+ it('if the first object is empty and the second nil', () => {
8650
+ expect(mergeWith(
8651
+ concat, {}, null
8652
+ )).toEqual({})
8653
+ })
8654
+
8655
+ it('if both objects are nil', () => {
8656
+ expect(mergeWith(
8657
+ concat, undefined, null
8658
+ )).toEqual({})
8659
+ })
8660
+
8661
+ it('if the first object is not empty and the second is nil', () => {
8662
+ expect(mergeWith(
8663
+ concat, { a : 'a' }, null
8664
+ )).toEqual({ a : 'a' })
8665
+ })
8666
+
8667
+ it('if the first object is nil and the second is not empty', () => {
8668
+ expect(mergeWith(
8669
+ concat, undefined, { a : 'a' }
8670
+ )).toEqual({ a : 'a' })
8671
+ })
8672
+ })
8504
8673
  ```
8505
8674
 
8506
8675
  </details>
@@ -9004,70 +9173,6 @@ describe('R.none', () => {
9004
9173
 
9005
9174
  [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#none)
9006
9175
 
9007
- ### nop
9008
-
9009
- ```typescript
9010
-
9011
- nop(): void
9012
- ```
9013
-
9014
- It returns `undefined`.
9015
-
9016
- <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.nop()%0A%2F%2F%20%3D%3E%20undefined">Try this <strong>R.nop</strong> example in Rambda REPL</a>
9017
-
9018
- <details>
9019
-
9020
- <summary>All Typescript definitions</summary>
9021
-
9022
- ```typescript
9023
- nop(): void;
9024
- ```
9025
-
9026
- </details>
9027
-
9028
- <details>
9029
-
9030
- <summary><strong>R.nop</strong> source</summary>
9031
-
9032
- ```javascript
9033
- export function nop(){}
9034
- ```
9035
-
9036
- </details>
9037
-
9038
- <details>
9039
-
9040
- <summary><strong>Tests</strong></summary>
9041
-
9042
- ```javascript
9043
- import { nop } from './nop.js'
9044
-
9045
- test('call', () => {
9046
- expect(nop).not.toThrow()
9047
- })
9048
- ```
9049
-
9050
- </details>
9051
-
9052
- <details>
9053
-
9054
- <summary><strong>Typescript</strong> test</summary>
9055
-
9056
- ```typescript
9057
- import {nop} from 'rambda'
9058
-
9059
- describe('R.nop', () => {
9060
- it('call', () => {
9061
- const result = nop()
9062
- result // $ExpectType void
9063
- })
9064
- })
9065
- ```
9066
-
9067
- </details>
9068
-
9069
- [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#nop)
9070
-
9071
9176
  ### not
9072
9177
 
9073
9178
  ```typescript
@@ -10356,12 +10461,7 @@ path<T>(pathToSearch: RamdaPath, obj: any): T | undefined;
10356
10461
  ```javascript
10357
10462
  import { createPath } from './_internals/createPath.js'
10358
10463
 
10359
- export function path(pathInput, obj){
10360
- if (arguments.length === 1) return _obj => path(pathInput, _obj)
10361
-
10362
- if (obj === null || obj === undefined){
10363
- return undefined
10364
- }
10464
+ export function pathFn(pathInput, obj){
10365
10465
  let willReturn = obj
10366
10466
  let counter = 0
10367
10467
 
@@ -10379,6 +10479,16 @@ export function path(pathInput, obj){
10379
10479
 
10380
10480
  return willReturn
10381
10481
  }
10482
+
10483
+ export function path(pathInput, obj){
10484
+ if (arguments.length === 1) return _obj => path(pathInput, _obj)
10485
+
10486
+ if (obj === null || obj === undefined){
10487
+ return undefined
10488
+ }
10489
+
10490
+ return pathFn(pathInput, obj)
10491
+ }
10382
10492
  ```
10383
10493
 
10384
10494
  </details>
@@ -11633,46 +11743,30 @@ test('prop', () => {
11633
11743
  <summary><strong>Typescript</strong> test</summary>
11634
11744
 
11635
11745
  ```typescript
11636
- import {pipe, prop} from 'rambda'
11746
+ import {prop} from 'rambda'
11637
11747
 
11638
11748
  describe('R.prop', () => {
11639
- const obj = {a: 1, b: 'foo'}
11640
- interface Something {
11641
- a?: number,
11642
- b?: string,
11749
+ interface Foo {
11750
+ a: number,
11751
+ b: string,
11752
+ c?: number,
11643
11753
  }
11754
+ const obj: Foo = {a: 1, b: 'foo'}
11644
11755
 
11645
11756
  it('issue #553', () => {
11646
- const result = prop('e', {e: 'test1', d: 'test2'})
11647
- const curriedResult = prop<string>('e')({e: 'test1', d: 'test2'})
11648
-
11649
- result // $ExpectType string
11650
- curriedResult // $ExpectType string
11651
- })
11652
- it('happy', () => {
11653
- const result = prop('a', obj)
11654
-
11655
- result // $ExpectType number
11656
- })
11657
- it('curried', () => {
11658
- const result = prop('b')(obj)
11659
-
11660
- result // $ExpectType string
11661
- })
11662
- it('curried with explicit object type', () => {
11663
- const result = prop<'a', Something>('a')(obj)
11664
-
11665
- result // $ExpectType number | undefined
11666
- })
11667
- it('curried with implicit object type', () => {
11668
- const result = pipe(value => value as Something, prop('b'))(obj)
11757
+ const result = {
11758
+ a: prop('a', obj),
11759
+ b: prop('b', obj),
11760
+ c: prop('c', obj),
11761
+ }
11762
+ const curriedResult = {
11763
+ a: prop('a')(obj),
11764
+ b: prop('b')(obj),
11765
+ c: prop('c')(obj),
11766
+ }
11669
11767
 
11670
- result // $ExpectType undefined
11671
- })
11672
- it('curried with explicit result type', () => {
11673
- const result = prop<'b', string>('b')(obj)
11674
-
11675
- result // $ExpectType string
11768
+ result // $ExpectType { a: number; b: string; c: number | undefined; }
11769
+ curriedResult // $ExpectType { a: number; b: string; c: number | undefined; }
11676
11770
  })
11677
11771
  })
11678
11772
 
@@ -11700,7 +11794,7 @@ describe('with number as prop', () => {
11700
11794
 
11701
11795
  ```typescript
11702
11796
 
11703
- propEq<K extends string | number>(propToFind: K, valueToMatch: any, obj: Record<K, any>): boolean
11797
+ propEq<K extends string | number>(valueToMatch: any, propToFind: K, obj: Record<K, any>): boolean
11704
11798
  ```
11705
11799
 
11706
11800
  It returns true if `obj` has property `propToFind` and its value is equal to `valueToMatch`.
@@ -11712,11 +11806,11 @@ It returns true if `obj` has property `propToFind` and its value is equal to `va
11712
11806
  <summary>All Typescript definitions</summary>
11713
11807
 
11714
11808
  ```typescript
11715
- propEq<K extends string | number>(propToFind: K, valueToMatch: any, obj: Record<K, any>): boolean;
11716
- propEq<K extends string | number>(propToFind: K, valueToMatch: any): (obj: Record<K, any>) => boolean;
11717
- propEq<K extends string | number>(propToFind: K): {
11718
- (valueToMatch: any, obj: Record<K, any>): boolean;
11719
- (valueToMatch: any): (obj: Record<K, any>) => boolean;
11809
+ propEq<K extends string | number>(valueToMatch: any, propToFind: K, obj: Record<K, any>): boolean;
11810
+ propEq<K extends string | number>(valueToMatch: any, propToFind: K): (obj: Record<K, any>) => boolean;
11811
+ propEq(valueToMatch: any): {
11812
+ <K extends string | number>(propToFind: K, obj: Record<K, any>): boolean;
11813
+ <K extends string | number>(propToFind: K): (obj: Record<K, any>) => boolean;
11720
11814
  };
11721
11815
  ```
11722
11816
 
@@ -11732,7 +11826,7 @@ import { equals } from './equals.js'
11732
11826
  import { prop } from './prop.js'
11733
11827
 
11734
11828
  function propEqFn(
11735
- propToFind, valueToMatch, obj
11829
+ valueToMatch, propToFind, obj
11736
11830
  ){
11737
11831
  if (!obj) return false
11738
11832
 
@@ -11749,14 +11843,16 @@ export const propEq = curry(propEqFn)
11749
11843
  <summary><strong>Tests</strong></summary>
11750
11844
 
11751
11845
  ```javascript
11846
+ import { BAR, FOO } from './_internals/testUtils.js'
11752
11847
  import { propEq } from './propEq.js'
11753
11848
 
11754
11849
  test('happy', () => {
11755
- expect(propEq('foo', 'bar')({ foo : 'bar' })).toBeTrue()
11756
- expect(propEq('foo', 'bar')({ foo : 'baz' })).toBeFalse()
11757
- expect(propEq('foo')('bar')({ foo : 'baz' })).toBeFalse()
11850
+ const obj = { [ FOO ] : BAR }
11851
+ expect(propEq(BAR, FOO)(obj)).toBeTrue()
11852
+ expect(propEq(1, FOO)(obj)).toBeFalse()
11853
+ expect(propEq(1)(FOO)(obj)).toBeFalse()
11758
11854
  expect(propEq(
11759
- 'foo', 'bar', null
11855
+ 1, 1, null
11760
11856
  )).toBeFalse()
11761
11857
  })
11762
11858
 
@@ -11787,12 +11883,12 @@ const objWithNumberIndex = {[numberProperty]: value}
11787
11883
 
11788
11884
  describe('R.propEq', () => {
11789
11885
  it('happy', () => {
11790
- const result = propEq(property, value, obj)
11886
+ const result = propEq(value, property, obj)
11791
11887
  result // $ExpectType boolean
11792
11888
  })
11793
11889
 
11794
11890
  it('number is property', () => {
11795
- const result = propEq(1, value, objWithNumberIndex)
11891
+ const result = propEq(value, 1, objWithNumberIndex)
11796
11892
  result // $ExpectType boolean
11797
11893
  })
11798
11894
 
@@ -11804,10 +11900,7 @@ describe('R.propEq', () => {
11804
11900
  const myObject: MyType = {}
11805
11901
  const valueToFind = '1111'
11806
11902
  // @ts-expect-error
11807
- propEq('optional', valueToFind, myObject)
11808
-
11809
- // @ts-expect-error
11810
- propEq('optional', valueToFind, myObject)
11903
+ propEq(valueToFind, 'optional', myObject)
11811
11904
  })
11812
11905
 
11813
11906
  it('imported from @types/ramda', () => {
@@ -11818,11 +11911,11 @@ describe('R.propEq', () => {
11818
11911
  foo: 'bar',
11819
11912
  }
11820
11913
  const value = ''
11821
- const result = propEq('foo', value)(obj)
11914
+ const result = propEq(value, 'foo')(obj)
11822
11915
  result // $ExpectType boolean
11823
11916
 
11824
11917
  // @ts-expect-error
11825
- propEq('bar', value)(obj)
11918
+ propEq(value, 'bar')(obj)
11826
11919
  })
11827
11920
  })
11828
11921
  ```
@@ -12560,7 +12653,7 @@ describe('R.repeat', () => {
12560
12653
 
12561
12654
  ```typescript
12562
12655
 
12563
- replace(strOrRegex: RegExp | string, replacer: string, str: string): string
12656
+ replace(strOrRegex: RegExp | string, replacer: RegExpReplacer, str: string): string
12564
12657
  ```
12565
12658
 
12566
12659
  It replaces `strOrRegex` found in `str` with `replacer`.
@@ -12572,9 +12665,9 @@ It replaces `strOrRegex` found in `str` with `replacer`.
12572
12665
  <summary>All Typescript definitions</summary>
12573
12666
 
12574
12667
  ```typescript
12575
- replace(strOrRegex: RegExp | string, replacer: string, str: string): string;
12576
- replace(strOrRegex: RegExp | string, replacer: string): (str: string) => string;
12577
- replace(strOrRegex: RegExp | string): (replacer: string) => (str: string) => string;
12668
+ replace(strOrRegex: RegExp | string, replacer: RegExpReplacer, str: string): string;
12669
+ replace(strOrRegex: RegExp | string, replacer: RegExpReplacer): (str: string) => string;
12670
+ replace(strOrRegex: RegExp | string): (replacer: RegExpReplacer) => (str: string) => string;
12578
12671
  ```
12579
12672
 
12580
12673
  </details>
@@ -12606,20 +12699,24 @@ import { replace } from './replace.js'
12606
12699
 
12607
12700
  test('happy', () => {
12608
12701
  expect(replace(
12609
- 'foo', 'yes', 'foo bar baz'
12610
- )).toBe('yes bar baz')
12702
+ /\s/g, '|', 'foo bar baz'
12703
+ )).toBe('foo|bar|baz')
12611
12704
  })
12612
12705
 
12613
- test('1', () => {
12614
- expect(replace(/\s/g)('|')('foo bar baz')).toBe('foo|bar|baz')
12615
- })
12616
-
12617
- test('2', () => {
12618
- expect(replace(/\s/g)('|', 'foo bar baz')).toBe('foo|bar|baz')
12619
- })
12706
+ test('with function as replacer input', () => {
12707
+ expect(replace(
12708
+ /\s/g,
12709
+ (
12710
+ match, offset, str
12711
+ ) => {
12712
+ expect(match).toBe(' ')
12713
+ expect([ 3, 7 ].includes(offset)).toBeTrue()
12714
+ expect(str).toBe('foo bar baz')
12620
12715
 
12621
- test('3', () => {
12622
- expect(replace(/\s/g, '|')('foo bar baz')).toBe('foo|bar|baz')
12716
+ return '|'
12717
+ },
12718
+ 'foo bar baz'
12719
+ )).toBe('foo|bar|baz')
12623
12720
  })
12624
12721
  ```
12625
12722
 
@@ -12644,6 +12741,16 @@ describe('R.replace', () => {
12644
12741
  it('with string as search pattern', () => {
12645
12742
  const result = replace('foo', replacer, str)
12646
12743
 
12744
+ result // $ExpectType string
12745
+ })
12746
+ it('with function as replacer', () => {
12747
+ const result = replace('f(o)o', (m: string, p1: string, offset: number) => {
12748
+ m // $ExpectType string
12749
+ p1 // $ExpectType string
12750
+ offset // $ExpectType number
12751
+ return p1
12752
+ }, str)
12753
+
12647
12754
  result // $ExpectType string
12648
12755
  })
12649
12756
  })
@@ -12657,6 +12764,16 @@ describe('R.replace - curried', () => {
12657
12764
  it('with string as search pattern', () => {
12658
12765
  const result = replace('foo', replacer)(str)
12659
12766
 
12767
+ result // $ExpectType string
12768
+ })
12769
+ it('with function as replacer', () => {
12770
+ const result = replace('f(o)o')((m: string, p1: string, offset: number) => {
12771
+ m // $ExpectType string
12772
+ p1 // $ExpectType string
12773
+ offset // $ExpectType number
12774
+ return p1
12775
+ })(str)
12776
+
12660
12777
  result // $ExpectType string
12661
12778
  })
12662
12779
  })
@@ -12693,10 +12810,9 @@ reverse(input: string): string;
12693
12810
  <summary><strong>R.reverse</strong> source</summary>
12694
12811
 
12695
12812
  ```javascript
12696
- export function reverse(listOrString){
12697
- if (typeof listOrString === 'string'){
12698
- return listOrString.split('').reverse()
12699
- .join('')
12813
+ export function reverse(listOrString) {
12814
+ if (typeof listOrString === 'string') {
12815
+ return listOrString.split('').reverse().join('')
12700
12816
  }
12701
12817
 
12702
12818
  const clone = listOrString.slice()
@@ -12712,22 +12828,22 @@ export function reverse(listOrString){
12712
12828
  <summary><strong>Tests</strong></summary>
12713
12829
 
12714
12830
  ```javascript
12715
- import { reverse } from './reverse.js'
12831
+ import {reverse} from './reverse.js'
12716
12832
 
12717
12833
  test('happy', () => {
12718
- expect(reverse([ 1, 2, 3 ])).toEqual([ 3, 2, 1 ])
12834
+ expect(reverse([1, 2, 3])).toEqual([3, 2, 1])
12719
12835
  })
12720
12836
 
12721
12837
  test('with string', () => {
12722
12838
  expect(reverse('baz')).toBe('zab')
12723
12839
  })
12724
12840
 
12725
- test('it doesn\'t mutate', () => {
12726
- const arr = [ 1, 2, 3 ]
12841
+ test("it doesn't mutate", () => {
12842
+ const arr = [1, 2, 3]
12727
12843
 
12728
- expect(reverse(arr)).toEqual([ 3, 2, 1 ])
12844
+ expect(reverse(arr)).toEqual([3, 2, 1])
12729
12845
 
12730
- expect(arr).toEqual([ 1, 2, 3 ])
12846
+ expect(arr).toEqual([1, 2, 3])
12731
12847
  })
12732
12848
  ```
12733
12849
 
@@ -12782,16 +12898,12 @@ set(lens: Lens): <T, U>(replacer: U, obj: T) => T;
12782
12898
  <summary><strong>R.set</strong> source</summary>
12783
12899
 
12784
12900
  ```javascript
12785
- import { always } from './always.js'
12786
- import { curry } from './curry.js'
12787
- import { over } from './over.js'
12901
+ import {always} from './always.js'
12902
+ import {curry} from './curry.js'
12903
+ import {over} from './over.js'
12788
12904
 
12789
- function setFn(
12790
- lens, replacer, x
12791
- ){
12792
- return over(
12793
- lens, always(replacer), x
12794
- )
12905
+ function setFn(lens, replacer, x) {
12906
+ return over(lens, always(replacer), x)
12795
12907
  }
12796
12908
 
12797
12909
  export const set = curry(setFn)
@@ -12804,43 +12916,39 @@ export const set = curry(setFn)
12804
12916
  <summary><strong>Tests</strong></summary>
12805
12917
 
12806
12918
  ```javascript
12807
- import { assoc } from './assoc.js'
12808
- import { lens } from './lens.js'
12809
- import { lensIndex } from './lensIndex.js'
12810
- import { lensPath } from './lensPath.js'
12811
- import { prop } from './prop.js'
12812
- import { set } from './set.js'
12919
+ import {assoc} from './assoc.js'
12920
+ import {lens} from './lens.js'
12921
+ import {lensIndex} from './lensIndex.js'
12922
+ import {lensPath} from './lensPath.js'
12923
+ import {prop} from './prop.js'
12924
+ import {set} from './set.js'
12813
12925
 
12814
12926
  const testObject = {
12815
- foo : 'bar',
12816
- baz : {
12817
- a : 'x',
12818
- b : 'y',
12927
+ foo: 'bar',
12928
+ baz: {
12929
+ a: 'x',
12930
+ b: 'y',
12819
12931
  },
12820
12932
  }
12821
12933
 
12822
12934
  test('assoc lens', () => {
12823
12935
  const assocLens = lens(prop('foo'), assoc('foo'))
12824
- const result = set(
12825
- assocLens, 'FOO', testObject
12826
- )
12936
+ const result = set(assocLens, 'FOO', testObject)
12827
12937
  const expected = {
12828
12938
  ...testObject,
12829
- foo : 'FOO',
12939
+ foo: 'FOO',
12830
12940
  }
12831
12941
  expect(result).toEqual(expected)
12832
12942
  })
12833
12943
 
12834
12944
  test('path lens', () => {
12835
12945
  const pathLens = lensPath('baz.a')
12836
- const result = set(
12837
- pathLens, 'z', testObject
12838
- )
12946
+ const result = set(pathLens, 'z', testObject)
12839
12947
  const expected = {
12840
12948
  ...testObject,
12841
- baz : {
12842
- a : 'z',
12843
- b : 'y',
12949
+ baz: {
12950
+ a: 'z',
12951
+ b: 'y',
12844
12952
  },
12845
12953
  }
12846
12954
  expect(result).toEqual(expected)
@@ -12849,10 +12957,8 @@ test('path lens', () => {
12849
12957
  test('index lens', () => {
12850
12958
  const indexLens = lensIndex(0)
12851
12959
 
12852
- const result = set(
12853
- indexLens, 3, [ 1, 2 ]
12854
- )
12855
- expect(result).toEqual([ 3, 2 ])
12960
+ const result = set(indexLens, 3, [1, 2])
12961
+ expect(result).toEqual([3, 2])
12856
12962
  })
12857
12963
  ```
12858
12964
 
@@ -13688,7 +13794,7 @@ describe('R.splitWhen', () => {
13688
13794
 
13689
13795
  ```typescript
13690
13796
 
13691
- startsWith(target: string, str: string): boolean
13797
+ startsWith<T extends string>(question: T, input: string): boolean
13692
13798
  ```
13693
13799
 
13694
13800
  When iterable is a string, then it behaves as `String.prototype.startsWith`.
@@ -13701,10 +13807,10 @@ When iterable is a list, then it uses R.equals to determine if the target list s
13701
13807
  <summary>All Typescript definitions</summary>
13702
13808
 
13703
13809
  ```typescript
13704
- startsWith(target: string, str: string): boolean;
13705
- startsWith(target: string): (str: string) => boolean;
13706
- startsWith<T>(target: T[], list: T[]): boolean;
13707
- startsWith<T>(target: T[]): (list: T[]) => boolean;
13810
+ startsWith<T extends string>(question: T, input: string): boolean;
13811
+ startsWith<T extends string>(question: T): (input: string) => boolean;
13812
+ startsWith<T>(question: T[], input: T[]): boolean;
13813
+ startsWith<T>(question: T[]): (input: T[]) => boolean;
13708
13814
  ```
13709
13815
 
13710
13816
  </details>
@@ -13717,17 +13823,17 @@ startsWith<T>(target: T[]): (list: T[]) => boolean;
13717
13823
  import { isArray } from './_internals/isArray.js'
13718
13824
  import { equals } from './equals.js'
13719
13825
 
13720
- export function startsWith(target, iterable){
13826
+ export function startsWith(question, iterable){
13721
13827
  if (arguments.length === 1)
13722
- return _iterable => startsWith(target, _iterable)
13828
+ return _iterable => startsWith(question, _iterable)
13723
13829
 
13724
13830
  if (typeof iterable === 'string'){
13725
- return iterable.startsWith(target)
13831
+ return iterable.startsWith(question)
13726
13832
  }
13727
- if (!isArray(target)) return false
13833
+ if (!isArray(question)) return false
13728
13834
 
13729
13835
  let correct = true
13730
- const filtered = target.filter((x, index) => {
13836
+ const filtered = question.filter((x, index) => {
13731
13837
  if (!correct) return false
13732
13838
  const result = equals(x, iterable[ index ])
13733
13839
  if (!result) correct = false
@@ -13735,7 +13841,7 @@ export function startsWith(target, iterable){
13735
13841
  return result
13736
13842
  })
13737
13843
 
13738
- return filtered.length === target.length
13844
+ return filtered.length === question.length
13739
13845
  }
13740
13846
  ```
13741
13847
 
@@ -13797,32 +13903,28 @@ describe('brute force', () => {
13797
13903
  ```typescript
13798
13904
  import {startsWith} from 'rambda'
13799
13905
 
13800
- describe('R.startsWith - array as iterable', () => {
13801
- const target = [{a: 1}]
13906
+ describe('R.startsWith - array', () => {
13907
+ const question = [{a: 1}]
13802
13908
  const iterable = [{a: 1}, {a: 2}]
13803
13909
  it('happy', () => {
13804
- const result = startsWith(target, iterable)
13805
-
13910
+ const result = startsWith(question, iterable)
13806
13911
  result // $ExpectType boolean
13807
13912
  })
13808
13913
  it('curried', () => {
13809
- const result = startsWith(target)(iterable)
13810
-
13914
+ const result = startsWith(question)(iterable)
13811
13915
  result // $ExpectType boolean
13812
13916
  })
13813
13917
  })
13814
13918
 
13815
- describe('R.startsWith - string as iterable', () => {
13816
- const target = 'foo'
13919
+ describe('R.startsWith - string', () => {
13920
+ const question = 'foo'
13817
13921
  const iterable = 'foo bar'
13818
13922
  it('happy', () => {
13819
- const result = startsWith(target, iterable)
13820
-
13923
+ const result = startsWith(question, iterable)
13821
13924
  result // $ExpectType boolean
13822
13925
  })
13823
13926
  it('curried', () => {
13824
- const result = startsWith(target)(iterable)
13825
-
13927
+ const result = startsWith(question)(iterable)
13826
13928
  result // $ExpectType boolean
13827
13929
  })
13828
13930
  })
@@ -15835,7 +15937,7 @@ describe('R.unless - curried', () => {
15835
15937
 
15836
15938
  ### unwind
15837
15939
 
15838
- <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20obj%20%3D%20%7B%0A%20%20a%3A%201%2C%0A%20%20b%3A%20%5B2%2C%203%5D%2C%0A%7D%0Aconst%20result%20%3D%20unwind('b'%2C%20Record%3Cstring%2C%20unknown%3E)%0Aconst%20expected%20%3D%20%5B%7Ba%3A1%2C%20b%3A2%7D%2C%20%7Ba%3A1%2C%20b%3A3%7D%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.unwind</strong> example in Rambda REPL</a>
15940
+ <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20obj%20%3D%20%7B%0A%20%20a%3A%201%2C%0A%20%20b%3A%20%5B2%2C%203%5D%2C%0A%7D%0Aconst%20result%20%3D%20R.unwind('b'%2C%20obj)%0Aconst%20expected%20%3D%20%5B%7Ba%3A1%2C%20b%3A2%7D%2C%20%7Ba%3A1%2C%20b%3A3%7D%5D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60">Try this <strong>R.unwind</strong> example in Rambda REPL</a>
15839
15941
 
15840
15942
  [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#unwind)
15841
15943
 
@@ -16560,7 +16662,7 @@ test('with list of objects', () => {
16560
16662
  })
16561
16663
 
16562
16664
  test('ramda accepts string as target input while rambda throws', () => {
16563
- expect(withoutRamda('0:1', [ '0', '0:1' ])).toEqual([])
16665
+ expect(withoutRamda('0:1', [ '0', '0:1' ])).toEqual([ '0:1' ])
16564
16666
  expect(() =>
16565
16667
  without('0:1', [ '0', '0:1' ])).toThrowErrorMatchingInlineSnapshot('"Cannot read property \'indexOf\' of 0:1"')
16566
16668
  expect(without([ '0:1' ], [ '0', '0:1' ])).toEqual([ '0' ])
@@ -17050,6 +17152,12 @@ describe('R.zipWith', () => {
17050
17152
 
17051
17153
  ## ❯ CHANGELOG
17052
17154
 
17155
+ 8.1.0
17156
+
17157
+ - Fix input order of TS definitions for `R.propEq` method - [Issue #688](https://github.com/selfrefactor/rambda/issues/688)
17158
+
17159
+ - Add `R.differenceWith` method - [Issue #91](https://github.com/selfrefactor/rambdax/issues/91)
17160
+
17053
17161
  8.0.0
17054
17162
 
17055
17163
  - handle falsy values in merge methods - https://github.com/ramda/ramda/pull/3222