Documentation
¶
Overview ¶
The iterable package provides several traversal and searching methods. It can be used on anything that satisfies the Iterable interface, including vector, though certain functions, such as Map, can also be used on something that would produce an infinite amount of data.
Index ¶
- func All(iter Iterable, f func(interface{}) bool) bool
- func Any(iter Iterable, f func(interface{}) bool) bool
- func Data(iter Iterable) []interface{}
- func Find(iter Iterable, f func(interface{}) bool) interface{}
- func Inject(iter Iterable, initial interface{}, f Injector) interface{}
- func Partition(iter Iterable, f func(interface{}) bool) (Iterable, Iterable)
- type ByteArray
- type FloatArray
- type Group
- type Grouper
- type Injector
- type IntArray
- type Iterable
- func Chain(args []Iterable) Iterable
- func Cycle(iter Iterable) Iterable
- func Drop(iter Iterable, n int) Iterable
- func DropWhile(iter Iterable, f func(interface{}) bool) Iterable
- func Filter(iter Iterable, f func(interface{}) bool) Iterable
- func GroupBy(iter Iterable, k Grouper) Iterable
- func Map(iter Iterable, f func(interface{}) interface{}) Iterable
- func Repeat(v interface{}) Iterable
- func RepeatTimes(v interface{}, n int) Iterable
- func Slice(iter Iterable, start, stop int) Iterable
- func Take(iter Iterable, n int) Iterable
- func TakeWhile(iter Iterable, f func(interface{}) bool) Iterable
- func Unique(iter Iterable, id Grouper) Iterable
- func Zip(args []Iterable) Iterable
- func ZipWith2(f func(c, d interface{}) interface{}, a, b Iterable) Iterable
- func ZipWith3(f func(d, e, f interface{}) interface{}, a, b, c Iterable) Iterable
- type StringArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Data ¶
func Data(iter Iterable) []interface{}
Data returns a slice containing the elements of iter.
func Find ¶
Find returns the first element of iter that satisfies f. Returns nil if no such element is found.
func Inject ¶
Inject combines the elements of iter by repeatedly calling f with an accumulated value and each element in order. The starting accumulated value is initial, and after each call the accumulated value is set to the return value of f. For instance, to compute a sum:
var arr IntArray = []int{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; sum := iterable.Inject(arr, 0, func(ax interface {}, x interface {}) interface {} { return ax.(int) + x.(int) }).(int)
Types ¶
type FloatArray ¶
type FloatArray []float
func (FloatArray) Iter ¶
func (a FloatArray) Iter() <-chan interface{}
type Group ¶
type Group struct { Key interface{} // key value for matching items Vals Iterable // Iterable for receiving values in the group }
Group is the type for elements returned by the GroupBy function.
type Grouper ¶
type Grouper interface { // Return the key for the given value Key(interface{}) interface{} // Compute equality for the given keys Equal(a, b interface{}) bool }
Key defines the interface required by the GroupBy function.
type Injector ¶
type Injector func(interface{}, interface{}) interface{}
Injector is a type representing a function that takes two arguments, an accumulated value and an element, and returns the next accumulated value. See the Inject function.
type Iterable ¶
type Iterable interface {
// Iter should return a fresh channel each time it is called.
Iter() <-chan interface{}
}
func DropWhile ¶
DropWhile returns an Iterable that returns each element of iter after the initial sequence for which f returns true.
func GroupBy ¶
GroupBy combines sequences of logically identical values from iter using k to generate a key to compare values. Each value emitted by the returned Iterable is of type Group, which contains the key used for matching the values for the group, and an Iterable for retrieving all the values in the group.
func RepeatTimes ¶
RepeatTimes generates a stream of n copies of v.
func Slice ¶
Slice returns an Iterable that contains the elements from iter with indexes in [start, stop).
func Zip ¶
Zip returns an Iterable of []interface{} consisting of the next element from each input Iterable. The length of the returned Iterable is the minimum of the lengths of the input Iterables.
type StringArray ¶
type StringArray []string
func (StringArray) Iter ¶
func (a StringArray) Iter() <-chan interface{}