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++);
}
}
View flatten.ts
function *flatten<T>(iterable: Iterable<T>, depth: number = Infinity): Iterable<T> {
if (depth === 0) { return iterable; }
for (let item of iterable) {
if (typeof item[Symbol.iterator] === 'function') {
yield *flatten(item, depth - 1);
} else {
yield item;
}
}
View li.js
function createTag(tag) {
return function applyTag (list) {
return list.map(x => `<${tag}>${x}</${tag}>`).join('');
}
}
var tagged = createTag('li');
var appled = tagged([1,2,3]);
View startwith.ts
'use strict';
import { IIterable } from '../iterable.interfaces';
import { ConcatIterable } from './concat';
export function startWith<T>(
source: IIterable<T>,
...args: IIterable<T>[]) {
return new ConcatIterable(...args.concat(source));
}
View reduce.js
sequence.reduce((arr, item) => arr.concat(formatForMS(item), [])
View onerrorresumenext.ts
'use strict';
import { IIterable, IIterator } from '../iterable.interfaces';
import { Iterable } from '../iterable';
import { Iterator } from '../iterator';
import { ArrayIterator } from './arrayiterable';
export class OnErrorResumeNextIterator<T> extends Iterator<T> {
private _it: IIterator<T>;
private _innerIt: IIterator<T>;
View zip.ts
'use strict';
import { IIterable, IIterator } from '../iterable.interfaces';
import { Iterable } from '../iterable';
import { Iterator } from '../iterator';
import { MapIterable } from './map';
export class ZipIterator<T> extends Iterator<T> {
private _it: IIterator<T>[];
View zip.ts
'use strict';
import { IIterable, IIterator } from '../iterable.interfaces';
import { Iterable } from '../iterable';
import { Iterator } from '../iterator';
import { MapIterable } from './map';
export class ZipIterator<T> extends Iterator<T> {
private _it: IIterator<T>[];
View finally.ts
'use strict';
import { IIterable, IIterator } from '../iterable.interfaces';
import { Iterable } from '../iterable';
import { Iterator } from '../iterator';
export class FinallyIterator<T> extends Iterator<T> {
private _it: IIterator<T>;
private _fn: () => void;
private _called: boolean;
View fold.js
'use strict';
let arr = [1,2,3,4,5];
let fn = (acc, x) => {
console.log(`${acc}-${x}`);
return acc * x;
};
let seed = 1;
/*