Documentation ¶
Overview ¶
Package goterator provides map and reduce functionality of iterators
Index ¶
- type IterFunc
- type Iterator
- func (iter *Iterator) All(f PredicateFunc) bool
- func (iter *Iterator) Any(f PredicateFunc) bool
- func (iter *Iterator) Collect() []interface{}
- func (iter *Iterator) Count() int
- func (iter *Iterator) Filter(f PredicateFunc) *Iterator
- func (iter *Iterator) Find(f PredicateFunc) (interface{}, bool)
- func (iter *Iterator) ForEach(f IterFunc)
- func (iter *Iterator) Last() interface{}
- func (iter *Iterator) Map(f MapFunc) *Iterator
- func (iter *Iterator) Max(f LessFunc) interface{}
- func (iter *Iterator) Min(f LessFunc) interface{}
- func (iter *Iterator) Nth(n int) (interface{}, bool)
- func (iter *Iterator) Reduce(initialState interface{}, f ReduceFunc) interface{}
- func (iter *Iterator) Skip(n int) *Iterator
- func (iter *Iterator) SkipWhile(f PredicateFunc) *Iterator
- func (iter *Iterator) Take(n int) *Iterator
- func (iter *Iterator) TakeWhile(f PredicateFunc) *Iterator
- type LessFunc
- type MapFunc
- type PredicateFunc
- type ReduceFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator represents an iterator object to apply map and reduce functions.
func (*Iterator) All ¶
func (iter *Iterator) All(f PredicateFunc) bool
All consumes elements and returns true if `f` returns true for all elements. Returns `true` for empty iterators.
func (*Iterator) Any ¶
func (iter *Iterator) Any(f PredicateFunc) bool
Any consumes elements and returns true if `f` returns true for at least one element. Returns `false` for empty iterators.
func (*Iterator) Collect ¶
func (iter *Iterator) Collect() []interface{}
Collect consumes elements and returns a slice of converted elements.
func (*Iterator) Filter ¶
func (iter *Iterator) Filter(f PredicateFunc) *Iterator
Filter lazily yields element if `f` returns true.
func (*Iterator) Find ¶
func (iter *Iterator) Find(f PredicateFunc) (interface{}, bool)
Find consumes elements and returns the first element that satisfies `f` (returning `true`). Returns `nil, false` if no element is found.
func (*Iterator) ForEach ¶
ForEach consumes elements and runs `f` for each element. The iteration is broken if `f` returns false.
func (*Iterator) Last ¶
func (iter *Iterator) Last() interface{}
Last consumes elements and returns the last element.
func (*Iterator) Nth ¶
Nth consumes elements and returns the `n`th element. Indexing starts from `0`. Returns an nil, false` if the length of iterator is less than `n`.
func (*Iterator) Reduce ¶
func (iter *Iterator) Reduce(initialState interface{}, f ReduceFunc) interface{}
Reduce consumes elements and runs `f` for each element. Returns the final state after iteration over all elements.
func (*Iterator) SkipWhile ¶
func (iter *Iterator) SkipWhile(f PredicateFunc) *Iterator
SkipWhile lazily skips element while `f` returns true. After returning `false` from `f`, this mapper is over.
func (*Iterator) TakeWhile ¶
func (iter *Iterator) TakeWhile(f PredicateFunc) *Iterator
TakeWhile lazily yields element while `f` returns true.
type LessFunc ¶
type LessFunc = func(first, second interface{}) bool
LessFunc returns true if first < second
type MapFunc ¶
type MapFunc = func(element interface{}) interface{}
MapFunc get an element and returns a converted element.
type PredicateFunc ¶
type PredicateFunc = func(element interface{}) bool
PredicateFunc gets an element and returns true if the element should be yielded.
type ReduceFunc ¶
type ReduceFunc = func(state, element interface{}) interface{}
ReduceFunc gets a state and an element, then returns the state.