Skip to content

Commit

Permalink
Reimplement empty() with native iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
afshin committed Aug 11, 2022
1 parent e9e35c5 commit 2a43121
Showing 1 changed file with 5 additions and 37 deletions.
42 changes: 5 additions & 37 deletions packages/algorithm/src/empty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
import { IIterator } from './iter';

/**
* Create an empty iterator.
Expand All @@ -16,45 +15,14 @@ import { IIterator } from './iter';
*
* #### Example
* ```typescript
* import { empty, toArray } from '@lumino/algorithm';
* import { empty } from '@lumino/algorithm';
*
* let stream = empty<number>();
*
* toArray(stream); // []
* Array.from(stream); // []
* ```
*/
export function empty<T>(): IIterator<T> {
return new EmptyIterator<T>();
}

/**
* An iterator which is always empty.
*/
export class EmptyIterator<T> implements IIterator<T> {
/**
* Get an iterator over the object's values.
*
* @returns An iterator which yields the object's values.
*/
iter(): IIterator<T> {
return this;
}

/**
* Create an independent clone of the iterator.
*
* @returns A new independent clone of the iterator.
*/
clone(): IIterator<T> {
return new EmptyIterator<T>();
}

/**
* Get the next value from the iterator.
*
* @returns The next value from the iterator, or `undefined`.
*/
next(): T | undefined {
return undefined;
}
// eslint-disable-next-line require-yield, @typescript-eslint/no-unused-vars
export function* empty<T>() {
return;
}

0 comments on commit 2a43121

Please sign in to comment.