linq

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package linq provides extra features for go's standard iter library.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound  = errors.New("linq: element is not found")
	ErrNotSingle = errors.New("linq: sequence is not single")
)

Errors.

Functions

func Equal

func Equal[E comparable](s1, s2 Seq[E]) (bool, error)

Equal reports whether two sequences are equal.

func Max

func Max[E cmp.Ordered](s Seq[E]) (E, error)

Max returns the maximal element in s.

func Min

func Min[E cmp.Ordered](s Seq[E]) (E, error)

Min returns the minimal element in s.

Types

type Entry added in v0.2.0

type Entry[K comparable, V any] struct {
	Key   K // The map key.
	Value V // The map value.
}

Entry represents an entry of map.

type Seq

type Seq[E any] func(yield func(E, error) bool)

Seq represents a sequence of elements.

func ChanValues added in v0.2.0

func ChanValues[V any](c <-chan V) Seq[V]

ChanValues returns a sequence that contains the chan values.

func Concat

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

Concat returns a new sequence concatenating the sequences.

func Elements added in v0.2.0

func Elements[E any](es ...E) Seq[E]

Elements returns a sequence that contains the elements.

func Empty

func Empty[E any]() Seq[E]

Empty returns an empty sequence.

func Error added in v0.2.0

func Error[E any](err error) Seq[E]

Error returns an sequence has error.

func Increment

func Increment(start, step int) Seq[int]

Increment generates a incremental sequence.

func Map

func Map[E, R any](s Seq[E], f func(E) (R, error)) Seq[R]

Map maps sequence using function f.

func MapEntries added in v0.2.0

func MapEntries[K comparable, V any, M ~map[K]V](m M) Seq[Entry[K, V]]

MapEntries returns a sequence that contains the map entries.

func MapKeys added in v0.2.0

func MapKeys[K comparable, V any, M ~map[K]V](m M) Seq[K]

MapKeys returns a sequence that contains the map keys.

func MapValues added in v0.2.0

func MapValues[K comparable, V any, M ~map[K]V](m M) Seq[V]

MapValues returns a sequence that contains the map values.

func Repeat

func Repeat[E any](e E) Seq[E]

Repeat generates a sequence that contains one repeated element.

func Runes added in v0.2.0

func Runes(s string) Seq[rune]

Runes returns a sequence that contains runes in string.

func Sort

func Sort[E cmp.Ordered](s Seq[E]) Seq[E]

Sort sorts a sequence of any ordered type in ascending order.

func Zip

func Zip[X, Y, R any](xs Seq[X], ys Seq[Y], f func(X, Y) (R, error)) Seq[R]

Zip applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.

func (Seq[E]) All

func (s Seq[E]) All(f func(E) bool) (bool, error)

All determines whether all elements of a sequence satisfy a condition.

func (Seq[E]) Any

func (s Seq[E]) Any(f func(E) bool) (bool, error)

Any determines whether a sequence contains any elements.

func (Seq[E]) Append

func (s Seq[E]) Append(es ...E) Seq[E]

Append appends es to sequence.

func (Seq[E]) Collect

func (s Seq[E]) Collect() ([]E, error)

Collect collects elements into a new slice and returns it.

func (Seq[E]) Count

func (s Seq[E]) Count() (int, error)

Count counts the number of elements in this sequence.

func (Seq[E]) Equal

func (s Seq[E]) Equal(other Seq[E], eq func(E, E) bool) (bool, error)

Equal reports whether two sequences are equal using an equality function on each pair of elements.

func (Seq[E]) Filter

func (s Seq[E]) Filter(f func(E) bool) Seq[E]

Filter filters a sequence of elements based on f.

func (Seq[E]) First

func (s Seq[E]) First() (E, error)

First returns the first element.

func (Seq[E]) Force added in v0.2.0

func (s Seq[E]) Force() Seq[E]

Force forces the calculation of seq elements.

func (Seq[E]) Get

func (s Seq[E]) Get(index int) (E, error)

Get returns the index'th element.

func (Seq[E]) IsEmpty

func (s Seq[E]) IsEmpty() (bool, error)

IsEmpty returns whether this sequence has no elements.

func (Seq[E]) Last

func (s Seq[E]) Last() (E, error)

Last returns the last element.

func (Seq[E]) Max

func (s Seq[E]) Max(cmp func(E, E) int) (E, error)

Max returns the maximal element in s, using cmp to compare elements.

func (Seq[E]) Min

func (s Seq[E]) Min(cmp func(E, E) int) (E, error)

Min returns the minimal element in s, using cmp to compare elements.

func (Seq[E]) Reverse

func (s Seq[E]) Reverse() Seq[E]

Reverse inverts the order of the elements in a sequence.

func (Seq[E]) Single

func (s Seq[E]) Single() (E, error)

Single checks that this sequence has only one element and returns that element.

func (Seq[E]) Skip

func (s Seq[E]) Skip(n int) Seq[E]

Skip skips a specified number of elements in a sequence and then returns the remaining elements.

func (Seq[E]) SkipFunc

func (s Seq[E]) SkipFunc(f func(E) bool) Seq[E]

SkipFunc skips elements in a sequence by f and returns the remaining elements.

func (Seq[E]) SkipLast

func (s Seq[E]) SkipLast(n int) Seq[E]

SkipLast returns a new sequence that contains the elements from source with the last count elements of the sequence omitted.

func (Seq[E]) SkipLastFunc

func (s Seq[E]) SkipLastFunc(f func(E) bool) Seq[E]

SkipLastFunc skips last elements in a sequence by f and returns the remaining elements.

func (Seq[E]) Sort

func (s Seq[E]) Sort(cmp func(E, E) int) Seq[E]

Sort sorts the sequence in ascending order as determined by the cmp function.

func (Seq[E]) SortStable

func (s Seq[E]) SortStable(cmp func(E, E) int) Seq[E]

SortStable sorts the sequence in ascending order as determined by the cmp function, keeping the original order of equal elements.

func (Seq[E]) Take

func (s Seq[E]) Take(n int) Seq[E]

Take returns a specified number of contiguous elements from the start of a sequence.

func (Seq[E]) TakeFunc

func (s Seq[E]) TakeFunc(f func(E) bool) Seq[E]

TakeFunc returns elements from a sequence as long as a specified condition is true.

func (Seq[E]) TakeLast

func (s Seq[E]) TakeLast(n int) Seq[E]

TakeLast returns a new sequence that contains the last n elements from s.

func (Seq[E]) TakeLastFunc

func (s Seq[E]) TakeLastFunc(f func(E) bool) Seq[E]

TakeLastFunc returns last elements from a sequence as long as a specified condition is true.

Jump to

Keyboard shortcuts

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