Options
All
  • Public
  • Public/Protected
  • All
Menu

Module iter

Callable

  • iter<E>(iterable: Iterable<E>, ...iterables: Iterable<E>[]): Iter<E>
  • Returns an Iter yielding items from a list of iterables

    Type parameters

    • E

      The type of elements the Iterable yields.

    Parameters

    • iterable: Iterable<E>

      the source iterable

    • Rest ...iterables: Iterable<E>[]

      other iterables to concatenate

    Returns Iter<E>

Index

Variables

Const collector

collector: Op = Op

Const nats

nats: Iter<number> = generate(0, v => v + 1)

Returns an Iter yielding all natural numbers starting from 0.

example
iter.nats
result: (0, 1, 2, 3, ...)

Const ops

ops: ops = opsCollectors

Const symbols

symbols: Iter<symbol> = fromLazy(Symbol).repeat()

Returns an Iter yielding infinite unique Symbols.

example
const [X_AXIS, Y_AXIS, Z_AXIS] = iter.symbols

Functions

arrayEntries

  • arrayEntries<E>(arr: E[]): Iter<[number, E]>
  • Returns an Iter yielding the array entries from array.entries()

    Type parameters

    • E

      The array element type

    Parameters

    • arr: E[]

      the source array

    Returns Iter<[number, E]>

empty

  • empty<T>(): Iter<T>

flatten

  • flatten<E>(iterable: Iterable<Iterable<E>>): Iter<E>
  • Returns an Iter that yields the values from each nested Iterable in the given Iterable.

    example
    iter.flatten(iter.of(iter.of(1, 3)), iter.of(iter.of (2, 4)))
    result: (1, 3, 2, 4)

    Type parameters

    • E

      the element type that the iterables of the given iterable yield.

    Parameters

    • iterable: Iterable<Iterable<E>>

      the source iterable of iterables

    Returns Iter<E>

fromIterator

  • fromIterator<E>(createIterator: function): Iter<E>
  • Returns an Iter yielding items from an iterator

    Type parameters

    • E

      The type of elements the Iterator yields.

    Parameters

    • createIterator: function

      a function creating a new iterator

        • (): Iterator<E>
        • Returns Iterator<E>

    Returns Iter<E>

fromLazy

  • fromLazy<E>(create: function): Iter<E>
  • Returns an Iter yielding a single element the is created lazily when the item is requested.

    example
    iter.fromLazy(Math.random)
    result: (0.243442)

    Type parameters

    • E

      the type of the element that is created

    Parameters

    • create: function

      A function that lazily creates an element to yield

        • (): E
        • Returns E

    Returns Iter<E>

generate

  • generate<E>(init: E, next: function): Iter<E>
  • Returns an Iter yielding a potentially infinite sequence of elements using a generation function

    example
    iter.generate(2, v => v * v)
    result: (2, 4, 16, 256, ...)

    Type parameters

    • E

      The type of elements the Iter yields.

    Parameters

    • init: E

      The initial value to yield.

    • next: function

      Function the returns the optional next value to yield based on the current value and its index.

        • (current: E, index: number): E | undefined
        • Parameters

          • current: E
          • index: number

          Returns E | undefined

    Returns Iter<E>

indexedBounce

  • Returns an Iter that yields the values from the source input of length N from index 0 to N-1, and then from N-2 downto 1.

    example
    iter.indexedBounce('abc')
    result: ('a', 'b', 'c', 'b' )

    Type parameters

    • E

      the element type of the source

    Parameters

    • input: Indexed<E>

      a source string or array of elements

    Returns Iter<E>

indexedReversed

  • Returns an Iter that yields the values from the source input in reversed order

    example
    iter.indexedReversed('abc')
    result: ('c', 'b', 'a')

    Type parameters

    • E

      the element type of the source

    Parameters

    • input: Indexed<E>

      a source string or array of elements

    Returns Iter<E>

mapEntries

  • mapEntries<K, V>(map: Map<K, V>): Iter<[K, V]>
  • Returns an Iter yielding the map entries from map.entries()

    Type parameters

    • K

      the map key type

    • V

      the map value type

    Parameters

    • map: Map<K, V>

      the source map

    Returns Iter<[K, V]>

