seqs

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT-0 Imports: 1 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All added in v0.5.0

func All[S Seq[E], E any](seq S, pred func(E) bool) (res bool)

All returns true if the specified predicate returns true for all elements of the specified sequence

Application to an infinite sequence will block indefinitely.

func And added in v0.7.0

func And[S Seq[bool]](seq S) bool

And returns true if all elements of the specified sequence are true, which includes the empty sequence

Application to an infinite sequence will block indefinitely.

func Any added in v0.5.0

func Any[S Seq[E], E any](seq S, pred func(E) bool) (res bool)

Any returns true if the specified predicate returns true for any element of the specified sequence

Application to an infinite sequence will block indefinitely.

func AppendTo added in v0.6.0

func AppendTo[S Seq[E], E any, Es ~[]E](seq S, slice Es) Es

AppendTo appends elements from the specified sequence to the slice(ish)

func Count added in v0.9.0

func Count[S Seq[E], E any](seq S) int

Count returns the number of elements in the specified sequence.

Application to an infinite sequence will block indefinitely.

func First added in v0.9.0

func First[S Seq[E], E any](seq S) (first E, hasFirst bool)

First returns the first element of the specified sequence and true, or the zero value of E and false if the sequence is empty.

func ForEach

func ForEach[S Seq[E], E any](seq S, yield func(E))

ForEach calls the specified function for each element of the specified sequence

Application to an infinite sequence will block indefinitely.

func ForEachUntilWithIndex added in v0.3.0

func ForEachUntilWithIndex[S Seq[E], E any](seq S, yield func(int, E) bool)

ForEachUntilWithIndex calls the specified function for each element of the specified sequence along with its index until the function returns `true`

func ForEachWhile

func ForEachWhile[S Seq[E], E any](seq S, yield func(E) bool)

ForEachWhile calls the specified function for each element of the specified sequence while the function returns `true`

func ForEachWhileWithIndex added in v0.3.0

func ForEachWhileWithIndex[S Seq[E], E any](seq S, yield func(int, E) bool)

ForEachWhileWithIndex calls the specified function for each element of the specified sequence along with its index while the function returns `true`

func ForEachWithIndex added in v0.3.0

func ForEachWithIndex[S Seq[E], E any](seq S, yield func(int, E))

ForEachWithIndex calls the specified function for each element of the specified sequence along with its index

func IsEmpty added in v0.11.0

func IsEmpty[S Seq[E], E any](seq S) bool

IsEmpty returns true if the specified sequence has no elements; otherwise, it returns false.

func Last added in v0.9.0

func Last[S Seq[E], E any](seq S) (last E, hasLast bool)

Last returns the last element of the specified sequence and true, or the zero value of E and false if the sequence is empty.

Application to an infinite sequence will block indefinitely.

func Or added in v0.7.0

func Or[S Seq[bool]](seq S) bool

Or returns true if any element of the specified sequence is true, which does not include the empty sequence

Application to an infinite sequence will block indefinitely.

func Reduce

func Reduce[S Seq[E], E any](seq S, op func(E, E) E) (res E)

Reduce returns a value obtained by aggregating elements of the specified sequence using the specified operation.

If the specified sequence is empty, the zero value of E will be returned. If the specified sequence has a single element only, that element will be returned.

Application to an infinite sequence will block indefinitely.

func SeededReduce added in v0.9.0

func SeededReduce[S Seq[E], E any, A any](seq S, seed A, op func(A, E) A) (res A)

SeededReduce returns a value obtained by applying the specified function to an accumlator value (initialized to the specified seed value) and successive elements of the sequence

Application to an infinite sequence will block indefinitely.

func Sum added in v0.6.0

func Sum[S Seq[E], E Summable](seq S) E

Sum returns the sum of the specified sequence's elements.

Application to an infinite sequence will block indefinitely.

func ToSet

func ToSet[S Seq[E], E comparable](seq S) (res map[E]bool)

