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 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 Func
- type Injector
- type Iterable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 Func ¶
type Func func(chan<- interface{})
A Func is a function that, when called, sends the iterable values on a channel.
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.