Options
All
  • Public
  • Public/Protected
  • All
Menu

pythonic-ts

Index

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

    • T

    • K: string = string

    Parameters

    • factory: () => T
        • (): T
        • Returns T

    Returns Record<K, T>

enumerate

  • enumerate<T>(iterator: T[] | Iterable<T>): Iterable<[number, T]>
  • Enumerate an iterable. In the case of arrays, enumerate(array) is equivalent to array.entries().

    Type parameters

    • T

    Parameters

    • iterator: T[] | Iterable<T>

    Returns Iterable<[number, T]>

    iterator of [index, item] tuples

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

    • T

      collection item

    • K

      group by key

    Parameters

    • collection: readonly T[]
    • iteratee: (obj: T) => K
        • (obj: T): K
        • Parameters

          • obj: T

          Returns 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

    • T

      collection item

    • K

      group by key

    Parameters

    • collection: readonly T[]
    • iteratee: (obj: T) => K
        • (obj: T): K
        • Parameters

          • obj: T

          Returns 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

    • T

    Parameters

    • generator: Generator<T>

    Returns (index: number) => T

      • (index: number): T
      • Parameters

        • index: number

        Returns T

mapIterator

  • mapIterator<T, T2>(iterator: Iterable<T>, callbackFn: (val: T, idx: number) => T2): Iterable<T2>
  • Type parameters

    • T

    • T2

    Parameters

    • iterator: Iterable<T>
    • callbackFn: (val: T, idx: number) => T2
        • (val: T, idx: number): T2
        • Parameters

          • val: T
          • idx: number

          Returns T2

    Returns Iterable<T2>

permutations

  • permutations<T>(input: readonly T[]): Iterable<T[]>

product

  • product<T>(...iterables: Iterableify<T>): Generator<T>

range

  • range(stop: number): RangeIterator
  • range(start: number, stop: number): RangeIterator
  • range(start: number, stop: number, step: number): RangeIterator
  • Returns an iterator of numbers and is commonly used for looping a specific number of times in for loops. The API is the same as Python's range.

    Parameters

    • stop: number

    Returns RangeIterator

    iterable iterator over range

  • Parameters

    • start: number
    • stop: number

    Returns RangeIterator

  • Parameters

    • start: number
    • stop: number
    • step: number

    Returns 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

    • T

    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

    • T

    Parameters

    • generator: IterableIterator<T>
    • n: number

    Returns T[]

zip

  • zip<T>(...toZip: Iterableify<T>): Generator<T>

Generated using TypeDoc