Skip to content

Commit a5938ed

Browse files
committed
chore@small
1 parent 5938627 commit a5938ed

File tree

14 files changed

+262
-99
lines changed

14 files changed

+262
-99
lines changed

README.md

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,10 @@ describe('allPass', () => {
565565
[1, 2, 3, 4],
566566
[3, 4, 5],
567567
]
568-
const result = R.pipe(list, R.map(R.allPass([R.includes(3), R.includes(4)])))
568+
const result = R.pipe(list, R.map(R.allPass([
569+
(x) => x.length > 2,
570+
(x) => x.includes(3)
571+
])))
569572
result // $ExpectType boolean[]
570573
})
571574
})
@@ -3388,7 +3391,7 @@ import { excludes, pipe } from 'rambda'
33883391
describe('R.excludes', () => {
33893392
it('happy', () => {
33903393
const list = [{ a: { b: '1' } }, { a: { b: '2' } }, { a: { b: '3' } }]
3391-
const result = pipe(list, excludes({ a: { b: '1' } }))
3394+
const result = pipe({ a: { b: '1' } }, excludes(list))
33923395
result // $ExpectType boolean
33933396
})
33943397
it('with string', () => {
@@ -3402,6 +3405,73 @@ describe('R.excludes', () => {
34023405

34033406
[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#excludes)
34043407

3408+
### exists
3409+
3410+
```typescript
3411+
3412+
exists<T>(predicate: (x: T) => boolean): (list: T[]) => boolean
3413+
```
3414+
3415+
It returns `true` if there is at least one element in `list` that satisfy the `predicate`.
3416+
3417+
```javascript
3418+
const predicate = x => R.type(x.foo) === 'Number'
3419+
const list = [{foo: 'bar'}, {foo: 1}]
3420+
3421+
const result = R.exists(predicate)(list)
3422+
// => true
3423+
```
3424+
3425+
<a title="redirect to Rambda Repl site" href="https://rambda.netlify.app?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%20'bar'%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.exists(predicate)(list)%0A%2F%2F%20%3D%3E%20true">Try this <strong>R.exists</strong> example in Rambda REPL</a>
3426+
3427+
<details>
3428+
3429+
<summary>All TypeScript definitions</summary>
3430+
3431+
```typescript
3432+
exists<T>(predicate: (x: T) => boolean): (list: T[]) => boolean;
3433+
```
3434+
3435+
</details>
3436+
3437+
<details>
3438+
3439+
<summary><strong>R.exists</strong> source</summary>
3440+
3441+
```javascript
3442+
import { find } from './find.js'
3443+
3444+
export function exists(predicate) {
3445+
return list => {
3446+
return find(predicate)(list) !== undefined
3447+
}
3448+
}
3449+
```
3450+
3451+
</details>
3452+
3453+
<details>
3454+
3455+
<summary><strong>TypeScript</strong> test</summary>
3456+
3457+
```typescript
3458+
import { exists, pipe } from 'rambda'
3459+
3460+
const list = [1, 2, 3]
3461+
3462+
describe('R.exists', () => {
3463+
it('happy', () => {
3464+
const predicate = (x: number) => x > 2
3465+
const result = pipe(list, exists(predicate))
3466+
result // $ExpectType boolean
3467+
})
3468+
})
3469+
```
3470+
3471+
</details>
3472+
3473+
[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#exists)
3474+
34053475
### filter
34063476

34073477
```typescript
@@ -4905,7 +4975,7 @@ describe('R.head', () => {
49054975

49064976
```typescript
49074977

4908-
includes(list: readonly string[] | string): (substringToFind: string) => boolean
4978+
includes<T>(list: readonly T[]): (target: T) => boolean
49094979
```
49104980

49114981
If `input` is string, then this method work as native `String.includes`.
@@ -4927,8 +4997,8 @@ const result = [
49274997
<summary>All TypeScript definitions</summary>
49284998

49294999
```typescript
4930-
includes(list: readonly string[] | string): (substringToFind: string) => boolean;
49315000
includes<T>(list: readonly T[]): (target: T) => boolean;
5001+
includes(list: readonly string[] | string): (substringToFind: string) => boolean;
49325002
```
49335003

49345004
</details>
@@ -5005,28 +5075,22 @@ test('with wrong input that does not throw', () => {
50055075
<summary><strong>TypeScript</strong> test</summary>
50065076

50075077
```typescript
5008-
import { pipe, includes } from 'rambda'
5078+
import { pipe , includes} from 'rambda'
50095079

50105080
describe('R.includes', () => {
50115081
it('happy', () => {
50125082
const list = [{ a: { b: '1' } }, { a: { b: '2' } }, { a: { b: '3' } }]
5013-
const result = pipe(list, includes({ a: { b: '1' } }))
5083+
const result = pipe({ a: { b: '1' } }, includes(list))
50145084
result // $ExpectType boolean
50155085
})
50165086
it('with string', () => {
5017-
const result = pipe('foo', includes('bar'))
5087+
const result = pipe('oo', includes('foo'))
50185088
result // $ExpectType boolean
50195089
})
50205090
it('with array of strings', () => {
5021-
const result = pipe(['1','2'], includes('1'))
5091+
const result = pipe('1', includes(['1','2','3']))
50225092
result // $ExpectType boolean
50235093
})
5024-
it('without R.pipe', () => {
5025-
const result1 = includes('1')(['1', '2'])
5026-
const result2 = includes(1)([1, 2])
5027-
result1 // $ExpectType boolean
5028-
result2 // $ExpectType boolean
5029-
})
50305094
})
50315095
```
50325096

@@ -9846,9 +9910,9 @@ import { range } from 'rambda'
98469910

98479911
describe('R.range', () => {
98489912
it('curried', () => {
9849-
const result = range(1)(4)
9913+
const result = [range(1, 4), range(1)]
98509914

9851-
result // $ExpectType number[]
9915+
result // $ExpectType number[][]
98529916
})
98539917
})
98549918
```

dist/rambda.cjs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,28 @@ function excludes(valueToFind) {
640640
return iterable => !includes(valueToFind)(iterable)
641641
}
642642

643+
function find(predicate) {
644+
return list => {
645+
let index = 0;
646+
const len = list.length;
647+
648+
while (index < len) {
649+
const x = list[index];
650+
if (predicate(x)) {
651+
return x
652+
}
653+
654+
index++;
655+
}
656+
}
657+
}
658+
659+
function exists(predicate) {
660+
return list => {
661+
return find(predicate)(list) !== undefined
662+
}
663+
}
664+
643665
function filterAsync(predicate) {
644666
return async list => {
645667
const willReturn = [];
@@ -669,22 +691,6 @@ function filterObject(predicate) {
669691
}
670692
}
671693

672-
function find(predicate) {
673-
return list => {
674-
let index = 0;
675-
const len = list.length;
676-
677-
while (index < len) {
678-
const x = list[index];
679-
if (predicate(x)) {
680-
return x
681-
}
682-
683-
index++;
684-
}
685-
}
686-
}
687-
688694
function findIndex(predicate) {
689695
return list => {
690696
const len = list.length;
@@ -1927,6 +1933,7 @@ exports.equals = equals;
19271933
exports.equalsFn = equalsFn;
19281934
exports.evolve = evolve;
19291935
exports.excludes = excludes;
1936+
exports.exists = exists;
19301937
exports.filter = filter;
19311938
exports.filterAsync = filterAsync;
19321939
exports.filterObject = filterObject;

dist/rambda.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,28 @@ function excludes(valueToFind) {
638638
return iterable => !includes(valueToFind)(iterable)
639639
}
640640

641+
function find(predicate) {
642+
return list => {
643+
let index = 0;
644+
const len = list.length;
645+
646+
while (index < len) {
647+
const x = list[index];
648+
if (predicate(x)) {
649+
return x
650+
}
651+
652+
index++;
653+
}
654+
}
655+
}
656+
657+
function exists(predicate) {
658+
return list => {
659+
return find(predicate)(list) !== undefined
660+
}
661+
}
662+
641663
function filterAsync(predicate) {
642664
return async list => {
643665
const willReturn = [];
@@ -667,22 +689,6 @@ function filterObject(predicate) {
667689
}
668690
}
669691

670-
function find(predicate) {
671-
return list => {
672-
let index = 0;
673-
const len = list.length;
674-
675-
while (index < len) {
676-
const x = list[index];
677-
if (predicate(x)) {
678-
return x
679-
}
680-
681-
index++;
682-
}
683-
}
684-
}
685-
686692
function findIndex(predicate) {
687693
return list => {
688694
const len = list.length;
@@ -1889,4 +1895,4 @@ function zipWith(fn, x) {
18891895
)
18901896
}
18911897

1892-
export { _arity, _includes, _indexOf, _lastIndexOf, addProp, addPropToObjects, all, allPass, any, anyPass, append, ascend, assertType, checkObjectWithSpec, compact, complement, concat, convertToType, count, countBy, createCompareFunction, createObjectFromKeys, defaultTo, descend, difference, drop, dropLast, dropLastWhile, dropWhile, duplicateBy, eqBy, eqProps, equals, equalsFn, evolve, excludes, filter, filterAsync, filterObject, find, findIndex, findLast, findLastIndex, findNth, flatMap, flatten, flattenObject, flattenObjectHelper, groupBy, groupByFallback, head, includes, indexBy, indexOf, init, interpolate, intersection, intersectionWith, intersperse, join, last, lastIndexOf, map, mapAsync, mapFn, mapKeys, mapObject, mapObjectAsync, mapParallelAsync, mapPropObject, match, maxBy, merge, mergeTypes, minBy, modifyItemAtIndex, modifyPath, modifyProp, none, objOf, objectIncludes, omit, partition, partitionObject, path, pathSatisfies, permutations, pick, pipe, pipeAsync, pluck, prepend, prop, propEq, propOr, propSatisfies, range, rangeDescending, reduce, reject, rejectObject, replace, replaceAll, shuffle, sort, sortBy, sortByDescending, sortByFn, sortByPath, sortByPathDescending, sortObject, sortWith, split, splitEvery, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, transformFlatObject, tryCatch, type, union, unionWith, uniq, uniqBy, uniqWith, unless, unwind, update, when, zip, zipWith };
1898+
export { _arity, _includes, _indexOf, _lastIndexOf, addProp, addPropToObjects, all, allPass, any, anyPass, append, ascend, assertType, checkObjectWithSpec, compact, complement, concat, convertToType, count, countBy, createCompareFunction, createObjectFromKeys, defaultTo, descend, difference, drop, dropLast, dropLastWhile, dropWhile, duplicateBy, eqBy, eqProps, equals, equalsFn, evolve, excludes, exists, filter, filterAsync, filterObject, find, findIndex, findLast, findLastIndex, findNth, flatMap, flatten, flattenObject, flattenObjectHelper, groupBy, groupByFallback, head, includes, indexBy, indexOf, init, interpolate, intersection, intersectionWith, intersperse, join, last, lastIndexOf, map, mapAsync, mapFn, mapKeys, mapObject, mapObjectAsync, mapParallelAsync, mapPropObject, match, maxBy, merge, mergeTypes, minBy, modifyItemAtIndex, modifyPath, modifyProp, none, objOf, objectIncludes, omit, partition, partitionObject, path, pathSatisfies, permutations, pick, pipe, pipeAsync, pluck, prepend, prop, propEq, propOr, propSatisfies, range, rangeDescending, reduce, reject, rejectObject, replace, replaceAll, shuffle, sort, sortBy, sortByDescending, sortByFn, sortByPath, sortByPathDescending, sortObject, sortWith, split, splitEvery, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, transformFlatObject, tryCatch, type, union, unionWith, uniq, uniqBy, uniqWith, unless, unwind, update, when, zip, zipWith };

dist/rambda.umd.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,28 @@
644644
return iterable => !includes(valueToFind)(iterable)
645645
}
646646

647+
function find(predicate) {
648+
return list => {
649+
let index = 0;
650+
const len = list.length;
651+
652+
while (index < len) {
653+
const x = list[index];
654+
if (predicate(x)) {
655+
return x
656+
}
657+
658+
index++;
659+
}
660+
}
661+
}
662+
663+
function exists(predicate) {
664+
return list => {
665+
return find(predicate)(list) !== undefined
666+
}
667+
}
668+
647669
function filterAsync(predicate) {
648670
return async list => {
649671
const willReturn = [];
@@ -673,22 +695,6 @@
673695
}
674696
}
675697

676-
function find(predicate) {
677-
return list => {
678-
let index = 0;
679-
const len = list.length;
680-
681-
while (index < len) {
682-
const x = list[index];
683-
if (predicate(x)) {
684-
return x
685-
}
686-
687-
index++;
688-
}
689-
}
690-
}
691-
692698
function findIndex(predicate) {
693699
return list => {
694700
const len = list.length;
@@ -1931,6 +1937,7 @@
19311937
exports.equalsFn = equalsFn;
19321938
exports.evolve = evolve;
19331939
exports.excludes = excludes;
1940+
exports.exists = exists;
19341941
exports.filter = filter;
19351942
exports.filterAsync = filterAsync;
19361943
exports.filterObject = filterObject;

0 commit comments

Comments
 (0)