Itertools is a Go package that provides many of the same high-order functions from the Python standard library.
Next, we see the different types of high-order functions provided by Itertools. High-order functions provide the vocabulary for the declarative coding style.
Infinite iterator creators:
Count(i)
: Infinite count fromi
Cycle(iter)
: Infinite cycling ofiter
(requires memory)Repeat(element [, n])
: Repeat the elementn
times (or infinitely)
Iterator destroyers:
Reduce(iter, reducer, memo)
: Reduce (or Foldl) across the iteratorList(iter)
: Create a list from the iterator
Iterator modifiers:
Chain(iters...)
: Chain together multiple iterators.DropWhile(predicate, iter)
: Drop elements until predicate(el) == false.TakeWhile(predicate, iter)
: Take elements until predicate(el) == false.Filter(predicate, iter)
: Filter out elements when predicate(el) == false.FilterFalse(predicate, iter)
: Filter out elements when predicate(el) == true.Slice(iter, start[, stop[, step]])
: Drop elements until...