ToSet returns a set (boolean valued map) created from the elements of the specified sequence

Application to an infinite sequence will block indefinitely.

func ToSlice

func ToSlice[S Seq[E], E any](seq S) (res []E)

ToSlice returns a slice of the specified sequence's elements

Types

type FiniteSeq added in v0.3.0

type FiniteSeq[E any] interface {
	Seq[E]
	Lener
}

FiniteSeq is a Seq that has a finite length

type Lener

type Lener interface {
	// Len returns the length of a collection
	//
	// This method returns an `int` to be consistent with the `len()` built-in function.
	Len() int
}

Lener is an interface optionally implemented by sequences which have a finite length

type Pair added in v0.12.0

type Pair[First, Second any] interface {
	Unwrap() (First, Second)
}

type Seq

type Seq[E any] interface {
	// ForEachUntil calls the specified function for each sequence element until the function returns `true`
	ForEachUntil(yield func(E) bool)
}

Seq defines a minimal interface for a sequence of values

func AsSeq added in v0.12.0

func AsSeq[S Seq[E], E any](seq S) Seq[E]

AsSeq type casts a concrete sequence as a generic sequence

func Concat added in v0.2.0

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

Concat returns a sequence that is the concatenation of the specified sequences

func Cycle added in v0.2.0

func Cycle[S Seq[E], E any](seq S) Seq[E]

Cycle returns an (almost always) infinite sequence that cyclically repeats the elements of the specified sequence

If the specified sequence is empty (or becomes empty at any point) the returned sequence becomes empty to avoid an unbreakable infinite loop.

func Empty

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

Empty returns an empty sequence

func Enumerate added in v0.12.0

func Enumerate[S Seq[E], E any](seq S) Seq[Pair[int, E]]

func Filter

func Filter[S Seq[E], E any](seq S, pred func(E) bool) Seq[E]

Filter returns a sequence that only contains elements of the specified sequence for which the specified predicate returns `true`

func FilterWithIndex added in v0.3.0

func FilterWithIndex[S Seq[E], E any](seq S, pred func(int, E) bool) Seq[E]

FilterWithIndex returns a sequence that only contains elements of the specified sequence for which the specified predicate returns `true`

func Flatten added in v0.3.0

func Flatten[SS Seq[S], S Seq[E], E any](seq SS) Seq[E]

Flatten returns a sequence that is the concatenation of sequences contained by the specified sequence

The returned sequence never implements the Lener interface. Use Concat with ToSlice if you want the resulting sequence to implement Lener when possible.

func FromSlice

func FromSlice[Es ~[]E, E any](s Es) Seq[E]

FromSlice returns a sequence whose elemets are (copies of) the specified slice's elements

func FromSlicePtrs added in v0.7.0

func FromSlicePtrs[Es ~[]E, E any](s Es) Seq[*E]

FromSlicePtrs returns a sequence whose elements are pointers to the specified slice's elements

func FromValues

func FromValues[E any](values ...E) Seq[E]

FromValues returns a sequence made up of the specified values

func Generate added in v0.6.0

func Generate[E any](gen func() E) Seq[E]

Generate returns a sequence whose elements are generated by calling the provided function

func GenerateWithIndex added in v0.6.0

func GenerateWithIndex[E any](gen func(idx int) E) Seq[E]

GenerateWithIndex returns a sequence whose elements are generated by calling the provided function with the current index

func Intersperse added in v0.2.0

func Intersperse[S Seq[E], E any](seq S, val E) Seq[E]

Intersperse returns a sequence whose elements are the same as the specified sequence's but interspersed with the specified value

func Map

func Map[S Seq[Src], Src any, Dst any](seq S, mapfn func(Src) Dst) Seq[Dst]

Map returns a sequence whose elements are obtained by applying the specified mapping function to elements of the specified sequence

func MapWithIndex added in v0.3.0

