Something went wrong. Try again.
Showcasing the power of iterators
Something went wrong. Try again.
iterator-power itertools
5 files
README.md
itertools #
A collection of Iterator functions inspired by Python's itertools module,
adapted to the conventions of Go.
| Python | Go | Description |
|---|---|---|
count(start=0) |
Count[N Number](start N) iter.Seq[N] |
Yield numbers from start, incrementing by 1, without end. |
count(start=0, step=1) |
CountStep[N Number](start, step N) iter.Seq[N] |
Yield numbers from start, incrementing by step, without end. |
repeat(object) |
RepeatForever[T any](v T) iter.Seq[T] |
Yield the same value over and over, without end. |
repeat(object, times) |
Repeat[T any](v T, times int) iter.Seq[T] |
Yield the same value times times, then stop. |
islice(iterable, stop) |
Take[T any](n int, seq iter.Seq[T]) iter.Seq[T] |
Yield the first n items of the source sequence, then stop. |
cycle(iterable) |
Cycle[T any](seq iter.Seq[T]) iter.Seq[T] |
Yield the values of seq, saving a copy, then repeat them endlessly. |
chain(*iterables) |
Chain[T any](seqs ...iter.Seq[T]) iter.Seq[T] |
Yield the values of each sequence in turn, exhausting one before starting the next. |
filter(predicate, iterable) |
Filter[T any](predicate func(T) bool, seq iter.Seq[T]) iter.Seq[T] |
Yield only the values of seq for which predicate returns true. |
References #
slices.Filterwas rejected in 2021: proposal: slices: new package to provide generic slice functions (discussion) (comment: Update, July 21 2021). Wrapping up the discussion, Russ Cox wrote: "Deleted Map, Filter, Reduce (probably better as part of a more comprehensive streams API somewhere else)". This package is a contribution to that future streams API.- Rob Pike killed
slices.Filteragain in 2023: Proposal: add generic Filter to slices package