View race-spec.ts
'use strict';
import * as test from 'tape';
import { of } from '../../dist/cjs/asynciterable/of';
import { race } from '../../dist/cjs/asynciterable/race';
import { hasNext, noNext } from '../asynciterablehelpers';
function delayValue<T>(value: T, time: number) {
return new Promise<T>(resolve => setTimeout(() => resolve(value), time));
}
View example.ts
const EventEmitter = require('events').EventEmitter;
const fromEventPattern = require('ix/asynciterable/fromeventpattern').fromEventPattern;
// Get Async Iterable
const e = new EventEmitter();
const ai = fromEventPattern(
h => e.addListener('data', h),
h => e.removeListener('data', h)
);
View ofentries.ts
'use strict';
import { IterableX } from '../iterable';
import { map } from './map';
function makeTuple<TFirst, TSecond>(x: TFirst, y: TSecond): [TFirst, TSecond] {
return [x, y];
}
class OfEntriesIterable<TSource> extends IterableX<[string, TSource]> {
View mapasync.ts
'use strict';
import { AsyncIterableX } from '../asynciterable';
import { bindCallback } from '../internal/bindcallback';
class MapAsyncIterable<TSource, TResult> extends AsyncIterableX<TResult> {
private _source: AsyncIterable<TSource>;
private _selector: (value: TSource, index: number) => Promise<TResult> | TResult;
constructor(
View asyncfuncs.ts
'use strict';
import { mapAsync } from 'ix/async/mapasync';
import { filterAsync } from 'ix/async/filterasync';
const source = filterAsync(
mapAsync([1, 2, 3, 4, 5], async x => x * x),
async x => x % 3 === 0
);
View mapasync.ts
'use strict';
class MapAsyncIterable<T, R> implements AsyncIterable<R> {
private _source: Iterable<T | PromiseLike<T>> | AsyncIterable<T>;
private _selector: (value: T) => Promise<R> | R;
constructor(
source: Iterable<T | PromiseLike<T>> | AsyncIterable<T>,
selector: (value: T) => Promise<R> | R) {
this._source = source;
View mapasync.ts
'use strict';
class MapAsyncIterable<T, R> implements AsyncIterable<R> {
private _source: Iterable<T>;
private _selector: (value: T) => Promise<R>;
constructor(source: Iterable<T>, selector: (value: T) => Promise<R>) {
this._source = source;
this._selector = selector;
}
View range-spec.ts
import * as test from 'tape';
import { elementAt } from '../../dist/cjs/iterable/elementat';
import { first } from '../../dist/cjs/iterable/first';
import { isEmpty } from '../../dist/cjs/iterable/isempty';
import { last } from '../../dist/cjs/iterable/last';
import { range } from '../../dist/cjs/iterable/range';
import { sequenceEqual } from '../../dist/cjs/iterable/sequenceEqual';
import { skip } from '../../dist/cjs/iterable/skip';
import { take } from '../../dist/cjs/iterable/take';
import { toArray } from '../../dist/cjs/iterable/toarray';
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[]>;