Skip to content

Commit 171b32f

Browse files
committed
chore@small
1 parent 3fad305 commit 171b32f

File tree

9 files changed

+823
-827
lines changed

9 files changed

+823
-827
lines changed

.github/README.md

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ In **Rambda** you have the choice to use dot notation(which is arguably more rea
8181
R.path('a.b', {a: {b: 1} })
8282
```
8383

84+
Please note that since path input is turned into array, i.e. if you want `R.path(['a','1', 'b'], {a: {'1': {b: 2}}})` to return `2`, you will have to pass array path, not string path. If you pass `a.1.b`, it will turn path input to `['a', 1, 'b']`.
85+
The other side effect is in `R.assocPath` and `R.dissocPath`, where inputs such as `['a', '1', 'b']` will be turned into `['a', 1, 'b']`.
86+
8487
### Comma notation for `R.pick` and `R.omit`
8588

8689
Similar to dot notation, but the separator is comma(`,`) instead of dot(`.`).
@@ -1887,11 +1890,11 @@ const path = 'b.c'
18871890
const newValue = 2
18881891
const obj = { a: 1 }
18891892

1890-
R.assocPath(path, newValue, Record<string, unknown>)
1893+
const result = R.assocPath(path, newValue, obj)
18911894
// => { a : 1, b : { c : 2 }}
18921895
```
18931896

1894-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20path%20%3D%20'b.c'%0Aconst%20newValue%20%3D%202%0Aconst%20obj%20%3D%20%7B%20a%3A%201%20%7D%0A%0Aconst%20result%20%3D%20R.assocPath(path%2C%20newValue%2C%20Record%3Cstring%2C%20unknown%3E)%0A%2F%2F%20%3D%3E%20%7B%20a%20%3A%201%2C%20b%20%3A%20%7B%20c%20%3A%202%20%7D%7D">Try this <strong>R.assocPath</strong> example in Rambda REPL</a>
1897+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20path%20%3D%20'b.c'%0Aconst%20newValue%20%3D%202%0Aconst%20obj%20%3D%20%7B%20a%3A%201%20%7D%0A%0Aconst%20result%20%3D%20R.assocPath(path%2C%20newValue%2C%20obj)%0A%2F%2F%20%3D%3E%20%7B%20a%20%3A%201%2C%20b%20%3A%20%7B%20c%20%3A%202%20%7D%7D">Try this <strong>R.assocPath</strong> example in Rambda REPL</a>
18951898

18961899
<details>
18971900

@@ -2022,27 +2025,6 @@ test('difference with ramda - doesn\'t overwrite primitive values with keys in t
20222025
})
20232026
})
20242027

