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()func New[T any](i iter.Seq[T]) Collection[T]func NewFromSlice[T any](s []T) Collection[T]func NewFromList[T any](l *list.List) Collection[T]func NewFromChan[T any](ctx context.Context, ch <-chan T) Collection[T]Creates a new Collection and does not consume the iterator.
func (c Collection[T]) Filter(p func(T) bool) Collection[T]func (c Collection[T]) Map[U any](p func(T) U) Collection[U]Transforms the iterator into a new type. Consumes the iterator.
func (c Collection[T]) Iter() iter.Seq[T]func (c Collection[T]) Slice() []Tfunc (c Collection[T]) Reduce[U any](p func(T, U) U) U