src/vs/base/common/iterator.ts
194 LOC · 138 covered · 56 uncovered · 58 ranges · 20961 concepts · 23 introducers · 12741 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
map.ts ×97
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { isIterable } from './types.js';
export namespace Iterable {
export function is<T = unknown>(thing: unknown): thing is Iterable<T> {
return !!thing && typeof thing === 'object' && typeof (thing as Iterable<T>)[Symbol.iterator] === 'function';
iterator.ts ×1
}
const _empty: Iterable<never> = Object.freeze([]);
export function empty<T = never>(): readonly never[] {
}
export function* single<T>(element: T): Iterable<T> {
}
export function wrap<T>(iterableOrElement: Iterable<T> | T): Iterable<T> {
return iterableOrElement;
} else {
return single(iterableOrElement);
}
}
export function from<T>(iterable: Iterable<T> | undefined | null): Iterable<T> {
return iterable ?? (_empty as Iterable<T>);
}
export function* reverse<T>(array: ReadonlyArray<T>): Iterable<T> {
for (let i = array.length - 1; i >= 0; i--) {
yield array[i];
}
}
export function isEmpty<T>(iterable: Iterable<T> | undefined | null): boolean {
return !iterable || iterable[Symbol.iterator]().next().done === true;
}
export function first<T>(iterable: Iterable<T>): T | undefined {
}
export function some<T>(iterable: Iterable<T>, predicate: (t: T, i: number) => unknown): boolean {
for (const element of iterable) {
}
}
export function every<T>(iterable: Iterable<T>, predicate: (t: T, i: number) => unknown): boolean {
for (const element of iterable) {
if (!predicate(element, i++)) {
return false;
}
}
return true;
}
export function find<T, R extends T>(iterable: Iterable<T>, predicate: (t: T) => t is R): R | undefined;
export function find<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): T | undefined;
export function find<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): T | undefined {
for (const element of iterable) {
if (predicate(element)) {
return element;
}
}
return undefined;
}
export function filter<T, R extends T>(iterable: Iterable<T>, predicate: (t: T) => t is R): Iterable<R>;
export function filter<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): Iterable<T>;
export function* filter<T>(iterable: Iterable<T>, predicate: (t: T) => boolean): Iterable<T> {
yield element;
}
}
export function* map<T, R>(iterable: Iterable<T>, fn: (t: T, index: number) => R): Iterable<R> {
for (const element of iterable) {
}
export function* flatMap<T, R>(iterable: Iterable<T>, fn: (t: T, index: number) => Iterable<R>): Iterable<R> {
let index = 0;
for (const element of iterable) {
yield* fn(element, index++);
}
}
export function* concat<T>(...iterables: (Iterable<T> | T)[]): Iterable<T> {
if (isIterable(item)) {
yield* item;
} else {
yield item;
}
}
export function reduce<T, R>(iterable: Iterable<T>, reducer: (previousValue: R, currentValue: T) => R, initialValue: R): R {
for (const element of iterable) {
}
}
export function length<T>(iterable: Iterable<T>): number {
let count = 0;
for (const _ of iterable) {
count++;
}
return count;
}
/**
* Returns an iterable slice of the array, with the same semantics as `array.slice()`.
*/
export function* slice<T>(arr: ReadonlyArray<T>, from: number, to = arr.length): Iterable<T> {
from = 0;
}
from += arr.length;
}
if (to < 0) {
to += arr.length;
to = arr.length;
}
for (; from < to; from++) {
}
/**
* Consumes `atMost` elements from iterable and returns the consumed elements,
* and an iterable for the rest of the elements.
*/
export function consume<T>(iterable: Iterable<T>, atMost: number = Number.POSITIVE_INFINITY): [T[], Iterable<T>] {
const consumed: T[] = [];
if (atMost === 0) {
return [consumed, iterable];
}
const iterator = iterable[Symbol.iterator]();
for (let i = 0; i < atMost; i++) {
const next = iterator.next();
if (next.done) {
return [consumed, Iterable.empty()];
}
consumed.push(next.value);
}
return [consumed, { [Symbol.iterator]() { return iterator; } }];
}
export async function asyncToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {
for await (const item of iterable) {
}
export async function asyncToArrayFlat<T>(iterable: AsyncIterable<T[]>): Promise<T[]> {
for await (const item of iterable) {
}
return result;