iterable

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 2 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(iter Iterable, f func(interface{}) bool) bool

All tests whether f is true for every element of iter.

func Any

func Any(iter Iterable, f func(interface{}) bool) bool

Any tests whether f is true for at least one element of iter.

func Data

func Data(iter Iterable) []interface{}

Data returns a slice containing the elements of iter.

func Find

func Find(iter Iterable, f func(interface{}) bool) interface{}

Find returns the first element of iter that satisfies f. Returns nil if no such element is found.

func Inject

func Inject(iter Iterable, initial interface{}, f Injector) interface{}

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)

func Partition

func Partition(iter Iterable, f func(interface{}) bool) (Iterable, Iterable)

Partition(iter, f) returns Filter(iter, f) and Filter(iter, !f).

Types

type ByteArray

type ByteArray []byte

func (ByteArray) Iter

func (a ByteArray) Iter() <-chan interface{}

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 IntArray

type IntArray []int

func (IntArray) Iter

func (a IntArray) Iter() <-chan interface{}

type Iterable

type Iterable interface {
	// Iter should return a fresh channel each time it is called.
	Iter() <-chan interface{}
}

func Chain

func Chain(args []Iterable) Iterable

Chain returns an Iterable that concatentates all values from the specified Iterables.

func Cycle

func Cycle(iter Iterable) Iterable

Cycle repeats the values of iter in order infinitely.

func Drop

func Drop(iter Iterable, n int) Iterable

Drop returns an Iterable that returns each element of iter after the first n elements.

func DropWhile

func DropWhile(iter Iterable, f func(interface{}) bool) Iterable

DropWhile returns an Iterable that returns each element of iter after the initial sequence for which f returns true.

func Filter

func Filter(iter Iterable, f func(interface{}) bool) Iterable

Filter returns an Iterable that returns the elements of iter that satisfy f.

func GroupBy

func GroupBy(iter Iterable, k Grouper) Iterable

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 Map

func Map(iter Iterable, f func(interface{}) interface{}) Iterable

Map returns an Iterable that returns the result of applying f to each element of iter.

func Repeat

func Repeat(v interface{}) Iterable

Repeat generates an infinite stream of v.

func RepeatTimes

func RepeatTimes(v interface{}, n int) Iterable

RepeatTimes generates a stream of n copies of v.

func Slice

func Slice(iter Iterable, start, stop int) Iterable

Slice returns an Iterable that contains the elements from iter with indexes in [start, stop).

func Take

func Take(iter Iterable, n int) Iterable

Take returns an Iterable that contains the first n elements of iter.

func TakeWhile

func TakeWhile(iter Iterable, f func(interface{}) bool) Iterable

TakeWhile returns an Iterable that contains elements from iter while f is true.

func Unique

func Unique(iter Iterable, id Grouper) Iterable

Unique removes duplicate values which occur consecutively using id to compute keys.

func Zip

func Zip(args []Iterable) Iterable

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.

func ZipWith2

func ZipWith2(f func(c, d interface{}) interface{}, a, b Iterable) Iterable

ZipWith returns an Iterable containing the result of executing f using arguments read from a and b.

func ZipWith3

func ZipWith3(f func(d, e, f interface{}) interface{}, a, b, c Iterable) Iterable

ZipWith returns an Iterable containing the result of executing f using arguments read from a, b and c.

type StringArray

type StringArray []string

func (StringArray) Iter

func (a StringArray) Iter() <-chan interface{}

Jump to

Keyboard shortcuts

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