func MapWithIndex[S Seq[Src], Src any, Dst any](seq S, mapfn func(int, Src) Dst) Seq[Dst]

MapWithIndex returns a sequence whose elements are obtained by applying the specified mapping function to elements of the specified sequence along with their indices

func PartialSums added in v0.9.0

func PartialSums[S Seq[E], E Summable](seq S) Seq[E]

PartialSums returns a sequence of the partial sums of the specified sequence.

func Reductions added in v0.9.0

func Reductions[S Seq[E], E any](seq S, op func(E, E) E) Seq[E]

Reductions returns the sequence of intermediate values of the reduction of the specified sequence with the specified operation.

If the specified sequence is empty, the returned sequence will be empty. If the specified sequence has a single element only, a sequence containing only that element will be returned.

func Reject added in v0.10.0

func Reject[S Seq[E], E any](seq S, pred func(E) bool) Seq[E]

Reject returns a sequence that only contains elements of the specified sequence for which the specified predicate returns `false`

func RejectWithIndex added in v0.10.0

func RejectWithIndex[S Seq[E], E any](seq S, pred func(int, E) bool) Seq[E]

RejectWithIndex returns a sequence that only contains elements of the specified sequence for which the specified predicate returns `false`

func Repeat

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

Repeat returns an infinite sequence that repeats the specified value

func RepeatN

func RepeatN[E any](e E, n int) Seq[E]

Repeat returns a finite sequence that repeats the specified value `n` times

func RoundRobin added in v0.2.0

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

RoundRobin returns a sequence whose elements are obtained by alternately taking elements from the specified sequences in a round-robin fashion

func SeededReductions added in v0.9.0

func SeededReductions[S Seq[E], E any, A any](seq S, seed A, op func(A, E) A) Seq[A]

SeededReductions returns the sequence of intermediate values of the reduction of the specified sequence by the specified operation starting with the specified seed value.

The returned sequence always has the seed value as its first element.

func SeqFunc added in v0.3.1

func SeqFunc[E any](fn func(yield func(E) bool)) Seq[E]

SeqFunc returns a sequence that has its ForEachUntil method implemented by the specified function

func Skip

func Skip[S Seq[E], E any](s S, n int) Seq[E]

Skip returns a sequence that omits the first `n` number of elements of the specified sequence

If the source sequence has less than `n` elements the returned sequence will be empty

func SkipWhile

func SkipWhile[S Seq[E], E any](s S, pred func(E) bool) Seq[E]

SkipWhile returns a sequence that omits elements of the specified sequence while the specified predicate returns `true`

func SlidingWindow added in v0.4.0

func SlidingWindow[S Seq[E], E any](seq S, count int, skip int) Seq[[]E]

SlidingWindow returns a sequence of windows (slices of count length) containing the elements of the specified sequence. Windows start after each other with a distance of skip.

func Take

func Take[S Seq[E], E any](s S, n int) Seq[E]

Take returns a sequence of the first `n` number of elements of the specified sequence

If the source sequence has less then `n` elements the returned sequence will also have only that many elements

func TakeWhile

func TakeWhile[S Seq[E], E any](s S, pred func(E) bool) Seq[E]

TakeWhile returns a sequence of the first elements of the specified sequence while the specified predicate returns `true`

TakeWhile(FromValues())

func ZipMany added in v0.8.0

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

ZipMany returns a sequence of slices containing elements of the same index from the specified sequences

func ZipWith added in v0.8.0

func ZipWith[S1 Seq[E1], S2 Seq[E2], E1 any, E2 any, T any](seq1 S1, seq2 S2, merge func(E1, E2) T) Seq[T]

ZipWith returns a sequence containing results of the specified merge function applied to elements of the same index from both specified sequences

type Summable added in v0.6.0

type Summable interface {
	~float32 | ~float64 | ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | string
}

Summable lists types that support addition using the + operator

Jump to

Keyboard shortcuts

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