Skip to content

About

Generic Collection with chained methods in Go

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

collection

This is a simple wrapper around iterators to provide method chaining.

c := New(func(yield func(int) bool) {
	for i := range 10 {
		if !yield(i) {
			return
		}
	}
})

result := c.
	Filter(func(i int) bool { return i%2 == 0 }).
	Map(func(i int) string { return fmt.Sprintf("%v", i) }).
	Slice()

Constructors

Iterator

func New[T any](i iter.Seq[T]) Collection[T]

Slice

func NewFromSlice[T any](s []T) Collection[T]

List

func NewFromList[T any](l *list.List) Collection[T]

Channel

func NewFromChan[T any](ctx context.Context, ch <-chan T) Collection[T]

Transformers

Creates a new Collection and does not consume the iterator.

Filter

func (c Collection[T]) Filter(p func(T) bool) Collection[T]

Map

func (c Collection[T]) Map[U any](p func(T) U) Collection[U]

Sinks

Transforms the iterator into a new type. Consumes the iterator.

Iterator

func (c Collection[T]) Iter() iter.Seq[T]

Slice

func (c Collection[T]) Slice() []T

Reduce

func (c Collection[T]) Reduce[U any](p func(T, U) U) U

About

Generic Collection with chained methods in Go

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages