From 050facc230595601a569190cdd6d9531ba604f9c Mon Sep 17 00:00:00 2001 From: "arvid.nicolaas" Date: Fri, 10 Jun 2022 17:48:52 +0200 Subject: [PATCH] fix(stream): improve Stream and AsyncStream API and fix and extend tsd tests --- .../async-custom/async-stream-custom.ts | 2 +- deno_dist/stream/async-custom/constructors.ts | 16 +- deno_dist/stream/async/interface.ts | 12 ++ deno_dist/stream/main/interface.ts | 37 +++++ .../src/async-custom/async-stream-custom.ts | 2 +- .../stream/src/async-custom/constructors.ts | 16 +- packages/stream/src/async/interface.ts | 12 ++ packages/stream/src/main/interface.ts | 37 +++++ packages/stream/test-d/async-stream.test-d.ts | 148 +++++++++++++++--- packages/stream/test-d/stream.test-d.ts | 107 +++++++++++-- 10 files changed, 335 insertions(+), 54 deletions(-) diff --git a/deno_dist/stream/async-custom/async-stream-custom.ts b/deno_dist/stream/async-custom/async-stream-custom.ts index 2a3959611..af056f3ed 100644 --- a/deno_dist/stream/async-custom/async-stream-custom.ts +++ b/deno_dist/stream/async-custom/async-stream-custom.ts @@ -1731,7 +1731,7 @@ export const AsyncStreamConstructorsImpl: AsyncStreamConstructors = }; }, zip(...sources): any { - return AsyncStreamConstructorsImpl.zipWith(...sources)(Array); + return AsyncStreamConstructorsImpl.zipWith(...(sources as any))(Array); }, zipAllWith(...sources): any { return (fillValue: any, zipFun: any): any => { diff --git a/deno_dist/stream/async-custom/constructors.ts b/deno_dist/stream/async-custom/constructors.ts index 22a68b617..a9db3e7b5 100644 --- a/deno_dist/stream/async-custom/constructors.ts +++ b/deno_dist/stream/async-custom/constructors.ts @@ -35,10 +35,10 @@ export interface AsyncStreamConstructors { * ``` * @note ends the AsyncStream when any of the given streams ends */ - zipWith( + zipWith( ...sources: { [K in keyof I]: AsyncStreamSource.NonEmpty } & unknown[] ): (zipFun: (...values: I) => R) => AsyncStream.NonEmpty; - zipWith( + zipWith( ...sources: { [K in keyof I]: AsyncStreamSource } & unknown[] ): (zipFun: (...values: I) => R) => AsyncStream; /** @@ -55,10 +55,10 @@ export interface AsyncStreamConstructors { * ``` * @note ends the AsyncStream when any of the given streams ends */ - zip( + zip( ...sources: { [K in keyof I]: AsyncStreamSource.NonEmpty } & unknown[] ): AsyncStream.NonEmpty; - zip( + zip( ...sources: { [K in keyof I]: AsyncStreamSource } & unknown[] ): AsyncStream; /** @@ -80,13 +80,13 @@ export interface AsyncStreamConstructors { * // => [10, 13, 5] * ``` */ - zipAllWith( + zipAllWith( ...sources: { [K in keyof I]: AsyncStreamSource.NonEmpty } & unknown[] ): ( fillValue: AsyncOptLazy, zipFun: (...values: { [K in keyof I]: I[K] | O }) => MaybePromise ) => AsyncStream.NonEmpty; - zipAllWith( + zipAllWith( ...sources: { [K in keyof I]: AsyncStreamSource } & unknown[] ): ( fillValue: AsyncOptLazy, @@ -110,11 +110,11 @@ export interface AsyncStreamConstructors { * ``` * @note ends the AsyncStream when any of the given streams ends */ - zipAll( + zipAll( fillValue: AsyncOptLazy, ...sources: { [K in keyof I]: AsyncStreamSource.NonEmpty } & unknown[] ): AsyncStream.NonEmpty<{ [K in keyof I]: I[K] | O }>; - zipAll( + zipAll( fillValue: AsyncOptLazy, ...sources: { [K in keyof I]: AsyncStreamSource } & unknown[] ): AsyncStream<{ [K in keyof I]: I[K] | O }>; diff --git a/deno_dist/stream/async/interface.ts b/deno_dist/stream/async/interface.ts index c80a8b1e5..a826bb1cc 100644 --- a/deno_dist/stream/async/interface.ts +++ b/deno_dist/stream/async/interface.ts @@ -1237,6 +1237,18 @@ export namespace AsyncStream { start?: AsyncStreamSource; end?: AsyncStreamSource; }): AsyncStream.NonEmpty; + /** + * Returns a non-empty AsyncStream containing non-repetitive elements of the source stream, where repetitive elements + * are compared using the optionally given `eq` equality function. + * @param eq - (default: `Eq.objectIs`) the `Eq` instance to use to test equality of elements + * @example + * ```ts + * await AsyncStream.of(1, 1, 2, 2, 3, 1).distinctPrevious().toArray() + * // => [1, 2, 3, 1] + * ``` + */ + distinctPrevious(eq?: Eq): AsyncStream.NonEmpty; + /** * Returns an AsyncStream containing the values resulting from applying the given the given `next` function to a current state (initially the given `init` value), * and the next stream value, and returning the new state. diff --git a/deno_dist/stream/main/interface.ts b/deno_dist/stream/main/interface.ts index 083c841dd..8792c2c0b 100644 --- a/deno_dist/stream/main/interface.ts +++ b/deno_dist/stream/main/interface.ts @@ -1182,6 +1182,43 @@ export namespace Stream { start?: StreamSource; end?: StreamSource; }): Stream.NonEmpty; + /** + * Returns a non-empty Stream containing non-repetitive elements of the source stream, where repetitive elements + * are compared using the optionally given `eq` equality function. + * @param eq - the `Eq` instance to use to test equality of elements + * @example + * ```ts + * Stream.of(1, 1, 2, 2, 3, 1).distinctPrevious().toArray() + * // => [1, 2, 3, 1] + * ``` + */ + distinctPrevious(eq?: Eq): Stream.NonEmpty; + /** + * Returns a Stream containing the values resulting from applying the given the given `next` function to a current state (initially the given `init` value), + * and the next Stream value, and returning the new state. + * @typeparam R - the resulting element type + * @param init - the initial result/state value + * @param next - a function taking the parameters below and returning the new result/state value
+ * - current: the current result/state value, initially `init`.
+ * - value: the next Stream value
+ * - index: the index of the given value
+ * - halt: a function that, if called, ensures that no new elements are passed + * @example + * ```ts + * console.log( + * Stream.empty() + * .foldStream(5, (current, value) => current + value) + * .toArray() + * ) + * // => [] + * console.log( + * Stream.of(1, 2, 3) + * .foldStream(5, (current, value) => current + value) + * .toArray() + * ) + * // => [6, 8, 11] + * ``` + */ foldStream( init: OptLazy, next: (current: R, value: T, index: number) => R diff --git a/packages/stream/src/async-custom/async-stream-custom.ts b/packages/stream/src/async-custom/async-stream-custom.ts index 972101866..65a26a46e 100644 --- a/packages/stream/src/async-custom/async-stream-custom.ts +++ b/packages/stream/src/async-custom/async-stream-custom.ts @@ -1731,7 +1731,7 @@ export const AsyncStreamConstructorsImpl: AsyncStreamConstructors = }; }, zip(...sources): any { - return AsyncStreamConstructorsImpl.zipWith(...sources)(Array); + return AsyncStreamConstructorsImpl.zipWith(...(sources as any))(Array); }, zipAllWith(...sources): any { return (fillValue: any, zipFun: any): any => { diff --git a/packages/stream/src/async-custom/constructors.ts b/packages/stream/src/async-custom/constructors.ts index 625b3cadc..695a457b4 100644 --- a/packages/stream/src/async-custom/constructors.ts +++ b/packages/stream/src/async-custom/constructors.ts @@ -35,10 +35,10 @@ export interface AsyncStreamConstructors { * ``` * @note ends the AsyncStream when any of the given streams ends */ - zipWith( + zipWith( ...sources: { [K in keyof I]: AsyncStreamSource.NonEmpty } & unknown[] ): (zipFun: (...values: I) => R) => AsyncStream.NonEmpty; - zipWith( + zipWith( ...sources: { [K in keyof I]: AsyncStreamSource } & unknown[] ): (zipFun: (...values: I) => R) => AsyncStream; /** @@ -55,10 +55,10 @@ export interface AsyncStreamConstructors { * ``` * @note ends the AsyncStream when any of the given streams ends */ - zip( + zip( ...sources: { [K in keyof I]: AsyncStreamSource.NonEmpty } & unknown[] ): AsyncStream.NonEmpty; - zip( + zip( ...sources: { [K in keyof I]: AsyncStreamSource } & unknown[] ): AsyncStream; /** @@ -80,13 +80,13 @@ export interface AsyncStreamConstructors { * // => [10, 13, 5] * ``` */ - zipAllWith( + zipAllWith( ...sources: { [K in keyof I]: AsyncStreamSource.NonEmpty } & unknown[] ): ( fillValue: AsyncOptLazy, zipFun: (...values: { [K in keyof I]: I[K] | O }) => MaybePromise ) => AsyncStream.NonEmpty; - zipAllWith( + zipAllWith( ...sources: { [K in keyof I]: AsyncStreamSource } & unknown[] ): ( fillValue: AsyncOptLazy, @@ -110,11 +110,11 @@ export interface AsyncStreamConstructors { * ``` * @note ends the AsyncStream when any of the given streams ends */ - zipAll( + zipAll( fillValue: AsyncOptLazy, ...sources: { [K in keyof I]: AsyncStreamSource.NonEmpty } & unknown[] ): AsyncStream.NonEmpty<{ [K in keyof I]: I[K] | O }>; - zipAll( + zipAll( fillValue: AsyncOptLazy, ...sources: { [K in keyof I]: AsyncStreamSource } & unknown[] ): AsyncStream<{ [K in keyof I]: I[K] | O }>; diff --git a/packages/stream/src/async/interface.ts b/packages/stream/src/async/interface.ts index 0b50c88a7..f32e354a9 100644 --- a/packages/stream/src/async/interface.ts +++ b/packages/stream/src/async/interface.ts @@ -1237,6 +1237,18 @@ export namespace AsyncStream { start?: AsyncStreamSource; end?: AsyncStreamSource; }): AsyncStream.NonEmpty; + /** + * Returns a non-empty AsyncStream containing non-repetitive elements of the source stream, where repetitive elements + * are compared using the optionally given `eq` equality function. + * @param eq - (default: `Eq.objectIs`) the `Eq` instance to use to test equality of elements + * @example + * ```ts + * await AsyncStream.of(1, 1, 2, 2, 3, 1).distinctPrevious().toArray() + * // => [1, 2, 3, 1] + * ``` + */ + distinctPrevious(eq?: Eq): AsyncStream.NonEmpty; + /** * Returns an AsyncStream containing the values resulting from applying the given the given `next` function to a current state (initially the given `init` value), * and the next stream value, and returning the new state. diff --git a/packages/stream/src/main/interface.ts b/packages/stream/src/main/interface.ts index b85a8bb7f..e1fa72e34 100644 --- a/packages/stream/src/main/interface.ts +++ b/packages/stream/src/main/interface.ts @@ -1182,6 +1182,43 @@ export namespace Stream { start?: StreamSource; end?: StreamSource; }): Stream.NonEmpty; + /** + * Returns a non-empty Stream containing non-repetitive elements of the source stream, where repetitive elements + * are compared using the optionally given `eq` equality function. + * @param eq - the `Eq` instance to use to test equality of elements + * @example + * ```ts + * Stream.of(1, 1, 2, 2, 3, 1).distinctPrevious().toArray() + * // => [1, 2, 3, 1] + * ``` + */ + distinctPrevious(eq?: Eq): Stream.NonEmpty; + /** + * Returns a Stream containing the values resulting from applying the given the given `next` function to a current state (initially the given `init` value), + * and the next Stream value, and returning the new state. + * @typeparam R - the resulting element type + * @param init - the initial result/state value + * @param next - a function taking the parameters below and returning the new result/state value
+ * - current: the current result/state value, initially `init`.
+ * - value: the next Stream value
+ * - index: the index of the given value
+ * - halt: a function that, if called, ensures that no new elements are passed + * @example + * ```ts + * console.log( + * Stream.empty() + * .foldStream(5, (current, value) => current + value) + * .toArray() + * ) + * // => [] + * console.log( + * Stream.of(1, 2, 3) + * .foldStream(5, (current, value) => current + value) + * .toArray() + * ) + * // => [6, 8, 11] + * ``` + */ foldStream( init: OptLazy, next: (current: R, value: T, index: number) => R diff --git a/packages/stream/test-d/async-stream.test-d.ts b/packages/stream/test-d/async-stream.test-d.ts index 9d1d30a36..cdc925ae3 100644 --- a/packages/stream/test-d/async-stream.test-d.ts +++ b/packages/stream/test-d/async-stream.test-d.ts @@ -1,4 +1,4 @@ -import { ArrayNonEmpty, AsyncReducer, Reducer } from '@rimbu/common'; +import { ArrayNonEmpty, AsyncReducer } from '@rimbu/common'; import { expectAssignable, expectError, @@ -6,8 +6,12 @@ import { expectNotType, expectType, } from 'tsd'; -import { AsyncFastIterator, AsyncStream } from '@rimbu/stream/async'; -import { Stream } from '@rimbu/stream'; +import { + AsyncFastIterator, + AsyncStream, + AsyncTransformer, +} from '@rimbu/stream/async'; +import type { Stream } from '@rimbu/stream'; // Variance expectAssignable>(AsyncStream.empty()); @@ -20,9 +24,11 @@ expectAssignable>(AsyncStream.of(1)); // Iterable expectType>( - AsyncStream.empty()[Symbol.iterator]() + AsyncStream.empty()[Symbol.asyncIterator]() +); +expectType>( + AsyncStream.of(1)[Symbol.asyncIterator]() ); -expectType>(AsyncStream.of(1)[Symbol.iterator]()); // AsyncStream.empty() expectType>(AsyncStream.empty()); @@ -115,6 +121,7 @@ expectType>( expectType>( AsyncStream.zipAll(true, AsyncStream.of(1)) ); +expectError(AsyncStream.zipAll(true)); // TODO // expectType>( @@ -155,7 +162,7 @@ expectType>( expectError(AsyncStream.zipWith()); -// // AsyncStream.zipAllWith() +// AsyncStream.zipAllWith() expectType>( AsyncStream.zipAllWith( AsyncStream.empty(), @@ -195,6 +202,26 @@ expectType>( AsyncStream.of(1 as number | string).append('a') ); +// .count() +expectType(await AsyncStream.empty().count()); +expectType(await AsyncStream.of(1).count()); + +// .countElement(..) +expectType(await AsyncStream.empty().countElement(1)); +expectType(await AsyncStream.of(1).countElement(1)); + +// .countNotElement(..) +expectType(await AsyncStream.empty().countNotElement(1)); +expectType(await AsyncStream.of(1).countNotElement(1)); + +// .contains(..) +expectType(await AsyncStream.empty().contains(1)); +expectType(await AsyncStream.of(1).contains(1)); + +// .containsSlice(..) +expectType(await AsyncStream.empty().containsSlice([1])); +expectType(await AsyncStream.of(1).containsSlice([1])); + // .collect(..) expectType>(AsyncStream.empty().collect(() => '')); expectType>(AsyncStream.of(1).collect(() => '')); @@ -249,10 +276,26 @@ expectType( ); // .filter(..) +expectType>(AsyncStream.empty().filter(() => true)); +expectType>(AsyncStream.of(1).filter(() => true)); + +// .filterNot(..) expectType>( - AsyncStream.empty().filter((v) => true) + AsyncStream.empty().filterNot(() => true) ); -expectType>(AsyncStream.of(1).filter(() => true)); +expectType>(AsyncStream.of(1).filterNot(() => true)); + +// .filterPure(..) +expectType>( + AsyncStream.empty().filterPure(() => true) +); +expectType>(AsyncStream.of(1).filterPure(() => true)); + +// .filterNotPure(..) +expectType>( + AsyncStream.empty().filterNotPure(() => true) +); +expectType>(AsyncStream.of(1).filterNotPure(() => true)); // .find(..) expectType( @@ -294,6 +337,14 @@ expectType( await AsyncStream.empty().first('a' as string) ); +// .forEach(..) +expectType(await AsyncStream.empty().forEach(() => {})); +expectType(await AsyncStream.of(1).forEach(() => {})); + +// .forEachPure(..) +expectType(await AsyncStream.empty().forEachPure(() => {})); +expectType(await AsyncStream.of(1).forEachPure(() => {})); + // .flatMap(..) expectType>( AsyncStream.empty().flatMap(() => AsyncStream.empty()) @@ -319,29 +370,34 @@ expectType>( AsyncStream.of(1).flatZip((v) => [String(v)]) ); -// .flatReducerStream(..) +// .transform(..) expectType>( - AsyncStream.empty().flatReduceStream( - null as unknown as AsyncReducer> + AsyncStream.empty().transform( + null as unknown as AsyncTransformer ) ); expectType>( - AsyncStream.empty().flatReduceStream( - null as unknown as AsyncReducer> + AsyncStream.empty().transform( + null as unknown as AsyncTransformer.NonEmpty ) ); expectType>( - AsyncStream.of(1).flatReduceStream( - null as unknown as AsyncReducer> + AsyncStream.of(1).transform( + null as unknown as AsyncTransformer ) ); expectType>( - AsyncStream.of(1).flatReduceStream( - null as unknown as AsyncReducer> + AsyncStream.of(1).transform( + null as unknown as AsyncTransformer.NonEmpty + ) +); +expectType>( + AsyncStream.of(1).transform( + null as unknown as AsyncReducer> ) ); expectType>( - AsyncStream.of(1).flatReduceStream( + AsyncStream.of(1).transform( null as unknown as AsyncReducer> ) ); @@ -372,6 +428,10 @@ expectType>( AsyncStream.of(1).foldStream('a', () => 'b') ); +// .distinctPrevious(..) +expectType>(AsyncStream.empty().distinctPrevious()); +expectType>(AsyncStream.of(1).distinctPrevious()); + // .indexed() expectType>( AsyncStream.empty().indexed() @@ -380,9 +440,19 @@ expectType>( AsyncStream.of('a').indexed() ); -// .indicesOf(..) -expectType>(AsyncStream.empty().indicesOf('b')); -expectType>(AsyncStream.of('a').indicesOf('b')); +// .indexOf(..) +expectType(await AsyncStream.empty().indexOf('b')); +expectType(await AsyncStream.of('a').indexOf('b')); + +// .indexOf(..) +expectType(await AsyncStream.empty().indexOf('b')); +expectType(await AsyncStream.of('a').indexOf('b')); + +// .indicesWhere(..) +expectType>( + AsyncStream.empty().indicesWhere(() => true) +); +expectType>(AsyncStream.of('a').indicesWhere(() => true)); // .indicesWhere(..) expectType>( @@ -415,10 +485,30 @@ expectType( await AsyncStream.empty().last('a' as string) ); +// .single(...) +expectType(await AsyncStream.empty().single()); +expectType(await AsyncStream.empty().single(1)); +expectType(await AsyncStream.empty().single('a')); +expectType(await AsyncStream.of(1, 2, 3).single()); +expectType(await AsyncStream.of(1, 2, 3).single(1)); +expectType(await AsyncStream.of(1, 2, 3).single('a')); + // .map(..) expectType>(AsyncStream.empty().map(() => 'a')); expectType>(AsyncStream.of(1).map(() => 'a')); +// .mapPure(..) +expectType>(AsyncStream.empty().mapPure(() => 'a')); +expectType>(AsyncStream.of(1).mapPure(() => 'a')); + +// .some(..) +expectType(await AsyncStream.empty().some(() => true)); +expectType(await AsyncStream.of(1).some(() => true)); + +// .every(..) +expectType(await AsyncStream.empty().every(() => true)); +expectType(await AsyncStream.of(1).every(() => true)); + // .max(..) expectType(await AsyncStream.empty().max()); expectError(AsyncStream.of(1).max(3)); @@ -467,7 +557,7 @@ expectType( await AsyncStream.empty().minBy(() => 0, 'a' as string) ); -// // .mkGroup(..) +// .mkGroup(..) expectType>(AsyncStream.empty().mkGroup({})); expectType>(AsyncStream.of(1).mkGroup({})); @@ -519,6 +609,10 @@ expectType>( ); expectType>(AsyncStream.of(1).prepend(3)); +// .join(..) +expectType(await AsyncStream.empty().join()); +expectType(await AsyncStream.of(1, 2, 3).join()); + // .reduce(..) expectType( await AsyncStream.empty().reduce(AsyncReducer.isEmpty) @@ -546,12 +640,12 @@ expectType>( AsyncStream.empty().reduceAllStream( AsyncReducer.isEmpty, AsyncReducer.sum, - ASyncReducer.join() + AsyncReducer.join() ) ); expectType>( AsyncStream.of(1).reduceAllStream( - ASyncReducer.isEmpty, + AsyncReducer.isEmpty, AsyncReducer.sum, AsyncReducer.join() ) @@ -581,7 +675,7 @@ expectType>( ); expectType>(AsyncStream.of(1).splitWhere(() => true)); -// .stream() +// .asyncStream() expectType>(AsyncStream.empty().asyncStream()); expectType>(AsyncStream.of(1).asyncStream()); @@ -599,3 +693,7 @@ expectType>(AsyncStream.of(1).takeWhile(() => true)); // .toArray() expectType(await AsyncStream.empty().toArray()); expectType>(await AsyncStream.of(1).toArray()); + +// .equals() +expectType(await AsyncStream.empty().equals([1, 2])); +expectType(await AsyncStream.of(1, 2).equals([1, 2])); diff --git a/packages/stream/test-d/stream.test-d.ts b/packages/stream/test-d/stream.test-d.ts index daf507d49..8ba3578d6 100644 --- a/packages/stream/test-d/stream.test-d.ts +++ b/packages/stream/test-d/stream.test-d.ts @@ -6,7 +6,7 @@ import { expectNotType, expectType, } from 'tsd'; -import { FastIterator, Stream } from '@rimbu/stream'; +import { FastIterator, Stream, Transformer } from '@rimbu/stream'; // Variance expectAssignable>(Stream.empty()); @@ -127,7 +127,7 @@ expectType>( expectError(Stream.zipAll(true)); -// // Stream.zipWith(..) +// Stream.zipWith(..) expectType>( Stream.zipWith( Stream.empty(), @@ -148,7 +148,7 @@ expectType>(Stream.zipWith(Stream.of(1))((a) => [a])); expectError(Stream.zipWith()); -// // Stream.zipAllWith() +// Stream.zipAllWith() expectType>( Stream.zipAllWith(Stream.empty(), Stream.empty())( true, @@ -227,10 +227,30 @@ expectType( Stream.empty().elementAt(1, () => '' as string) ); +// .forEach(..) +expectType(Stream.empty().forEach(() => {})); +expectType(Stream.of(1).forEach(() => {})); + +// .forEachPure(..) +expectType(Stream.empty().forEachPure(() => {})); +expectType(Stream.of(1).forEachPure(() => {})); + // .filter(..) expectType>(Stream.empty().filter((v) => true)); expectType>(Stream.of(1).filter(() => true)); +// .filterNot(..) +expectType>(Stream.empty().filterNot((v) => true)); +expectType>(Stream.of(1).filterNot(() => true)); + +// .filterPure(..) +expectType>(Stream.empty().filterPure((v) => true)); +expectType>(Stream.of(1).filterPure(() => true)); + +// .filterNotPure(..) +expectType>(Stream.empty().filterNotPure((v) => true)); +expectType>(Stream.of(1).filterNotPure(() => true)); + // .find(..) expectType(Stream.empty().find(() => true)); expectType(Stream.empty().find(() => true, 1)); @@ -265,6 +285,14 @@ expectType(Stream.empty().first(1)); expectType(Stream.of(1).first()); expectType(Stream.empty().first('a' as string)); +// .single(..) +expectType(Stream.empty().single()); +expectType(Stream.empty().single(1)); +expectType(Stream.empty().single('a' as string)); +expectType(Stream.of(1).single()); +expectType(Stream.of(1).single(1)); +expectType(Stream.of(1).single('a' as string)); + // .flatMap(..) expectType>( Stream.empty().flatMap(() => Stream.empty()) @@ -284,20 +312,23 @@ expectType>( Stream.of(1).flatZip((v) => [String(v)]) ); -// .flatReducerStream(..) +// .transform(..) expectType>( - Stream.empty().flatReduceStream( - null as unknown as Reducer> + Stream.empty().transform( + null as unknown as Transformer ) ); expectType>( - Stream.of(1).flatReduceStream( - null as unknown as Reducer> + Stream.empty().transform( + null as unknown as Transformer.NonEmpty ) ); +expectType>( + Stream.of(1).transform(null as unknown as Transformer) +); expectType>( - Stream.of(1).flatReduceStream( - null as unknown as Reducer> + Stream.of(1).transform( + null as unknown as Transformer.NonEmpty ) ); @@ -325,6 +356,14 @@ expectType>(Stream.of(1).foldStream('a', () => 'b')); expectType>(Stream.empty().indexed()); expectType>(Stream.of('a').indexed()); +// .indexWhere(..) +expectType(Stream.empty().indexWhere(() => true)); +expectType(Stream.of(1).indexWhere(() => true)); + +// .indexOf(..) +expectType(Stream.empty().indexOf(2)); +expectType(Stream.of(1).indexOf(2)); + // .indicesOf(..) expectType>(Stream.empty().indicesOf('b')); expectType>(Stream.of('a').indicesOf('b')); @@ -333,6 +372,24 @@ expectType>(Stream.of('a').indicesOf('b')); expectType>(Stream.empty().indicesWhere(() => true)); expectType>(Stream.of('a').indicesWhere(() => true)); +// .some(..) +expectType(Stream.empty().some(() => true)); +expectType(Stream.of('a').some(() => true)); + +// .every(..) +expectType(Stream.empty().every(() => true)); +expectType(Stream.of('a').every(() => true)); + +// .contains(..) +expectType(Stream.empty().contains(2)); +expectType(Stream.of(1).contains(2)); +expectError(Stream.of(1).contains('a')); + +// .containsSlice(..) +expectType(Stream.empty().containsSlice([2])); +expectType(Stream.of(1).containsSlice([2])); +expectError(Stream.of(1).containsSlice(['a'])); + // .intersperse(..) expectType>( Stream.empty().intersperse(Stream.empty()) @@ -356,6 +413,10 @@ expectType(Stream.empty().last('a' as string)); expectType>(Stream.empty().map(() => 'a')); expectType>(Stream.of(1).map(() => 'a')); +// .mapPure(..) +expectType>(Stream.empty().mapPure(() => 'a')); +expectType>(Stream.of(1).mapPure(() => 'a')); + // .max(..) expectType(Stream.empty().max()); expectError(Stream.of(1).max(3)); @@ -400,7 +461,7 @@ expectType( Stream.empty().minBy(() => 0, 'a' as string) ); -// // .mkGroup(..) +// .mkGroup(..) expectType>(Stream.empty().mkGroup({})); expectType>(Stream.of(1).mkGroup({})); @@ -510,3 +571,27 @@ expectType>(Stream.of(1).takeWhile(() => true)); // .toArray() expectType(Stream.empty().toArray()); expectType>(Stream.of(1).toArray()); + +// .equals(..) +expectType(Stream.empty().equals([1])); +expectType(Stream.of(1).equals([1])); + +// .count() +expectType(Stream.empty().count()); +expectType(Stream.of(1).count()); + +// .countElement(..) +expectType(Stream.empty().countElement(1)); +expectType(Stream.of(1).countElement(1)); + +// .countNotElement(..) +expectType(Stream.empty().countNotElement(1)); +expectType(Stream.of(1).countNotElement(1)); + +// .join(..) +expectType(Stream.empty().join()); +expectType(Stream.of(1).join()); + +// .distinctPrevious(..) +expectType>(Stream.empty().distinctPrevious()); +expectType>(Stream.of(1).distinctPrevious());