iterable

package
v0.0.0-...-2eef10d Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: Apache-2.0 Imports: 0 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 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 Func

type Func func(chan<- interface{})

A Func is a function that, when called, sends the iterable values on a channel.

func (Func) Iter

func (f Func) Iter() <-chan interface{}

Iter creates and returns a new channel; it starts a goroutine running f to send values to the 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 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 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 TakeWhile

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

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

Jump to

Keyboard shortcuts

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