This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Iterable arrays chain, extended for "getLength" and "at" accessor. | |
*/ | |
export interface IArraysChain<T> extends RelativeIndexable<T>, Iterable<T> { | |
/** | |
* Calculates total length of all input arrays combined. | |
*/ | |
getLength(): number; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retry-status object type, for use with RetryCB. | |
*/ | |
export type RetryStatus = { | |
/** | |
* Retry index, starting from 0. | |
*/ | |
index: number, | |
/** | |
* Retry overall duration, in milliseconds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Observable, switchMap} from 'rxjs'; | |
/** | |
* Spike detection result. | |
*/ | |
export interface ISpike { | |
/** | |
* Detected spike change, in percent. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type basicType<T> = T extends 'string' ? string : | |
T extends 'number' ? number : | |
T extends 'boolean' ? boolean : | |
T extends 'bigint' ? bigint : | |
never; | |
function removeByType<T, A>(input: T[], t1: keyof A): Exclude<T, basicType<typeof t1>>[]; | |
function removeByType<T, A, B>(input: T[], t1: keyof A, t2: keyof B): Exclude<T, basicType<typeof t1 | typeof t2>>[]; | |
function removeByType<T, A, B, C>(input: T[], t1: keyof A, t2: keyof B, t3: keyof C): Exclude<T, basicType<typeof t1 | typeof t2 | typeof t3>>[]; | |
function removeByType<T, A, B, C, D>(input: T[], t1: keyof A, t2: keyof B, t3: keyof C, t4: keyof D): Exclude<T, basicType<typeof t1 | typeof t2 | typeof t3 | typeof t4>>[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Pool} from 'pg'; // or from 'pg-pool' | |
import {QueryIterable, QueryIterablePool} from 'pg-iterator'; | |
import {from, finalize, Observable} from 'rxjs'; | |
const pool = new Pool({/* connection details */}); | |
// RxJs helper for completing queries safely: | |
function fromQuery<T>(qi: QueryIterable<T>, text: string, params?: any[]): Observable<T> { | |
return from(qi.query(text, params)).pipe(finalize(() => qi.release())); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {aggregate, reduce, skip, take, distinct, map, Operation, tap} from 'iter-ops'; | |
/////////////////////////////////////////////////////////////////////////////// | |
// Collection of custom operators for "iter-ops", made from existing operators, | |
// as implementation examples + ideas (these are not part of the library). | |
/////////////////////////////////////////////////////////////////////////////// | |
/** | |
* Logs values into the console. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {pipe, reduce} from 'iter-ops'; | |
const m = new Map<string, number>(); | |
m.set('one', 1); | |
m.set('two', 2); | |
m.set('three', 3); | |
const i = pipe(m.values(), reduce((a, c) => a + c, 5)); | |
console.log(...i); //=> 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {pipe, reduce} from 'iter-ops'; | |
const m = new Map<string, number>(); | |
m.set('one', 1); | |
m.set('two', 2); | |
m.set('three', 3); | |
const i = pipe(m.values(), reduce((a, c) => a + c)); | |
console.log(...i); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {pipeAsync, map, waitRace, delay} from 'iter-ops'; | |
const i = pipeAsync( | |
[1, 2, 3], | |
map(s => Promise.resolve(s * 10)), | |
delay(100), | |
waitRace(3) | |
); | |
(async function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////// | |
// RUN THIS FIRST: npm install iter-ops@2.2.0-beta.0 | |
// | |
// The example below crashes NodeJS (it runs out of memory) | |
// operator source: https://github.com/vitaly-t/iter-ops/blob/wait-cache/src/ops/async/wait-cache.ts | |
////////////////// | |
import {map, pipeAsync, waitCache} from 'iter-ops'; |
NewerOlder