GeezerVison is showing graup.github.io — pythonic-ts
Functions
defaultdict
- defaultdict<T, K>(factory: () => T): Record<K, T>
-
Create an object which calls a factory function when a non-existing key is accessed.
Type parameters
Parameters
Returns Record<K, T>
enumerate
- enumerate<T>(iterator: T[] | Iterable<T>): Iterable<[number, T]>
groupBy
- groupBy<T, K>(collection: readonly T[], iteratee: (obj: T) => K): Map<K, T[]>
-
Creates a Map composed of keys generated from the results of running
each element of collection through iteratee. The corresponding value of
each key is a list of all elements responsible for generating the key. The
iteratee is invoked with one argument: (value).
To convert the result to an object, use Object.fromEntries(groupBy(...)).
const array = [6.1, 4.2, 6.3];
groupBy(array, Math.floor)
// => [6, [6.1, 6.3]], [4, [4.2]]
Type parameters
Parameters
-
collection: readonly T[]
-
iteratee: (obj: T) => K
Returns Map<K, T[]>
keyBy
- keyBy<T, K>(collection: readonly T[], iteratee: (obj: T) => K): Map<K, T>
-
Creates a Map composed of keys generated from the results of running
each element of collection through iteratee. The corresponding value of
each key is the last element responsible for generating the key. The
iteratee is invoked with one argument: (value).
To convert to an object, use Object.fromEntries(keyBy(...)).
const array = [
{ 'id': '1', 'code': 97 },
{ 'id': '2', 'code': 100 }
]
keyBy(array, ({ id }) => id)
// => [['1', { 'id': '1', 'code': 97 }], ['2', { 'id': '2', 'code': 100 }]
Type parameters
Parameters
-
collection: readonly T[]
-
iteratee: (obj: T) => K
Returns Map<K, T>
lazyItemGetter
- lazyItemGetter<T>(generator: Generator<T>): (index: number) => T
-
A lazy iterator that evaluates the given generator only as far as needed
and caches the results to return an item at index
Type parameters
Parameters
Returns (index: number) => T
mapIterator
- mapIterator<T, T2>(iterator: Iterable<T>, callbackFn: (val: T, idx: number) => T2): Iterable<T2>
-
Type parameters
Parameters
-
iterator: Iterable<T>
-
callbackFn: (val: T, idx: number) => T2
-
- (val: T, idx: number): T2
Returns Iterable<T2>
permutations
- permutations<T>(input: readonly T[]): Iterable<T[]>
-
Type parameters
Parameters
Returns Iterable<T[]>
product
- product<T>(...iterables: Iterableify<T>): Generator<T>
-
Cartesian product of input iterables.
Roughly equivalent to nested for-loops in a generator expression.
const z = product([1, 2, 3], [true, false]);
Array.from(z) //=> [[1, true], [2, true], [3, true], [1, false], [2, false], [3, false]]
Source: based on https://gist.github.com/cybercase/db7dde901d7070c98c48#gistcomment-3033459
Type parameters
Parameters
-
Rest ...iterables: Iterableify<T>
Returns Generator<T>
range
- range(stop: number): RangeIterator
- range(start: number, stop: number): RangeIterator
- range(start: number, stop: number, step: number): RangeIterator
repeat
- repeat<T>(item: T, times?: number): Generator<T>
-
Iterator that repeats item times number of times.
When times is undefined, repeats indefinitely.
Type parameters
Parameters
-
item: T
-
Optional times: number
Returns Generator<T>
take
- take<T>(generator: IterableIterator<T>, n: number): T[]
-
Takes n items from iterator by calling next() n times and returns
an array of items. Stops iterating when iterator is exhausted.
Type parameters
Parameters
-
generator: IterableIterator<T>
-
n: number
Returns T[]
zip
- zip<T>(...toZip: Iterableify<T>): Generator<T>
-
const z = zip([1, 2, 3], 'abc');
Array.from(z) //=> [[1, 'a'], [2, 'b'], [3, 'c']]
Type parameters
Parameters
-
Rest ...toZip: Iterableify<T>
Returns Generator<T>
|