// Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. /*----------------------------------------------------------------------------- | Copyright (c) 2014-2017, PhosphorJS Contributors | | Distributed under the terms of the BSD 3-Clause License. | | The full license is in the file LICENSE, distributed with this software. |----------------------------------------------------------------------------*/ import { IIterator } from './iter'; /** * Create an empty iterator. * * @returns A new iterator which yields nothing. * * #### Example * ```typescript * import { empty, toArray } from '@lumino/algorithm'; * * let stream = empty(); * * toArray(stream); // [] * ``` */ export function empty(): IIterator { return new EmptyIterator(); } /** * An iterator which is always empty. */ export class EmptyIterator implements IIterator { /** * Get an iterator over the object's values. * * @returns An iterator which yields the object's values. */ iter(): IIterator { return this; } /** * Create an independent clone of the iterator. * * @returns A new independent clone of the iterator. */ clone(): IIterator { return new EmptyIterator(); } /** * Get the next value from the iterator. * * @returns The next value from the iterator, or `undefined`. */ next(): T | undefined { return undefined; } }