File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -59,14 +59,16 @@ export function* readArray<T>(
5959 }
6060}
6161
62+ const sentinel = Symbol ( ) ;
63+
6264export function * ensureSortedSet < T > (
6365 iterable : Iterable < T > ,
6466 comparator : ( a : T , b : T ) => number ,
6567) : Generator < T > {
66- let previous : T | null = null ;
68+ let previous : T | typeof sentinel = sentinel ;
6769
6870 for ( const element of iterable ) {
69- if ( previous != null && comparator ( element , previous ) < = 0 ) {
71+ if ( previous !== sentinel && comparator ( previous , element ) > = 0 ) {
7072 throw new Error ( "iterable is not a sorted set." ) ;
7173 }
7274
@@ -79,10 +81,10 @@ export async function* ensureSortedSetAsync<T>(
7981 iterable : AsyncIterable < T > | Iterable < T > ,
8082 comparator : ( a : T , b : T ) => number ,
8183) : AsyncGenerator < T > {
82- let previous : T | null = null ;
84+ let previous : T | typeof sentinel = sentinel ;
8385
8486 for await ( const element of iterable ) {
85- if ( previous != null && comparator ( element , previous ) < = 0 ) {
87+ if ( previous !== sentinel && comparator ( previous , element ) > = 0 ) {
8688 throw new Error ( "async-iterable is not a sorted set." ) ;
8789 }
8890
You can’t perform that action at this time.
0 commit comments