View tomap.ts
'use strict';
export function toMap<TSource, TKey>(
source: Iterable<TSource>,
keySelector: (item: TSource) => TKey): Map<TKey, TSource>;
export function toMap<TSource, TKey, TElement = TSource>(
source: Iterable<TSource>,
keySelector: (item: TSource) => TKey,
elementSelector?: (item: TSource) => TElement): Map<TKey, TElement> {
let map = new Map<TKey, TElement | TSource>();
View reduce.ts
'use strict';
export async function reduce<T>(
source: AsyncIterable<T>,
accumulator: (acc: T, value: T, index: number) => T,
seed?: T): Promise<T>;
export async function reduce<T>(
source: AsyncIterable<T>,
accumulator: (acc: T[], value: T, index: number) => T[],
seed?: T[]): Promise<T[]>;
View onErrorResumeNext.ts
'use strict';
function* _onErrorResumeNext<TSource>(source: Iterable<Iterable<TSource>>): Iterable<TSource> {
for (let item of source) {
let it = item[Symbol.iterator]();
while (1) {
let next;
try {
next = it.next();
} catch (e) {
View catch.ts
import { IterableX } from '../../iterable';
import { _catchStatic as catchStatic } from '../../iterable/catch';
function _catchStatic<T>(...args: Iterable<T>[]) {
return new IterableX<T>(catchStatic<T>(...args));
}
IterableX.catch = _catchStatic;
declare module '../../iterable' {
View if.ts
import { IterableX } from '../../iterable';
import { _if as ifStatic } from '../../iterable/if';
function* _if<T>(
fn: () => boolean,
thenSource: Iterable<T>,
elseSource: Iterable<T>) {
return new IterableX(ifStatic(fn, thenSource, elseSource));
}
View zip.ts
'use strict';
import { map } from './map';
function* _zip<T>(source: Iterable<T>[]): Iterable<T[]> {
for (let i = 0; i < source.length; i++) {
let its = source.map(x => x[Symbol.iterator]());
let nexts = its.map(it => it.next());
if (nexts.every(next => !next.done)) {
yield nexts.map(next => next.value);
View flattenasync.ts
'use strict';
import { isAsyncIterable } from '../internal/isasynciterable';
export async function *flattenAsync<T>(iterable: AsyncIterable<T>, depth: number = Infinity): AsyncIterable<T> {
if (depth === 0) { return iterable; }
for await (let item of iterable) {
if (isAsyncIterable(item)) {
yield *flattenAsync(item, depth - 1);
} else {
View flatmap.ts
'use strict';
import { bindCallback } from '../internal/bindcallback';
export async function *flatMapAsync<TSource, TResult>(
source: AsyncIterable<TSource>,
fn: (value: TSource) => AsyncIterable<TResult>,
thisArg?: any): AsyncIterable<TResult> {
let sel = bindCallback(fn, thisArg, 1);
for await (let outerItem of source) {
View buffer.ts
'use strict';
export function* buffer<TSource>(
source: Iterable<TSource>,
count: number,
skip?: number): Iterable<TSource[]> {
if (skip == null) { skip = count; }
let buffers: TSource[][] = [], i = 0;
for (let item of source)
{
View foreachasync.ts
async function forEach<T>(iterable: AsyncIterable<T>, fn: (value: T, index: number) => void, thisArg?: any): Promise<void> {
const fun = fn.bind(thisArg);
let i = 0;
for await (let item of iterable) {
fun(item, i++);
}
}