Module iterate

Types

Iterator*[T] = (iterator (): T)
  Source Edit
Iterable*[T] = Iterator[T] | seq[T]
  Source Edit

Procs

proc items*[T](s: Iterator[T]): Iterator[T]
  Source Edit
proc next*[T](i: Iterator[T]): Option[T]
Advances the iterator and return next item or none[T] if there are no more items.   Source Edit
proc unzip*[A, B](i: Iterator[tuple[a: A, b: B]]): tuple[a: seq[A], b: seq[B]]
Returns (i[0].a, i[1].a, ...), (i[0].b, i[1].b, ...)   Source Edit
proc dropWhile*[T](i: Iterable[T]; f: proc (t: T): bool): T {.
multifuncIterator
.}
Skips longest sequence of elements of this iterator for which f returns true.   Source Edit
proc takeWhile*[T](i: Iterable[T]; f: proc (t: T): bool): T {.
multifuncIterator
.}
Returns longest sequence of elements for which f returns true.   Source Edit
proc filter*[T](i: Iterable[T]; f: proc (t: T): bool): T {.
multifuncIterator
.}
Returns items for which f returns true.   Source Edit
proc reversed*[T](s: seq[T]): seq[T]
  Source Edit
proc all*(i: Iterable[bool]): bool
Returns true iff all items in i are true.   Source Edit
proc someTrue*(i: Iterable[bool]): bool
Returns true iff some item in i is true.   Source Edit
proc sorted*[T](i: Iterable[T]): seq[T]
  Source Edit
proc findOne*[T](i: Iterable[T]; function: (proc (t: T): bool)): Option[T]
  Source Edit
proc argmax*[T](s: seq[T]): int
  Source Edit

Iterators

iterator items*[T](i: Iterator[T]): T
Iterate over closure iterator.   Source Edit
iterator flatten*[T](coll: Iterator[seq[T]]): T {.
multifuncIterator
.}
Flattens iterator e.g. [[1, 2], [3, 4], [5, 6]] == [1, 2, 3, 4, 5, 6]   Source Edit
iterator grouping*[T](it: Iterator[T]; n: int; discardLast = false): seq[T] {.
multifuncIterator
.}
Partitions the iterator into iterator that returns n-item sequences of consecutive items. Last sequence may contain less items if discardLast is true else they will be discarded.   Source Edit
iterator map*[T, R](coll: Iterable[T]; f: (proc (item: T): R)): R {.
multifuncIterator
.}
  Source Edit
iterator flatMap*[T, R](coll: seq[T]; f: (proc (item: T): seq[R])): R {.
multifuncIterator
.}
  Source Edit
iterator range*(start: int; `end`: int; step: int = 1): int {.
multifuncIterator
.}
  Source Edit
iterator range*(`end`: int): int {.
multifuncIterator
.}
  Source Edit
iterator zip*[A, B](a: Iterable[A]; b: Iterable[B]): tuple[a: A, b: B] {.
multifuncIterator
.}
Returns (a[0], b[0]), (a[1], b[1]), ...   Source Edit

Converters

converter toSeq*[T](s: Iterable[T]): seq[T]
  Source Edit

Macros

macro multifuncIterator*(b): untyped

Iterator that is closure and inline at the same time, depending on the context.

Example:

iterator foo(): int {.multifuncIterator.} =
  yield 5

```

  Source Edit

Templates

template wrapIterable*(typ): untyped
Creates closure version of items for type that already has inline version.   Source Edit
template iteratorToSeq*(iter: untyped): expr
  Source Edit