itertools

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All added in v0.2.0

func All[V any](seq iter.Seq[V], f func(V) bool) bool

func Defer added in v0.4.0

func Defer(f func()) func(yield func() bool)

Defer returns an iterator that will run f after yielding once. Used for block level defer. ```

func f(m *sync.Mutex) {
	m.Lock()
	for range Defer(func() {
		m.Unlock()
	}) {
		// do something while m locked
	}
	// m is unlocked here
}

```

func Map

func Map[V any, B any](seq iter.Seq[V], f func(V) B) iter.Seq[B]

func Once added in v0.4.0

func Once[V any](v V) iter.Seq[V]

Once returns an iterator that yields an element exactly once.

Types

type Iterator added in v0.3.0

type Iterator[V any] struct {
	// contains filtered or unexported fields
}

func Single added in v0.3.0

func Single[V any](seq iter.Seq[V]) Iterator[V]

Single converts a possible multi-use iterator into a single-use resumable iterator. Must `defer it.Stop()` or fully consume the iterator, otherwise you have a goroutine (coroutine created by iter.Pull) leak. See https://pkg.go.dev/iter#hdr-Single_Use_Iterators. Goroutine leak detector: https://github.com/uber-go/goleak

func (*Iterator[V]) Next added in v0.3.0

func (it *Iterator[V]) Next() (V, bool)

func (*Iterator[V]) Seq added in v0.3.0

func (it *Iterator[V]) Seq() iter.Seq[V]

func (*Iterator[V]) Stop added in v0.3.0

func (it *Iterator[V]) Stop()

Jump to

Keyboard shortcuts

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