Skip to content

Commit a0d2ba2

Browse files
authored
Add missing JS change for R.includes and R.excludes methods (#801)
* chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * Fix R.includes * chore@small * d * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * kata * 2 * 3 * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * repl * chore@small * chore@small * chore@small * feat@fix filter * readonly on top * chore@small * union.with * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small * chore@small
1 parent 0904c4a commit a0d2ba2

21 files changed

+203
-247
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
11.0.1
2+
3+
- Add missing JS change for `R.includes` and `R.excludes` methods in `11.0.0` release.
4+
15
11.0.0
26

37
- Breaking change: `R.includes` and `R.excludes` now accept list as first argument and value to search as second argument. This makes it more useful when used with `R.filter` and `R.reject`.

README.md

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -532,20 +532,19 @@ export function allPass(predicates) {
532532
```javascript
533533
import { allPass } from './allPass.js'
534534
import { filter } from './filter.js'
535-
import { includes } from './includes.js'
536535
import { pipe } from './pipe.js'
537536

538537
const list = [
539538
[1, 2, 3, 4],
540539
[3, 4, 5],
541540
]
542541
test('happy', () => {
543-
const result = pipe(list, filter(allPass([includes(2), includes(3)])))
542+
const result = pipe(list, filter(allPass([x => x.includes(2), x => x.includes(3)])))
544543
expect(result).toEqual([[1, 2, 3, 4]])
545544
})
546545

547546
test('when returns false', () => {
548-
const result = pipe(list, filter(allPass([includes(12), includes(31)])))
547+
const result = pipe(list, filter(allPass([x => x.includes(12), x => x.includes(31)])))
549548
expect(result).toEqual([])
550549
})
551550
```
@@ -2029,12 +2028,12 @@ difference<T>(x: T[]): (y: T[]) => T[];
20292028

20302029
```javascript
20312030
import { filter } from './filter.js'
2032-
import { includes } from './includes.js'
2031+
import { excludes } from './excludes.js'
20332032

2034-
export function difference(x) {
2035-
return y => ([
2036-
...filter(value => !includes(value)(y))(x),
2037-
...filter(value => !includes(value)(x))(y),
2033+
export function difference(listA) {
2034+
return listB => ([
2035+
...filter(value => excludes(listB)(value))(listA),
2036+
...filter(value => excludes(listA)(value))(listB),
20382037
])
20392038
}
20402039
```
@@ -3350,8 +3349,8 @@ excludes<T>(list: readonly T[]): (target: T) => boolean;
33503349
```javascript
33513350
import { includes } from './includes.js'
33523351

3353-
export function excludes(valueToFind) {
3354-
return iterable => !includes(valueToFind)(iterable)
3352+
export function excludes(iterable) {
3353+
return valueToFind => !includes(iterable)(valueToFind)
33553354
}
33563355
```
33573356

@@ -3367,15 +3366,15 @@ import { excludes } from './excludes.js'
33673366
test('excludes with string', () => {
33683367
const str = 'more is less'
33693368

3370-
expect(excludes('less')(str)).toBeFalsy()
3371-
expect(excludes('never')(str)).toBeTruthy()
3369+
expect(excludes(str)('less')).toBeFalsy()
3370+
expect(excludes(str)('never')).toBeTruthy()
33723371
})
33733372

33743373
test('excludes with array', () => {
33753374
const arr = [1, 2, 3]
33763375

3377-
expect(excludes(2)(arr)).toBeFalsy()
3378-
expect(excludes(4)(arr)).toBeTruthy()
3376+
expect(excludes(arr)(2)).toBeFalsy()
3377+
expect(excludes(arr)(4)).toBeTruthy()
33793378
})
33803379
```
33813380

@@ -5034,8 +5033,8 @@ includes(list: readonly string[] | string): (substringToFind: string) => boolean
50345033
import { isArray } from './_internals/isArray.js'
50355034
import { _indexOf } from './equals.js'
50365035

5037-
export function includes(valueToFind) {
5038-
return iterable => {
5036+
export function includes(iterable) {
5037+
return valueToFind => {
50395038
if (typeof iterable === 'string') {
50405039
return iterable.includes(valueToFind)
50415040
}
@@ -5063,30 +5062,30 @@ import { includes } from './includes.js'
50635062
test('with string as iterable', () => {
50645063
const str = 'foo bar'
50655064

5066-
expect(includes('bar')(str)).toBeTruthy()
5067-
expect(includes('never')(str)).toBeFalsy()
5065+
expect(includes(str)('foo')).toBeTruthy()
5066+
expect(includes(str)('never')).toBeFalsy()
50685067
})
50695068

50705069
test('with array as iterable', () => {
50715070
const arr = [1, 2, 3]
50725071

5073-
expect(includes(2)(arr)).toBeTruthy()
5074-
expect(includes(4)(arr)).toBeFalsy()
5072+
expect(includes(arr)(2)).toBeTruthy()
5073+
expect(includes(arr)(4)).toBeFalsy()
50755074
})
50765075

50775076
test('with list of objects as iterable', () => {
50785077
const arr = [{ a: 1 }, { b: 2 }, { c: 3 }]
50795078

5080-
expect(includes({ c: 3 })(arr)).toBeTruthy()
5079+
expect(includes(arr)({ c: 3 })).toBeTruthy()
50815080
})
50825081

50835082
test('with NaN', () => {
5084-
const result = includes(Number.NaN)([Number.NaN])
5083+
const result = includes([Number.NaN])(Number.NaN)
50855084
expect(result).toBeTruthy()
50865085
})
50875086

50885087
test('with wrong input that does not throw', () => {
5089-
const result = includes(1)(/foo/g)
5088+
const result = includes([1])(/foo/g)
50905089
expect(result).toBeFalsy()
50915090
})
50925091
```
@@ -5573,7 +5572,7 @@ import { filter } from './filter.js'
55735572
import { includes } from './includes.js'
55745573

55755574
export function intersection(listA) {
5576-
return listB => filter(x => includes(x)(listA))(listB)
5575+
return listB => filter(includes(listA))(listB)
55775576
}
55785577
```
55795578

@@ -11638,13 +11637,13 @@ symmetricDifference<T>(x: T[]): (y: T[]) => T[];
1163811637

1163911638
```javascript
1164011639
import { filter } from './filter.js'
11641-
import { includes } from './includes.js'
11640+
import { excludes } from './excludes.js'
1164211641

11643-
export function symmetricDifference(x) {
11644-
return y => [
11645-
...filter(value => !includes(value)(y))(x),
11646-
...filter(value => !includes(value)(x))(y),
11647-
]
11642+
export function symmetricDifference(listA) {
11643+
return listB => [
11644+
...filter(excludes(listB))(listA),
11645+
...filter(excludes(listA))(listB),
11646+
]
1164811647
}
1164911648
```
1165011649

@@ -12777,21 +12776,13 @@ union<T>(x: T[]): (y: T[]) => T[];
1277712776
<summary><strong>R.union</strong> source</summary>
1277812777

1277912778
```javascript
12780-
import { cloneList } from './_internals/cloneList.js'
12781-
import { includes } from './includes.js'
12782-
12783-
export function union(x) {
12784-
return y => {
12785-
const toReturn = cloneList(x)
12786-
12787-
y.forEach(yInstance => {
12788-
if (!includes(yInstance)(x)) {
12789-
toReturn.push(yInstance)
12790-
}
12791-
})
12779+
import { excludes } from './excludes.js'
1279212780

12793-
return toReturn
12794-
}
12781+
export function union(listA) {
12782+
return listB => [
12783+
...listA,
12784+
...listB.filter(excludes(listA)),
12785+
]
1279512786
}
1279612787
```
1279712788

@@ -13982,6 +13973,10 @@ describe('R.zipWith', () => {
1398213973

1398313974
## ❯ CHANGELOG
1398413975

13976+
11.0.1
13977+
13978+
- Add missing JS change for `R.includes` and `R.excludes` methods in `11.0.0` release.
13979+
1398513980
11.0.0
1398613981

1398713982
- Breaking change: `R.includes` and `R.excludes` now accept list as first argument and value to search as second argument. This makes it more useful when used with `R.filter` and `R.reject`.

dist/rambda.cjs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ function equals(a) {
481481
return b => equalsFn(a, b)
482482
}
483483

484-
function includes(valueToFind) {
485-
return iterable => {
484+
function includes(iterable) {
485+
return valueToFind => {
486486
if (typeof iterable === 'string') {
487487
return iterable.includes(valueToFind)
488488
}
@@ -497,10 +497,14 @@ function includes(valueToFind) {
497497
}
498498
}
499499

500-
function difference(x) {
501-
return y => ([
502-
...filter(value => !includes(value)(y))(x),
503-
...filter(value => !includes(value)(x))(y),
500+
function excludes(iterable) {
501+
return valueToFind => !includes(iterable)(valueToFind)
502+
}
503+
504+
function difference(listA) {
505+
return listB => ([
506+
...filter(value => excludes(listB)(value))(listA),
507+
...filter(value => excludes(listA)(value))(listB),
504508
])
505509
}
506510

@@ -636,10 +640,6 @@ function evolve(rules) {
636640
return mapObject((x, prop) => type(rules[prop]) === 'Function' ? rules[prop](x): x)
637641
}
638642

639-
function excludes(valueToFind) {
640-
return iterable => !includes(valueToFind)(iterable)
641-
}
642-
643643
function find(predicate) {
644644
return list => {
645645
let index = 0;
@@ -951,7 +951,7 @@ function interpolate(input) {
951951
}
952952

953953
function intersection(listA) {
954-
return listB => filter(x => includes(x)(listA))(listB)
954+
return listB => filter(includes(listA))(listB)
955955
}
956956

957957
function _includesWith(pred, x, list) {
@@ -1669,11 +1669,11 @@ function splitEvery(sliceLength) {
16691669
}
16701670
}
16711671

1672-
function symmetricDifference(x) {
1673-
return y => [
1674-
...filter(value => !includes(value)(y))(x),
1675-
...filter(value => !includes(value)(x))(y),
1676-
]
1672+
function symmetricDifference(listA) {
1673+
return listB => [
1674+
...filter(excludes(listB))(listA),
1675+
...filter(excludes(listA))(listB),
1676+
]
16771677
}
16781678

16791679
function tail(listOrString) {
@@ -1770,18 +1770,11 @@ function tryCatch(fn, fallback) {
17701770
}
17711771
}
17721772

1773-
function union(x) {
1774-
return y => {
1775-
const toReturn = cloneList(x);
1776-
1777-
y.forEach(yInstance => {
1778-
if (!includes(yInstance)(x)) {
1779-
toReturn.push(yInstance);
1780-
}
1781-
});
1782-
1783-
return toReturn
1784-
}
1773+
function union(listA) {
1774+
return listB => [
1775+
...listA,
1776+
...listB.filter(excludes(listA)),
1777+
]
17851778
}
17861779

17871780
function unionWith(predicate, x) {

dist/rambda.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ function equals(a) {
479479
return b => equalsFn(a, b)
480480
}
481481

482-
function includes(valueToFind) {
483-
return iterable => {
482+
function includes(iterable) {
483+
return valueToFind => {
484484
if (typeof iterable === 'string') {
485485
return iterable.includes(valueToFind)
486486
}
@@ -495,10 +495,14 @@ function includes(valueToFind) {
495495
}
496496
}
497497

498-
function difference(x) {
499-
return y => ([
500-
...filter(value => !includes(value)(y))(x),
501-
...filter(value => !includes(value)(x))(y),
498+
function excludes(iterable) {
499+
return valueToFind => !includes(iterable)(valueToFind)
500+
}
501+
502+
function difference(listA) {
503+
return listB => ([
504+
...filter(value => excludes(listB)(value))(listA),
505+
...filter(value => excludes(listA)(value))(listB),
502506
])
503507
}
504508

@@ -634,10 +638,6 @@ function evolve(rules) {
634638
return mapObject((x, prop) => type(rules[prop]) === 'Function' ? rules[prop](x): x)
635639
}
636640

637-
function excludes(valueToFind) {
638-
return iterable => !includes(valueToFind)(iterable)
639-
}
640-
641641
function find(predicate) {
642642
return list => {
643643
let index = 0;
@@ -949,7 +949,7 @@ function interpolate(input) {
949949
}
950950

951951
function intersection(listA) {
952-
return listB => filter(x => includes(x)(listA))(listB)
952+
return listB => filter(includes(listA))(listB)
953953
}
954954

955955
function _includesWith(pred, x, list) {
@@ -1667,11 +1667,11 @@ function splitEvery(sliceLength) {
16671667
}
16681668
}
16691669

1670-
function symmetricDifference(x) {
1671-
return y => [
1672-
...filter(value => !includes(value)(y))(x),
1673-
...filter(value => !includes(value)(x))(y),
1674-
]
1670+
function symmetricDifference(listA) {
1671+
return listB => [
1672+
...filter(excludes(listB))(listA),
1673+
...filter(excludes(listA))(listB),
1674+
]
16751675
}
16761676

16771677
function tail(listOrString) {
@@ -1768,18 +1768,11 @@ function tryCatch(fn, fallback) {
17681768
}
17691769
}
17701770

1771-
function union(x) {
1772-
return y => {
1773-
const toReturn = cloneList(x);
1774-
1775-
y.forEach(yInstance => {
1776-
if (!includes(yInstance)(x)) {
1777-
toReturn.push(yInstance);
1778-
}
1779-
});
1780-
1781-
return toReturn
1782-
}
1771+
function union(listA) {
1772+
return listB => [
1773+
...listA,
1774+
...listB.filter(excludes(listA)),
1775+
]
17831776
}
17841777

17851778
function unionWith(predicate, x) {

0 commit comments

Comments
 (0)