2025-
test('bug 524', () => {
2026-
/*
2027-
https://github.com/selfrefactor/rambda/issues/524
2028-
*/
2029-
const state = {}
2030-
2031-
const withDateLike = assocPathFn(
2032-
[ 'outerProp', '2020-03-10' ],
2033-
{ prop : 2 },
2034-
state
2035-
)
2036-
const withNumber = assocPathFn(
2037-
[ 'outerProp,5' ], { prop : 2 }, state
2038-
)
2039-
2040-
const withDateLikeExpected = { outerProp : { '2020-03-10' : { prop : 2 } } }
2041-
const withNumberExpected = { outerProp : { 5 : { prop : 2 } } }
2042-
expect(withDateLike).toEqual(withDateLikeExpected)
2043-
// expect(withNumber).toEqual(withNumberExpected)
2044-
})
2045-
20462028
test('adds a key to an empty object', () => {
20472029
expect(assocPathFn(
20482030
[ 'a' ], 1, {}
@@ -3195,7 +3177,7 @@ export function differenceWithFn(
31953177
fn, a, b
31963178
){
31973179
const willReturn = []
3198-
const [ first, second ] = a.length > b.length ? [ a, b ] : [ b, a ]
3180+
const [ first, second ] = a.length >= b.length ? [ a, b ] : [ b, a ]
31993181

32003182
first.forEach(item => {
32013183
const hasItem = second.some(secondItem => fn(item, secondItem))
@@ -3217,19 +3199,21 @@ export const differenceWith = curry(differenceWithFn)
32173199
<summary><strong>Tests</strong></summary>
32183200

32193201
```javascript
3220-
import { differenceWith } from './differenceWith.js'
3202+
import { differenceWith } from './differenceWith.js';
32213203

3222-
test('happy', () => {
3223-
const foo = [ { a : 1 }, { a : 2 }, { a : 3 } ]
3224-
const bar = [ { a : 3 }, { a : 4 } ]
3225-
const fn = function (r, s){
3226-
return r.a === s.a
3227-
}
3228-
const result = differenceWith(
3229-
fn, foo, bar
3230-
)
3231-
expect(result).toEqual([ { a : 1 }, { a : 2 } ])
3232-
})
3204+
const fn = (a, b) => a.x === b.x;
3205+
3206+
test('same length of list', () => {
3207+
const result = differenceWith(fn, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 3 }]);
3208+
expect(result).toEqual([{ x: 2 }]);
3209+
});
3210+
3211+
test('different length of list', () => {
3212+
const foo = [{ x: 1 }, { x: 2 }, { x: 3 }];
3213+
const bar = [{ x: 3 }, { x: 4 }];
3214+
const result = differenceWith(fn, foo, bar);
3215+
expect(result).toEqual([{ x: 1 }, { x: 2 }]);
3216+
});
32333217
```
32343218

32353219
</details>
@@ -11119,14 +11103,14 @@ const pathToSearch = 'a.b'
1111911103
const pathToSearchList = ['a', 'b']
1112011104

1112111105
const result = [
11122-
R.path(pathToSearch, Record<string, unknown>),
11123-
R.path(pathToSearchList, Record<string, unknown>),
11124-
R.path('a.b.c.d', Record<string, unknown>)
11106+
R.path(pathToSearch, obj),
11107+
R.path(pathToSearchList, obj),
11108+
R.path('a.b.c.d', obj)
1112511109
]
1112611110
// => [1, 1, undefined]
1112711111
```
1112811112

11129-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20obj%20%3D%20%7Ba%3A%20%7Bb%3A%201%7D%7D%0Aconst%20pathToSearch%20%3D%20'a.b'%0Aconst%20pathToSearchList%20%3D%20%5B'a'%2C%20'b'%5D%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.path(pathToSearch%2C%20Record%3Cstring%2C%20unknown%3E)%2C%0A%20%20R.path(pathToSearchList%2C%20Record%3Cstring%2C%20unknown%3E)%2C%0A%20%20R.path('a.b.c.d'%2C%20Record%3Cstring%2C%20unknown%3E)%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%201%2C%20undefined%5D">Try this <strong>R.path</strong> example in Rambda REPL</a>
11113+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20obj%20%3D%20%7Ba%3A%20%7Bb%3A%201%7D%7D%0Aconst%20pathToSearch%20%3D%20'a.b'%0Aconst%20pathToSearchList%20%3D%20%5B'a'%2C%20'b'%5D%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.path(pathToSearch%2C%20obj)%2C%0A%20%20R.path(pathToSearchList%2C%20obj)%2C%0A%20%20R.path('a.b.c.d'%2C%20obj)%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%201%2C%20undefined%5D">Try this <strong>R.path</strong> example in Rambda REPL</a>
1113011114

1113111115
<details>
1113211116

@@ -11239,12 +11223,14 @@ test('works with string instead of array', () => {
1123911223

1124011224
test('path', () => {
1124111225
expect(path([ 'foo', 'bar', 'baz' ])({ foo : { bar : { baz : 'yes' } } })).toBe('yes')
11242-
1124311226
expect(path([ 'foo', 'bar', 'baz' ])(null)).toBeUndefined()
11244-
1124511227
expect(path([ 'foo', 'bar', 'baz' ])({ foo : { bar : 'baz' } })).toBeUndefined()
1124611228
})
1124711229

11230+
test('with number string in between', () => {
11231+
expect(path(['a','1','b'], {a: [{b: 1}, {b: 2}]})).toBe(2)
11232+
})
11233+
1124811234
test('null is not a valid path', () => {
1124911235
expect(path('audio_tracks', {
1125011236
a : 1,
@@ -18567,6 +18553,14 @@ describe('R.zipWith', () => {
1856718553

1856818554
## ❯ CHANGELOG
1856918555

18556+
9.4.2
18557+
18558+
- Fix bug with `R.differenceWith` when two arrays has same length - [Issue #750](https://github.com/selfrefactor/rambda/issues/757)
18559+
18560+
9.4.1
18561+
18562+
- Allow path input to not be transformed when string numbers are there - [Issue #750](https://github.com/selfrefactor/rambda/issues/750)
18563+
1857018564
9.4.0
1857118565

1857218566
- Fix `deno` release

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
9.4.2
2+
3+
- Fix bug with `R.differenceWith` when two arrays has same length - [Issue #750](https://github.com/selfrefactor/rambda/issues/757)
4+
5+
9.4.1
6+
7+
- Allow path input to not be transformed when string numbers are there - [Issue #750](https://github.com/selfrefactor/rambda/issues/750)
8+
19
9.4.0
210

311
- Fix `deno` release

README.md

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ In **Rambda** you have the choice to use dot notation(which is arguably more rea
8181
R.path('a.b', {a: {b: 1} })
8282
```
8383

84+
Please note that since path input is turned into array, i.e. if you want `R.path(['a','1', 'b'], {a: {'1': {b: 2}}})` to return `2`, you will have to pass array path, not string path. If you pass `a.1.b`, it will turn path input to `['a', 1, 'b']`.
85+
The other side effect is in `R.assocPath` and `R.dissocPath`, where inputs such as `['a', '1', 'b']` will be turned into `['a', 1, 'b']`.
86+
8487
### Comma notation for `R.pick` and `R.omit`
8588

8689
Similar to dot notation, but the separator is comma(`,`) instead of dot(`.`).
@@ -1789,7 +1792,7 @@ assocPath<Output>(path: Path, newValue: any, obj: object): Output
17891792

17901793
It makes a shallow clone of `obj` with setting or overriding with `newValue` the property found with `path`.
17911794

1792-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20path%20%3D%20'b.c'%0Aconst%20newValue%20%3D%202%0Aconst%20obj%20%3D%20%7B%20a%3A%201%20%7D%0A%0Aconst%20result%20%3D%20R.assocPath(path%2C%20newValue%2C%20Record%3Cstring%2C%20unknown%3E)%0A%2F%2F%20%3D%3E%20%7B%20a%20%3A%201%2C%20b%20%3A%20%7B%20c%20%3A%202%20%7D%7D">Try this <strong>R.assocPath</strong> example in Rambda REPL</a>
1795+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20path%20%3D%20'b.c'%0Aconst%20newValue%20%3D%202%0Aconst%20obj%20%3D%20%7B%20a%3A%201%20%7D%0A%0Aconst%20result%20%3D%20R.assocPath(path%2C%20newValue%2C%20obj)%0A%2F%2F%20%3D%3E%20%7B%20a%20%3A%201%2C%20b%20%3A%20%7B%20c%20%3A%202%20%7D%7D">Try this <strong>R.assocPath</strong> example in Rambda REPL</a>
17931796

17941797
<details>
17951798

@@ -1920,27 +1923,6 @@ test('difference with ramda - doesn\'t overwrite primitive values with keys in t
19201923
})
19211924
})
19221925

1923-
test('bug 524', () => {
1924-
/*
1925-
https://github.com/selfrefactor/rambda/issues/524
1926-
*/
1927-
const state = {}
1928-
1929-
const withDateLike = assocPathFn(
1930-
[ 'outerProp', '2020-03-10' ],
1931-
{ prop : 2 },
1932-
state
1933-
)
1934-
const withNumber = assocPathFn(
1935-
[ 'outerProp,5' ], { prop : 2 }, state
1936-
)
1937-
1938-
const withDateLikeExpected = { outerProp : { '2020-03-10' : { prop : 2 } } }
1939-
const withNumberExpected = { outerProp : { 5 : { prop : 2 } } }
1940-
expect(withDateLike).toEqual(withDateLikeExpected)
1941-
// expect(withNumber).toEqual(withNumberExpected)
1942-
})
1943-
19441926
test('adds a key to an empty object', () => {
19451927
expect(assocPathFn(
19461928
[ 'a' ], 1, {}
@@ -3024,7 +3006,7 @@ export function differenceWithFn(
30243006
fn, a, b
30253007
){
30263008
const willReturn = []
3027-
const [ first, second ] = a.length > b.length ? [ a, b ] : [ b, a ]
3009+
const [ first, second ] = a.length >= b.length ? [ a, b ] : [ b, a ]
30283010

30293011
first.forEach(item => {
30303012
const hasItem = second.some(secondItem => fn(item, secondItem))
@@ -3046,19 +3028,21 @@ export const differenceWith = curry(differenceWithFn)
30463028
<summary><strong>Tests</strong></summary>
30473029

30483030
```javascript
3049-
import { differenceWith } from './differenceWith.js'
3031+
import { differenceWith } from './differenceWith.js';
30503032

3051-
test('happy', () => {
3052-
const foo = [ { a : 1 }, { a : 2 }, { a : 3 } ]
3053-
const bar = [ { a : 3 }, { a : 4 } ]
3054-
const fn = function (r, s){
3055-
return r.a === s.a
3056-
}
3057-
const result = differenceWith(
3058-
fn, foo, bar
3059-
)
3060-
expect(result).toEqual([ { a : 1 }, { a : 2 } ])
3061-
})
3033+
const fn = (a, b) => a.x === b.x;
3034+
3035+
test('same length of list', () => {
3036+
const result = differenceWith(fn, [{ x: 1 }, { x: 2 }], [{ x: 1 }, { x: 3 }]);
3037+
expect(result).toEqual([{ x: 2 }]);
3038+
});
3039+
3040+
test('different length of list', () => {
3041+
const foo = [{ x: 1 }, { x: 2 }, { x: 3 }];
3042+
const bar = [{ x: 3 }, { x: 4 }];
3043+
const result = differenceWith(fn, foo, bar);
3044+
expect(result).toEqual([{ x: 1 }, { x: 2 }]);
3045+
});
30623046
```
30633047

30643048
</details>
@@ -10446,7 +10430,7 @@ If `pathToSearch` is `'a.b'` then it will return `1` if `obj` is `{a:{b:1}}`.
1044610430

1044710431
It will return `undefined`, if such path is not found.
1044810432

10449-
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20obj%20%3D%20%7Ba%3A%20%7Bb%3A%201%7D%7D%0Aconst%20pathToSearch%20%3D%20'a.b'%0Aconst%20pathToSearchList%20%3D%20%5B'a'%2C%20'b'%5D%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.path(pathToSearch%2C%20Record%3Cstring%2C%20unknown%3E)%2C%0A%20%20R.path(pathToSearchList%2C%20Record%3Cstring%2C%20unknown%3E)%2C%0A%20%20R.path('a.b.c.d'%2C%20Record%3Cstring%2C%20unknown%3E)%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%201%2C%20undefined%5D">Try this <strong>R.path</strong> example in Rambda REPL</a>
10433+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20obj%20%3D%20%7Ba%3A%20%7Bb%3A%201%7D%7D%0Aconst%20pathToSearch%20%3D%20'a.b'%0Aconst%20pathToSearchList%20%3D%20%5B'a'%2C%20'b'%5D%0A%0Aconst%20result%20%3D%20%5B%0A%20%20R.path(pathToSearch%2C%20obj)%2C%0A%20%20R.path(pathToSearchList%2C%20obj)%2C%0A%20%20R.path('a.b.c.d'%2C%20obj)%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%201%2C%20undefined%5D">Try this <strong>R.path</strong> example in Rambda REPL</a>
1045010434

1045110435
<details>
1045210436

@@ -10559,12 +10543,14 @@ test('works with string instead of array', () => {
1055910543

1056010544
test('path', () => {
1056110545
expect(path([ 'foo', 'bar', 'baz' ])({ foo : { bar : { baz : 'yes' } } })).toBe('yes')
10562-
1056310546
expect(path([ 'foo', 'bar', 'baz' ])(null)).toBeUndefined()
10564-
1056510547
expect(path([ 'foo', 'bar', 'baz' ])({ foo : { bar : 'baz' } })).toBeUndefined()
1056610548
})
1056710549

10550+
test('with number string in between', () => {
10551+
expect(path(['a','1','b'], {a: [{b: 1}, {b: 2}]})).toBe(2)
10552+
})
10553+
1056810554
test('null is not a valid path', () => {
1056910555
expect(path('audio_tracks', {
1057010556
a : 1,
@@ -17257,6 +17243,14 @@ describe('R.zipWith', () => {
1725717243

1725817244
## ❯ CHANGELOG
1725917245

17246+
9.4.2
17247+
17248+
- Fix bug with `R.differenceWith` when two arrays has same length - [Issue #750](https://github.com/selfrefactor/rambda/issues/757)
17249+
17250+
9.4.1
17251+
17252+
- Allow path input to not be transformed when string numbers are there - [Issue #750](https://github.com/selfrefactor/rambda/issues/750)
17253+
1726017254
9.4.0
1726117255

1726217256
- Fix `deno` release

dist/rambda.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ function difference(a, b) {
812812

813813
function differenceWithFn(fn, a, b) {
814814
const willReturn = [];
815-
const [first, second] = a.length > b.length ? [a, b] : [b, a];
815+
const [first, second] = a.length >= b.length ? [a, b] : [b, a];
816816
first.forEach(item => {
817817
const hasItem = second.some(secondItem => fn(item, secondItem));
818818
if (!hasItem && _indexOf(item, willReturn) === -1) {

dist/rambda.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)