Skip to content

Commit e88523a

Browse files
authored
Merge pull request #98 from Smoren/dev
Ready for release v2.5.0
2 parents 43ea955 + 660b605 commit e88523a

File tree

8 files changed

+175
-2
lines changed

8 files changed

+175
-2
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# IterTools Typescript Change Log
22

3+
## v2.5.0 - 2025-12-31
4+
5+
### New features
6+
* summary
7+
* `isEmpty()`
8+
* `isEmptyAsync()`
9+
* Stream
10+
* `isEmpty()`
11+
* AsyncStream
12+
* `isEmpty()`
13+
314
## v2.4.1 - 2025-12-30
415

516
### Fixes

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Quick Reference
235235
| [`anyMatch`](#any-match) | True if any item is true according to predicate | `summary.anyMatch(data, predicate)` | `summary.anyMatchAsync(data, predicate)` |
236236
| [`exactlyN`](#exactly-n) | True if exactly n items are true according to predicate | `summary.exactlyN(data, n, predicate)` | `summary.exactlyNAsync(data, n, predicate)` |
237237
| [`isAsyncIterable`](#is-async-iterable) | True if given data is async iterable | `summary.isAsyncIterable(data)` ||
238+
| [`isEmpty`](#is-empty) | True if iterable is empty | `summary.isEmpty(data)` | `summary.isEmptyAsync(data)` |
238239
| [`isIterable`](#is-iterable) | True if given data is iterable | `summary.isIterable(data)` ||
239240
| [`isIterator`](#is-iterator) | True if given data is iterator | `summary.isIterator(data)` ||
240241
| [`isReversed`](#is-reversed) | True if iterable reverse sorted | `summary.isReversed(data)` | `summary.isReversedAsync(data)` |
@@ -341,6 +342,7 @@ Quick Reference
341342
| [`allUnique`](#all-unique-1) | Returns true if all elements of stream are unique | `stream.allUnique(predicate)` |
342343
| [`anyMatch`](#any-match-1) | Returns true if any item in stream matches predicate | `stream.anyMatch(predicate)` |
343344
| [`exactlyN`](#exactly-n-1) | Returns true if exactly n items are true according to predicate | `stream.exactlyN(n, predicate)` |
345+
| [`isEmpty`](#is-empty-1) | Returns true if stream is empty | `stream.isEmpty()` |
344346
| [`isReversed`](#is-reversed-1) | Returns true if stream is sorted in reverse descending order | `stream.isReversed()` |
345347
| [`isSorted`](#is-sorted-1) | Returns true if stream is sorted in ascending order | `stream.isSorted()` |
346348
| [`noneMatch`](#none-match-1) | Returns true if none of the items in stream match predicate | `stream.noneMatch(predicate)` |
@@ -1945,6 +1947,30 @@ Summary.isReversed(numbers);
19451947
// false
19461948
```
19471949

1950+
### Is Empty
1951+
Returns true if there are no elements, otherwise false.
1952+
1953+
```
1954+
function isEmpty(data: Iterable<unknown> | Iterator<unknown>): boolean
1955+
```
1956+
1957+
- Returns true if empty.
1958+
- Returns false if one or more elements.
1959+
1960+
```typescript
1961+
import { summary } from "itertools-ts";
1962+
1963+
const emptyArray = [];
1964+
1965+
Summary.isEmpty(emptyArray);
1966+
// true
1967+
1968+
const numbers = [3];
1969+
1970+
Summary.isEmpty(numbers);
1971+
// false
1972+
```
1973+
19481974
### Is Sorted
19491975
Returns true if elements are sorted, otherwise false.
19501976

@@ -3618,6 +3644,33 @@ Stream.of(input)
36183644
// false
36193645
```
36203646

3647+
##### Is Empty
3648+
Returns true if iterable source is empty, otherwise false.
3649+
3650+
```
3651+
Stream<T>.isEmpty(): boolean
3652+
```
3653+
3654+
Returns true if iterable source is empty.
3655+
3656+
Returns false if iterable source has one or more elements.
3657+
3658+
```typescript
3659+
import { Stream } from "itertools-ts";
3660+
3661+
const emptyArray = [];
3662+
3663+
Stream.of(emptyArray)
3664+
.isEmpty();
3665+
// true
3666+
3667+
const input = [1];
3668+
3669+
Stream.of(isEmpty)
3670+
.isEmpty();
3671+
// false
3672+
```
3673+
36213674
##### Is Sorted
36223675
Returns true if iterable source is sorted in ascending order; otherwise false.
36233676

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@smoren/itertools-ts",
3-
"version": "2.4.1",
3+
"version": "2.5.0",
44
"license": "MIT",
55
"exports": "./src/index.ts"
66
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "itertools-ts",
3-
"version": "2.4.1",
3+
"version": "2.5.0",
44
"description": "Extended itertools port for TypeScript and JavaScript. Provides a huge set of functions for working with iterable collections (including async ones)",
55
"license": "MIT",
66
"repository": {

src/async-stream.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,15 @@ export class AsyncStream<T> implements AsyncIterable<T> {
937937
return summary.exactlyNAsync(this, n, predicate);
938938
}
939939

940+
/**
941+
* Returns true if given stream is empty.
942+
*
943+
* @see summary.isEmptyAsync
944+
*/
945+
async isEmpty(): Promise<boolean> {
946+
return summary.isEmptyAsync(this);
947+
}
948+
940949
/**
941950
* Returns true if stream is sorted in ascending order; otherwise false.
942951
*

src/stream.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,16 @@ export class Stream<T> implements Iterable<T> {
860860
exactlyN(n: number, predicate?: (item: T) => boolean): boolean {
861861
return summary.exactlyN(this, n, predicate);
862862
}
863+
864+
/**
865+
* Returns true if given stream is empty.
866+
*
867+
* @see summary.isEmpty
868+
*/
869+
isEmpty(): boolean {
870+
return summary.isEmpty(this);
871+
}
872+
863873
/**
864874
* Returns true if stream is sorted in ascending order; otherwise false.
865875
*

tests/async-stream/summary.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ function dataProviderForArraysTrue(): Array<[Array<any>, (iterable: Array<any>)
111111
(iterable: Iterable<unknown | Iterator<unknown>>) => AsyncStream.of(iterable)
112112
.exactlyN(3),
113113
],
114+
[
115+
[],
116+
(iterable: Iterable<number> | Iterator<number>) => AsyncStream.of(iterable)
117+
.isEmpty(),
118+
],
114119
[
115120
[1, -1, 2, -2, 3, -3],
116121
(iterable: Iterable<number> | Iterator<number>) => AsyncStream.of(iterable)
@@ -232,6 +237,11 @@ function dataProviderForStringsTrue(): Array<[string, (iterable: string) => Prom
232237
(iterable) => AsyncStream.of(iterable)
233238
.exactlyN(0),
234239
],
240+
[
241+
'',
242+
(iterable) => AsyncStream.of(iterable)
243+
.isEmpty(),
244+
],
235245
[
236246
'123',
237247
(iterable) => AsyncStream.of(iterable)
@@ -355,6 +365,11 @@ function dataProviderForSetsTrue(): Array<[Set<any>, (iterable: Set<any>) => Pro
355365
(iterable: Set<unknown>) => AsyncStream.of(iterable)
356366
.exactlyN(3),
357367
],
368+
[
369+
new Set([]),
370+
(iterable: Set<number>) => AsyncStream.of(iterable)
371+
.isEmpty(),
372+
],
358373
[
359374
new Set([1, -1, 2, -2, 3, -3]),
360375
(iterable: Set<number>) => AsyncStream.of(iterable)
@@ -458,6 +473,11 @@ function dataProviderForMapsTrue(): Array<[Map<any, any>, (iterable: Map<any, an
458473
(iterable: Map<unknown, number>) => AsyncStream.of(iterable)
459474
.anyMatch((x) => x[1] > 0),
460475
],
476+
[
477+
createMapFixture([]),
478+
(iterable: Map<unknown, number>) => AsyncStream.of(iterable)
479+
.isEmpty(),
480+
],
461481
[
462482
createMapFixture([1, -1, 2, -2, 3, -3]),
463483
(iterable: Map<unknown, number>) => AsyncStream.of(iterable)
@@ -582,6 +602,11 @@ function dataProviderForAsyncTrue(): Array<[Array<any>, (iterable: AsyncIterable
582602
(iterable: AsyncIterable<unknown> | AsyncIterator<unknown>) => AsyncStream.of(iterable)
583603
.exactlyN(3),
584604
],
605+
[
606+
[],
607+
(iterable: AsyncIterable<number> | AsyncIterator<number>) => AsyncStream.of(iterable)
608+
.isEmpty(),
609+
],
585610
[
586611
[1, -1, 2, -2, 3, -3],
587612
(iterable: AsyncIterable<number> | AsyncIterator<number>) => AsyncStream.of(iterable)
@@ -706,6 +731,11 @@ function dataProviderForArraysFalse(): Array<[Array<any>, (iterable: Array<any>)
706731
(iterable: Iterable<unknown>) => AsyncStream.of(iterable)
707732
.exactlyN(4),
708733
],
734+
[
735+
[1],
736+
(iterable: Iterable<number>) => AsyncStream.of(iterable)
737+
.isEmpty(),
738+
],
709739
[
710740
[1, -1, 2, -2, 3, -3],
711741
(iterable: Iterable<number>) => AsyncStream.of(iterable)
@@ -805,6 +835,11 @@ function dataProviderForStringsFalse(): Array<[string, (iterable: string) => Pro
805835
(iterable) => AsyncStream.of(iterable)
806836
.exactlyN(1),
807837
],
838+
[
839+
'1',
840+
(iterable) => AsyncStream.of(iterable)
841+
.isEmpty(),
842+
],
808843
[
809844
'131',
810845
(iterable) => AsyncStream.of(iterable)
@@ -892,6 +927,11 @@ function dataProviderForSetsFalse(): Array<[Set<any>, (iterable: Set<any>) => Pr
892927
(iterable: Set<number>) => AsyncStream.of(iterable)
893928
.exactlyN(4),
894929
],
930+
[
931+
new Set([1]),
932+
(iterable: Set<number>) => AsyncStream.of(iterable)
933+
.isEmpty(),
934+
],
895935
[
896936
new Set([1, -1, 2, -2, 3, -3]),
897937
(iterable: Set<number>) => AsyncStream.of(iterable)
@@ -966,6 +1006,11 @@ function dataProviderForMapsFalse(): Array<[Map<any, any>, (iterable: Map<any, a
9661006
(iterable: Map<unknown, number>) => AsyncStream.of(iterable)
9671007
.anyMatch((x) => x[1] > 10),
9681008
],
1009+
[
1010+
createMapFixture([1]),
1011+
(iterable: Map<unknown, number>) => AsyncStream.of(iterable)
1012+
.isEmpty(),
1013+
],
9691014
[
9701015
createMapFixture([1, -1, 2, -2, 3, -3]),
9711016
(iterable: Map<unknown, number>) => AsyncStream.of(iterable)
@@ -1066,6 +1111,11 @@ function dataProviderForAsyncFalse(): Array<[Array<any>, (iterable: AsyncIterabl
10661111
(iterable: AsyncIterable<unknown> | AsyncIterator<unknown>) => AsyncStream.of(iterable)
10671112
.exactlyN(4),
10681113
],
1114+
[
1115+
[1],
1116+
(iterable: AsyncIterable<number> | AsyncIterator<number>) => AsyncStream.of(iterable)
1117+
.isEmpty(),
1118+
],
10691119
[
10701120
[1, -1, 2, -2, 3, -3],
10711121
(iterable: AsyncIterable<number> | AsyncIterator<number>) => AsyncStream.of(iterable)

tests/stream/summary.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ function dataProviderForArraysTrue(): Array<[Array<any>, (iterable: Array<any>)
9797
(iterable: Iterable<unknown | Iterator<unknown>>) => Stream.of(iterable)
9898
.exactlyN(3),
9999
],
100+
[
101+
[],
102+
(iterable: Iterable<number> | Iterator<number>) => Stream.of(iterable)
103+
.isEmpty(),
104+
],
100105
[
101106
[1, -1, 2, -2, 3, -3],
102107
(iterable: Iterable<number> | Iterator<number>) => Stream.of(iterable)
@@ -218,6 +223,11 @@ function dataProviderForStringsTrue(): Array<[string, (iterable: string) => bool
218223
(iterable) => Stream.of(iterable)
219224
.exactlyN(0),
220225
],
226+
[
227+
'',
228+
(iterable) => Stream.of(iterable)
229+
.isEmpty(),
230+
],
221231
[
222232
'123',
223233
(iterable) => Stream.of(iterable)
@@ -341,6 +351,11 @@ function dataProviderForSetsTrue(): Array<[Set<any>, (iterable: Set<any>) => boo
341351
(iterable: Set<unknown>) => Stream.of(iterable)
342352
.exactlyN(3),
343353
],
354+
[
355+
new Set([]),
356+
(iterable: Set<number>) => Stream.of(iterable)
357+
.isEmpty(),
358+
],
344359
[
345360
new Set([1, -1, 2, -2, 3, -3]),
346361
(iterable: Set<number>) => Stream.of(iterable)
@@ -444,6 +459,11 @@ function dataProviderForMapsTrue(): Array<[Map<any, any>, (iterable: Map<any, an
444459
(iterable: Map<unknown, number>) => Stream.of(iterable)
445460
.anyMatch((x) => x[1] > 0),
446461
],
462+
[
463+
createMapFixture([]),
464+
(iterable: Map<unknown, number>) => Stream.of(iterable)
465+
.isEmpty(),
466+
],
447467
[
448468
createMapFixture([1, -1, 2, -2, 3, -3]),
449469
(iterable: Map<unknown, number>) => Stream.of(iterable)
@@ -547,6 +567,11 @@ function dataProviderForArraysFalse(): Array<[Array<any>, (iterable: Array<any>)
547567
(iterable: Iterable<unknown>) => Stream.of(iterable)
548568
.exactlyN(4),
549569
],
570+
[
571+
[1],
572+
(iterable: Iterable<number>) => Stream.of(iterable)
573+
.isEmpty(),
574+
],
550575
[
551576
[1, -1, 2, -2, 3, -3],
552577
(iterable: Iterable<number>) => Stream.of(iterable)
@@ -646,6 +671,11 @@ function dataProviderForStringsFalse(): Array<[string, (iterable: string) => boo
646671
(iterable) => Stream.of(iterable)
647672
.exactlyN(1),
648673
],
674+
[
675+
'1',
676+
(iterable) => Stream.of(iterable)
677+
.isEmpty(),
678+
],
649679
[
650680
'131',
651681
(iterable) => Stream.of(iterable)
@@ -733,6 +763,11 @@ function dataProviderForSetsFalse(): Array<[Set<any>, (iterable: Set<any>) => bo
733763
(iterable: Set<number>) => Stream.of(iterable)
734764
.exactlyN(4),
735765
],
766+
[
767+
new Set([1]),
768+
(iterable: Set<number>) => Stream.of(iterable)
769+
.isEmpty(),
770+
],
736771
[
737772
new Set([1, -1, 2, -2, 3, -3]),
738773
(iterable: Set<number>) => Stream.of(iterable)
@@ -807,6 +842,11 @@ function dataProviderForMapsFalse(): Array<[Map<any, any>, (iterable: Map<any, a
807842
(iterable: Map<unknown, number>) => Stream.of(iterable)
808843
.anyMatch((x) => x[1] > 10),
809844
],
845+
[
846+
createMapFixture([1]),
847+
(iterable: Map<unknown, number>) => Stream.of(iterable)
848+
.isEmpty(),
849+
],
810850
[
811851
createMapFixture([1, -1, 2, -2, 3, -3]),
812852
(iterable: Map<unknown, number>) => Stream.of(iterable)

0 commit comments

Comments
 (0)