giter

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package giter provides the abstraction of map, slice or channel types into iterators for common processing

Usually we can use gslice for slices, gmap for maps and gchan for channels.

In most scenarios, we DO NOT need to use the giter package directly

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllFromSeq

func AllFromSeq[T any](seq Seq[T], f func(T) bool) bool

AllFromSeq return true if all elements from seq satisfy the condition evaluated by f.

func AnyFromSeq

func AnyFromSeq[T any](seq Seq[T], f func(T) bool) bool

AnyFromSeq return true if any elements from seq satisfy the condition evaluated by f.

func At

func At[T any](seq Seq[T], index int) optional.O[T]

At return the element at index from seq.

func AvgByFromSeq

func AvgByFromSeq[V any, T constraints.Number](seq Seq[V], f func(V) T) float64

AvgByFromSeq return the average value of all elements from seq, evaluated by f.

func AvgFromSeq

func AvgFromSeq[T constraints.Number](seq Seq[T]) float64

AvgFromSeq return the average value of all elements from seq.

func Contains

func Contains[T comparable](seq Seq[T], in T) bool

Contains return true if v is in seq.

func ContainsAll

func ContainsAll[T comparable](seq Seq[T], in []T) bool

ContainsAll return true if all elements from seq is in vs.

func ContainsAny

func ContainsAny[T comparable](seq Seq[T], in []T) bool

ContainsAny return true if any element from seq is in vs.

func ContainsBy

func ContainsBy[T any](seq Seq[T], f func(T) bool) bool

ContainsBy return true if any element from seq satisfies the condition evaluated by f.

func Count

func Count[T any](seq Seq[T]) int

Count return the number of elements in seq.

func Find

func Find[T any](seq Seq[T], f func(T) bool) (val T, found bool)

Find return the first element from seq that satisfies the condition evaluated by f with a boolean representing whether it exists.

func FindO

func FindO[T any](seq Seq[T], f func(T) bool) optional.O[T]

FindO return the first element from seq that satisfies the condition evaluated by f.

func ForEach

func ForEach[T any](seq Seq[T], f func(T) bool)

ForEach execute f for each element in seq.

func ForEachIdx

func ForEachIdx[T any](seq Seq[T], f func(idx int, v T) bool)

ForEachIdx execute f for each element in seq with its index.

func Head[T any](seq Seq[T]) (v T, hasOne bool)

Head return the first element from seq with a boolean representing whether it is at least one element in seq.

func HeadO

func HeadO[T any](seq Seq[T]) optional.O[T]

HeadO return the first element from seq.

func Join

func Join[T ~string](seq Seq[T], sep T) T

Join return the concatenation of all elements in seq with sep.

func Max

func Max[T constraints.Ordered](seq Seq[T]) (r optional.O[T])

Max returns the maximum element in seq.

func MaxBy

func MaxBy[T constraints.Ordered](seq Seq[T], less func(T, T) bool) (r optional.O[T])

MaxBy return the maximum element in seq, evaluated by f.

func Min

func Min[T constraints.Ordered](seq Seq[T]) (r optional.O[T])

Min return the minimum element in seq.

func MinBy

func MinBy[T constraints.Ordered](seq Seq[T], less func(T, T) bool) (r optional.O[T])

MinBy return the minimum element in seq, evaluated by f.

func PullOut

func PullOut[T any](seq Seq[T], n int) (out []T)

PullOut pull out n elements from seq.

func ToSlice

func ToSlice[T any](seq Seq[T]) (out []T)

ToSlice returns the elements in seq as a slice.

Types

type Seq

type Seq[V any] iter.Seq[V]

Seq is a sequence of elements provided by an iterator-like function. We made an Alias Seq to iter.Seq for providing a compatible interface in lower go versions.

func Concat

func Concat[T any](seqs ...Seq[T]) Seq[T]

Concat receive some seqs and return a seq concat them

func Filter

func Filter[T any](seq Seq[T], f func(T) bool) Seq[T]

Filter returns a new seq filtered origin seq with f

func FromSlice

func FromSlice[T any](in []T) Seq[T]

FromSlice received a slice and returned a Seq for this slice.

func FromSliceReverse added in v0.1.4

func FromSliceReverse[T any, Slice ~[]T](in Slice) Seq[T]

func FromSliceShuffle added in v0.1.5

func FromSliceShuffle[T any](in []T) Seq[T]

FromSliceShuffle return a seq that shuffle the elements in the input slice.

func Limit added in v0.1.4

func Limit[T any](seq Seq[T], n int) Seq[T]

Limit return a seq that limit n elements from seq.

func Repeat added in v0.1.5

func Repeat[T any](seq Seq[T], count int) Seq[T]

Repeat return a seq that repeat seq for count times.

func Replace added in v0.1.4

func Replace[T comparable](seq Seq[T], from, to T, n int) Seq[T]

Replace return a seq that replace from -> to

func ReplaceAll added in v0.1.4

func ReplaceAll[T comparable](seq Seq[T], from, to T) Seq[T]

ReplaceAll return a seq that replace all from -> to

func Reverse added in v0.1.4

func Reverse[T any](seq Seq[T]) Seq[T]

Reverse return a reversed seq.

func Skip added in v0.1.4

func Skip[T any](seq Seq[T], n int) Seq[T]

Skip return a seq that skip n elements from seq.

type Seq2

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

Seq2 is a sequence of key/value pair provided by an iterator-like function. We made an Alias Seq2 to iter.Seq2 for providing a compatible interface in lower go versions.

Jump to

Keyboard shortcuts

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