mapKeys

  • mapKeys<K>(map: Map<K, any>): Iter<K>
  • Returns an Iter yielding the map keys from map.keys()

    Type parameters

    • K

      the map key type

    Parameters

    • map: Map<K, any>

      the source map

    Returns Iter<K>

mapValues

  • mapValues<V>(map: Map<any, V>): Iter<V>
  • Returns an Iter yielding the map keys from map.keys()

    Type parameters

    • V

      the map value type

    Parameters

    • map: Map<any, V>

      the source map

    Returns Iter<V>

objectEntries

  • objectEntries<T>(obj: T): Iter<[keyof T, T[keyof T]]>
  • Returns an Iter yielding the object entries as tuples of type [string, any]

    Type parameters

    • T: __type

    Parameters

    • obj: T

      the source object

    Returns Iter<[keyof T, T[keyof T]]>

objectKeys

  • objectKeys<T>(obj: T): Iter<keyof T>
  • Returns an Iter yielding the object keys as strings

    Type parameters

    • T: __type

    Parameters

    • obj: T

      the source object

    Returns Iter<keyof T>

objectValues

  • objectValues<V>(obj: Record<any, V>): Iter<V>
  • Returns an Iter yielding the object values

    Type parameters

    • V

    Parameters

    • obj: Record<any, V>

      the source object

    Returns Iter<V>

of

  • Returns an Iter instance yielding the given elements.

    example
    iter.of(1, 3, 5)
    result: (1, 3, 5)

    Type parameters

    • E

      The type of elements the Iter instance can yield.

    Parameters

    • Rest ...elems: NonEmpty<E>

      the source elements

    Returns Iter<E>

random

  • random(min?: number, max?: number): Iter<number>
  • Returns an Iter yielding a random floating point number between min and max

    example
    iter.random()
    result: (0.5234)
    example
    iter.random(10, 20).repeat()
    result: (17.3541, 12.1324, 18.4243, ...)

    Parameters

    • Default value min: number = 0

      the minimum value

    • Default value max: number = 1

      the maximum value

    Returns Iter<number>

randomInt

  • randomInt(min?: number, max?: number): Iter<number>
  • Returns an Iter yielding a random integer between min and max

    example
    iter.randomInt()
    result: (535984)
    example
    iter.randomInt(0, 10).repeat()
    result: (8, 2, 5, 3, 5, 1, 7, ...)

    Parameters

    • Default value min: number = Number.MIN_VALUE

      the minimum value

    • Default value max: number = Number.MAX_VALUE

      the maximum value

    Returns Iter<number>

range

  • range(from: number, until?: undefined | number, step?: number): Iter<number>
  • Returns an Iter yielding values in a range from the from value, until the until value if specified, increasing by step.

    example
    iter.range(10, 50, 10)
    result: (10, 20, 30, 40)
    example
    iter.range(50, 0, -10)
    result: (50, 40, 30, 20, 10)
    example
    iter.range(0, undefined, 3)
    result: (0, 3, 6, 9, ...)

    Parameters

    • from: number

      the start value of the range

    • Optional until: undefined | number

      (optional) the end value of the range

    • Default value step: number = 1

      the step size

    Returns Iter<number>

unfold

  • unfold<S, E>(init: S, next: function): Iter<E>
  • Returns an Iter yielding a potentially infinite sequence of elements using an unfolding function

    example
    iter.unfold(1, s => ['a'.repeat(s), s * 2])
    result: ('a', 'aa', 'aaaa', 'aaaaaaaa', ...)

    Type parameters

    • S

      the internal 'state' of the unfolding function

    • E

      the type of elements the Iter yields.

    Parameters

    • init: S

      The initial internal 'state' of the unfolding function

    • next: function

      A function taking the current state, and returning an optional tuple containing the element to yield and the next state.

        • (currentState: S, index: number): [E, S] | undefined
        • Parameters

          • currentState: S
          • index: number

          Returns [E, S] | undefined

    Returns Iter<E>

Generated using TypeDoc