iter

package
v0.0.0-...-beca06d Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](s iter.Seq[T], f func(T) bool) bool

All returns true if all elements in s satisfy the predicate f. If s is nil or empty, All returns true.

func Any

func Any[T any](s iter.Seq[T], f func(T) bool) bool

Any returns true if any element in the sequence satisfies the predicate, false otherwise. If the sequence is nil or empty, Any returns false.

func Count

func Count[T any](s iter.Seq[T], f func(T) bool) int

Count returns the number of elements in the sequence that satisfy the predicate f.

func Filter

func Filter[T any](s iter.Seq[T], f func(T) bool) iter.Seq[T]

Filter returns a new sequence containing only the elements of sequence 's' that satisfy the predicate f.

func FilterToSlice

func FilterToSlice[T any](s iter.Seq[T], f func(T) bool) []T

FilterToSlice returns a new slice containing only the elements of sequence 's' that satisfy the predicate f.

func Find

func Find[T any](s iter.Seq[T], f func(T) bool) (int, T)

Find returns the index and the element of the first element in the sequence that satisfies the predicate f. If no element satisfies the predicate, Find returns -1 and the zero value of the element type.

func GroupBy

func GroupBy[T any, K comparable, V any](s iter.Seq[T], kv func(T) (K, V)) map[K][]V

GroupBy groups the elements of the sequence s by the key returned by the function kv.

func Map

func Map[T any, U any](is iter.Seq[T], f func(T) U) iter.Seq[U]

Map applies a function to each element of a sequence and returns a new sequence.

func MapToSlice

func MapToSlice[T any, U any](is iter.Seq[T], f func(T) U) []U

MapToSlice applies a function to each element of a sequence and returns a new slice.

func MapUnique

func MapUnique[T any, U comparable](is iter.Seq[T], f func(T) U) iter.Seq[U]

MapUnique applies a function to each element of a sequence and returns a new sequence with unique elements only.

func MapUniqueToSlice

func MapUniqueToSlice[T any, U comparable](is iter.Seq[T], f func(T) U) []U

MapUniqueToSlice applies a function to each element of a sequence and returns a new slice with unique elements only.

func Partition

func Partition[T any](s iter.Seq[T], predicate func(T) bool) (trueGroup iter.Seq[T], falseGroup iter.Seq[T])

Partition returns two sequences, the first sequence contains all elements that satisfy the predicate, and the second sequence contains all elements that do not satisfy the predicate.

func PartitionConsEq

func PartitionConsEq[T any](s iter.Seq[T], eq func(a, b T) bool) iter.Seq[[]T]

PartitionConsEq returns a sequence of slices of consecutive equal elements.

func PartitionConsEqToSlice

func PartitionConsEqToSlice[T any](s iter.Seq[T], eq func(a, b T) bool) [][]T

PartitionConsEqToSlice returns a slice of slices of consecutive equal elements.

func PartitionToSlice

func PartitionToSlice[T any](s iter.Seq[T], predicate func(T) bool) (trueGroup []T, falseGroup []T)

PartitionToSlice returns two slices, the first slice contains all elements that satisfy the predicate, and the second slice contains all elements that do not satisfy the predicate.

func Reduce

func Reduce[T any, A any](s iter.Seq[T], a A, f func(T, A) A) A

Reduce applies a function against an accumulator and each element in the sequence (from left to right) to reduce it to a single value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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