iter

package
Version: v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(cb Callback, fs ...Func) bool

func First added in v2.3.0

func First(f Func) (value interface{}, ok bool)

Calls `cb` with the first value yielded by `f` and then stops iteration. `ok` if `cb` was called with a value. Returning the value interface{} would require the caller to keep a

func ForPerm

func ForPerm(n int, callback func(i int) (more bool)) bool

func IterableAsSlice

func IterableAsSlice(it Iterable) (ret []interface{})

func N

func N(n int) []struct{}

func NewIterator

func NewIterator(it Iterable) (ret *iterator)

func ToSlice

func ToSlice(f Func) (ret []interface{})

Types

type Callback

type Callback func(value interface{}) (more bool)

Callback receives a value and returns true if another value should be received or false to stop iteration.

type Func

type Func func(Callback)

Func iterates by calling Callback for each of its values.

func Chain

func Chain(fs ...Func) Func
func Head(n int, f Func) Func

func ToFunc

func ToFunc(it Iterator) Func

type Group

type Group interface {
	Iterator
	Key() interface{}
}

type Iterable

type Iterable interface {
	Iter(Callback)
}

type Iterator

type Iterator interface {
	// Advances to the next value. Returns false if there are no more values.
	// Must be called before the first value.
	Next() bool
	// Returns the current value. Should panic when the iterator is in an
	// invalid state.
	Value() interface{}
	// Ceases iteration prematurely. This should occur implicitly if Next
	// returns false.
	Stop()
}

func GroupBy

func GroupBy(input Iterator, keyFunc func(interface{}) interface{}) Iterator

Group by returns an iterator of iterators over the values of the input iterator that consecutively return the same value when input to the key function. Note that repeated calls to each value of the GroupBy Iterator does not return a new iterator over the values for that key.

func Slice

func Slice(a []interface{}) Iterator

func StringIterator

func StringIterator(a string) Iterator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL