Documentation
¶
Overview ¶
itertools is a (limited) port of Python's itertools module.
Index ¶
- func Chain(iterables ...[]int) []int
- func Combinations(iterable []int, r int) [][]int
- func Compress(data, selectors []int) []int
- func Count(start, stop, step int) []int
- func Cycle(iterable []int, n int) []int
- func DropWhile(predicate func(int) bool, iterable []int) []int
- func IFilter(predicate func(int) bool, iterable []int) []int
- func IFilterFalse(predicate func(int) bool, iterable []int) []int
- func IZip(iterables ...[]int) [][]int
- func IZipLongest(fillvalue int, iterables ...[]int) [][]int
- func Permutations(iterable []interface{}, r int) [][]interface{}
- func Product(args ...[]int) [][]int
- func Repeat(element, n int) []int
- func TakeWhile(predicate func(int) bool, iterable []int) []int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
Chain returns a slice consisting of the elements within iterables.
Used for treating consecutive sequences as a single sequence.
Chain([]int{1, 2, 3}, []int{4, 5, 6}) -> [1 2 3 4 5 6]
func Combinations ¶
Combinations returns r length subsquences of elements from iterable.
Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat values in each combination.
Combinations([]int{1, 2, 3, 4, 5}, 4) -> [[1 2 3 4] [1 2 3 5] [1 2 4 5] [1 3 4 5] [2 3 4 5]]
func Compress ¶
Compress returns a slice based on data compressed by selectors.
Elements in data are included in the returned slice if they have a correspondig element in selectors that is greater than 0. Stops when either the data or selectors iterables has been exhausted.
Compress([]int{1, 2, 3}, []int{0, 1, 1}) -> [2 3]
func Count ¶
Count returns a slice with step-spaced values from the range beginning with start and ending before stop.
Count(1, 10, 1) -> [1 2 3 4 5 6 7 8 9]
func Cycle ¶
Cycle returns a slice with values from iterable, repeating elements until n elements can be returned.
Cycle([]int{1, 2, 3, 4}, 6) -> [1 2 3 4 1 2]
func DropWhile ¶
DropWhile drops elements from the iterable as long as the predicate is true; afterwards, returns every element.
DropWhile(is_odd, []int{1, 3, 2, 4, 5, 7, 6, 8}) -> [2 4 5 7 6 8]
func IFilter ¶
IFilter filters elements from the iterable returning only those for which the predicate is true. If predicate is nil, returns the elements that are greater than 0.
IFilter(is_odd, []int{1, 3, 2, 4, 5, 7, 6, 8}) -> [1 3 5 7] IFilter(nil, []int{-2, -1, 0, 1, 2} -> [1 2]
func IFilterFalse ¶
IFilterFalse filters elements from the iterable returning only those for which the predicate is false. If predicate is nil, returns the elements that are less than or equal to 0.
IFilterFalse(is_odd, []int{1, 3, 2, 4, 5, 7, 6, 8}) -> [2 4 6 8] IFilterFalse(nil, []int{-2, -1, 0, 1, 2}) -> [-2 -1 0]
func IZip ¶
IZip aggregates elements from each of the iterables.
IZip should only be used with unequal length inputs when you don't care about trailing unmatched values from the longer iterables. If those values are important, use IZipLongest() instead.
IZip([]int{10, 20, 30}, []int{1, 2, 3}) -> [[10 1] [20 2] [30 3]]
func IZipLongest ¶
IZipLongest aggregates elements from each of the iterables.
If the iterables are of uneven length, missing values are filled-in with fillvalue. Iteration continues until the longest iterable is exhausted.
IZipLongest(0, []int{10, 20, 30}, []int{1, 2}) -> [[10 1] [20 2] [30 0]]
func Permutations ¶
func Permutations(iterable []interface{}, r int) [][]interface{}
Permutations returns sucessive r length permutations of elements from iterable.
Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeat values in each permutation.
Permutations([]int{1, 2, 3}, 3) -> [[1 2 3] [1 3 2] [2 1 3] [2 3 1] [3 1 2] [3 2 1]]
func Product ¶
Product returns the cartesian product of input iterables.
Product([]int{1, 2}, []int{3, 4}) -> [[1 3] [1 4] [2 3] [2 4]]
Types ¶
This section is empty.