itertools

package
v0.0.0-...-99fdc18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2013 License: BSD-2-Clause Imports: 0 Imported by: 0

Documentation

Overview

itertools is a (limited) port of Python's itertools module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(iterables ...[]int) []int

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

func Combinations(iterable []int, r int) [][]int

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

func Compress(data, selectors []int) []int

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

func Count(start, stop, step int) []int

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

func Cycle(iterable []int, n int) []int

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

func DropWhile(predicate func(int) bool, iterable []int) []int

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

func IFilter(predicate func(int) bool, iterable []int) []int

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

func IFilterFalse(predicate func(int) bool, iterable []int) []int

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

func IZip(iterables ...[]int) [][]int

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

func IZipLongest(fillvalue int, iterables ...[]int) [][]int

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

func Product(args ...[]int) [][]int

Product returns the cartesian product of input iterables.

Product([]int{1, 2}, []int{3, 4}) -> [[1 3] [1 4] [2 3] [2 4]]

func Repeat

func Repeat(element, n int) []int

Repeat returns a slice with element repeated n times.

Repeat(10, 5) -> [10 10 10 10 10]

func TakeWhile

func TakeWhile(predicate func(int) bool, iterable []int) []int

TakeWhile returns elements from the iterable as long as the predicate is true.

TakeWhile(is_odd, []int{1, 3, 2, 4, 5, 7, 6, 8}) -> [1, 3]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL