iter

package
v0.0.0-...-49448ba Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyIter = errors.New("contains no elements")
View Source
var ErrOutOfRange = errors.New("out of range")

Functions

func All

func All[S any](src Iterer[S], predicate func(S) bool) (result bool, err error)

func Any

func Any[S any](src Iterer[S], predicate func(S) bool) (result bool, err error)

func Collect

func Collect[S any](src Iterer[S], dst interface{ Add(S) }) (err error)

func Contains

func Contains[S comparable](src Iterer[S], target S) (result bool, err error)

func ElementAt

func ElementAt[S any](src Iterer[S], idx uint) (result S, err error)

func First

func First[S any](src Iterer[S]) (result S, err error)

func FirstOrDefault

func FirstOrDefault[S any](src Iterer[S]) (result S, err error)

func Fold

func Fold[S, R any](src Iterer[S], seed R, reducer func(R, S) R) (result R, err error)

func Last

func Last[S any](src Iterer[S]) (result S, err error)

func LastOrDefault

func LastOrDefault[S any](src Iterer[S]) (result S, err error)

func Len

func Len[S any](src Iterer[S]) (result int, err error)

func Max

func Max[S constraints.Ordered](src Iterer[S]) (result S, err error)

func Min

func Min[S constraints.Ordered](src Iterer[S]) (result S, err error)

func Reduce

func Reduce[S any](src Iterer[S], reducer func(S, S) S) (result S, err error)

func Sum

func Sum[S constraints.Integer | constraints.Float](src Iterer[S]) (result S, err error)

func ToSlice

func ToSlice[S any](src Iterer[S]) (result []S, err error)

Types

type Grouping

type Grouping[S any, K comparable] struct {
	Key    K
	Values []S
}

type Iter

type Iter[T any] interface {
	Next() (T, bool)
	Close() error
}

type Iterer

type Iterer[T any] interface {
	Iter() Iter[T]
}

func Chunk

func Chunk[S any](src Iterer[S], size int) Iterer[[]S]

func Concat

func Concat[S any](first Iterer[S], second Iterer[S]) Iterer[S]

func Distinct

func Distinct[S comparable](src Iterer[S]) Iterer[S]

func Empty

func Empty[S any]() Iterer[S]

func Err

func Err[S any](err error) Iterer[S]

func Filter

func Filter[S any](src Iterer[S], filter func(S) bool) Iterer[S]

func FromMap

func FromMap[K comparable, V any](m map[K]V) Iterer[KeyValuePair[K, V]]

func FromSlice

func FromSlice[T any](values []T) Iterer[T]

func Generate

func Generate[T any](generator func() (T, bool)) Iterer[T]

func Group

func Group[S any, K comparable](src Iterer[S], keySelector func(S) K) Iterer[Grouping[S, K]]

func Range

func Range[T constraints.Integer | constraints.Float](from T, to T, step T) Iterer[T]

func RangeInclusive

func RangeInclusive[T constraints.Integer | constraints.Float](from T, to T, step T) Iterer[T]

func Repeat

func Repeat[T any](value T, count int) Iterer[T]

func Select

func Select[S, R any](src Iterer[S], selector func(S) R) Iterer[R]

func SelectMany

func SelectMany[S, R any](src Iterer[S], selector func(S) Iterer[R]) Iterer[R]

func Skip

func Skip[S any](src Iterer[S], skip int) Iterer[S]

func Take

func Take[S any](src Iterer[S], limit int) Iterer[S]

func Zip

func Zip[S1, S2, R any](first Iterer[S1], second Iterer[S2], zipper func(S1, S2) R) Iterer[R]

type ItererFunc

type ItererFunc[T any] func() Iter[T]

func (ItererFunc[T]) Iter

func (f ItererFunc[T]) Iter() Iter[T]

type KeyValuePair

type KeyValuePair[K comparable, V any] struct {
	Key   K
	Value V
}

Jump to

Keyboard shortcuts

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