iterx

package
v0.0.0-...-cbfc8b7 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package iterx provides some extensions to the base iter.Seq and iter.Seq2 types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PartitionSlice

func PartitionSlice[T any, K comparable](i SliceIter[T], partitionFn func(T) K) map[K]SliceIter[T]

PartitionSlice will break a SliceIter into groups based on the result of partitionFn.

Types

type Filter

type Filter[T any] func(T) bool

Filter is a function that returns true if the element of an iter.Seq should be yielded to the caller.

func Any

func Any[T any]() Filter[T]

Any will create a Filter that matches all elements.

func NoZeroValues

func NoZeroValues[T comparable]() Filter[T]

NoZeroValues creates a Filter that excludes elements that are the zero value for the type. The underlying type must be comparable.

func NotEqual

func NotEqual[T comparable](val T) Filter[T]

NotEqual creates a Filter that excludes elements that equal the value. The underlying type must be comparable.

func (Filter[T]) And

func (f Filter[T]) And(other Filter[T]) Filter[T]

And combines multiple Filter into one, where both must be true to yield the element.

func (Filter[T]) Or

func (f Filter[T]) Or(other Filter[T]) Filter[T]

Or combines multiple Filter into one, where one or the other must be true to yield the element.

type MapIter

type MapIter[K comparable, V any] iter.Seq2[K, V]

func SelectMap

func SelectMap[K comparable, V any](m map[K]V) MapIter[K, V]

SelectMap translates any map to a MapIter.

func SliceMap

func SliceMap[T any](slice []T) MapIter[int, T]

SliceMap will create a MapIter with the indexes and values of the given slice.

func (MapIter[K, V]) Count

func (i MapIter[K, V]) Count() int

func (MapIter[K, V]) FilterKeys

func (i MapIter[K, V]) FilterKeys(filter Filter[K]) MapIter[K, V]

func (MapIter[K, V]) FilterValues

func (i MapIter[K, V]) FilterValues(filter Filter[V]) MapIter[K, V]

func (MapIter[K, V]) First

func (i MapIter[K, V]) First() (K, V, bool)

func (MapIter[K, V]) ForEach

func (i MapIter[K, V]) ForEach(handler func(key K, val V) bool)

func (MapIter[K, V]) Keys

func (i MapIter[K, V]) Keys() SliceIter[K]

func (MapIter[K, V]) Limit

func (i MapIter[K, V]) Limit(limit int) MapIter[K, V]

func (MapIter[K, V]) Map

func (i MapIter[K, V]) Map() map[K]V

func (MapIter[K, V]) Values

func (i MapIter[K, V]) Values() SliceIter[V]

type SliceIter

type SliceIter[T any] iter.Seq[T]

func Select

func Select[T any](slice []T, filter Filter[T]) SliceIter[T]

Select will use the provided Filter to select elements from a slice, returning a SliceIter.

func SelectAll

func SelectAll[T any](slice []T) SliceIter[T]

SelectAll will translate any slice into a SliceIter.

func SelectSet

func SelectSet[K comparable, V any](m map[K]V) SliceIter[K]

SelectSet will translate a map as a set of values into a MapIter. This is semantically equivalent to calling SelectMap(m).Keys(), but slightly more computationally efficient.

func (SliceIter[T]) Count

func (i SliceIter[T]) Count() int

func (SliceIter[T]) Filter

func (i SliceIter[T]) Filter(filter Filter[T]) SliceIter[T]

func (SliceIter[T]) First

func (i SliceIter[T]) First() (T, bool)

func (SliceIter[T]) ForEach

func (i SliceIter[T]) ForEach(handler func(val T) bool)

func (SliceIter[T]) Limit

func (i SliceIter[T]) Limit(limit int) SliceIter[T]

func (SliceIter[T]) Slice

func (i SliceIter[T]) Slice() []T

func (SliceIter[T]) WithIndex

func (i SliceIter[T]) WithIndex() MapIter[int, T]

Jump to

Keyboard shortcuts

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