Documentation
¶
Overview ¶
Package slice implements an iterator that traverses uni-directionally over a generic slice of elements
Slice supports the SizeHint interface.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator[T any] struct { // contains filtered or unexported fields }
Iterator traverses over a slice of element of type T.
Example ¶
package main import ( "context" "fmt" "github.com/jake-scott/go-functional/iter/slice" ) func main() { input := []string{"dog", "cat", "fox", "pigeon"} ctx := context.Background() iter := slice.New(input) for iter.Next(ctx) { fmt.Printf("Animal: <%s>\n", iter.Get()) } if err := iter.Error(); err != nil { panic(err) } }
Output: Animal: <dog> Animal: <cat> Animal: <fox> Animal: <pigeon>
func New ¶
New returns an implementation of Iterator that traverses over the provided slice. The iterator returned supports the SizeHint itnerface.
func (*Iterator[T]) Error ¶
Error returns the context's error if the context is cancelled during a call to Next()
func (*Iterator[T]) Get ¶
func (r *Iterator[T]) Get() T
Get returns element of the underlying slice that the iterator refers to
The context is not used in this iterator implementation.
Click to show internal directories.
Click to hide internal directories.