seq

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const OutOfBounds = "out of bounds"

Variables

This section is empty.

Functions

func AllMatch

func AllMatch[T any](predicate func(T) bool, it Sequence[T]) bool

Returns true if all elements in the Sequence match the condition.

func AnyMatch

func AnyMatch[T any](predicate func(T) bool, it Sequence[T]) bool

Returns true if any elements in the Sequence match the condition.

func At

func At[T any](index int, it Sequence[T]) option.Option[T]

Return the element at index.

func Average

Returns the average of all the elements in the Sequence.

func Collect

func Collect[T any, S any, R any](collector Collector[S, T, R], it Sequence[T]) R

Collecting via Collector.

func CollectToSlice

func CollectToSlice[T any](it Iterator[T]) []T

func Contains

func Contains[T comparable](target T, it Sequence[T]) bool

Returns true if the target is included in the Sequence.

func Count

func Count[T any](it Sequence[T]) int

Return the total number of Sequence.

func Equals

func Equals[T comparable](l Collection[T], r Collection[T]) bool

func First

func First[T any](it Sequence[T]) option.Option[T]

Return the first element.

func FirstIndexOf

func FirstIndexOf[T comparable](li Sequence[T], element T) int

func Fold

func Fold[T any, R any](initial R, operation func(R, T) R, it Sequence[T]) R

Return the value of the final composite, operates on the Sequence from back to front.

func ForEach

func ForEach[T any](action func(T), it Sequence[T])

The action is executed for each element of the Sequence, and the argument to the action is the element.

func IsEmpty

func IsEmpty[T any](c Collection[T]) bool

Ruturns true if the count of collection is 0.

func IsNotEmpty

func IsNotEmpty[T any](c Collection[T]) bool

Ruturns true if the count of collection is 0.

func Last

func Last[T any](it Sequence[T]) option.Option[T]

Return the last element.

func Max

func Max[T constraints.Ordered](it Sequence[T]) option.Option[T]

Return the maximum value of all elements of the Sequence.

func MaxBy

func MaxBy[T any](greater func(T, T) bool, it Sequence[T]) option.Option[T]

Return the maximum value of all elements of the Sequence.

func Min

func Min[T constraints.Ordered](it Sequence[T]) option.Option[T]

Return the minimum value of all elements of the Sequence.

func MinBy

func MinBy[T any](less func(T, T) bool, it Sequence[T]) option.Option[T]

Return the minimum value of all elements of the Sequence.

func NoneMatch

func NoneMatch[T any](predicate func(T) bool, it Sequence[T]) bool

Returns true if none elements in the Sequence match the condition.

func Product

func Product[T constraints.Integer | constraints.Float](it Sequence[T]) T

Returns the product of all the elements in the Sequence.

func Reduce

func Reduce[T any](operation func(T, T) T, it Sequence[T]) option.Option[T]

Return the value of the final composite, operates on the Sequence from front to back.

func Sum

func Sum[T constraints.Integer | constraints.Float](it Sequence[T]) T

Returns the sum of all the elements in the Sequence.

Types

type Collection

type Collection[T any] interface {
	Sequence[T]

	Count() int
}

Sequence's extended interfaces, can provide more information to optimize performance.

type Collector

type Collector[S any, T any, R any] interface {
	Builder() S
	Append(builder S, element T)
	Finish(builder S) R
}

type Iterator

type Iterator[T any] interface {
	Next() option.Option[T]
}

By implementing Next you can perform iterations and end them when the return value is None.

type Pair

type Pair[T, R any] struct {
	First  T
	Second R
}

type Sequence

type Sequence[T any] interface {
	Iterator() Iterator[T]
}

Sequence can be obtained iteratively through Iterator, and each iterator should be independent.

func Concat

func Concat[T any](left Sequence[T], right Sequence[T]) Sequence[T]

By connecting two Sequences in series, the new Sequence will iterate over the first Sequence before continuing with the second Sequence.

func Enumerate

func Enumerate[T any](it Sequence[T]) Sequence[Pair[int, T]]

Add subscripts to the incoming Sequence.

func Filter

func Filter[T any](predicate func(T) bool, it Sequence[T]) Sequence[T]

Use predicate to filter an Sequence to another Sequence

func Flatten

func Flatten[T Sequence[U], U any](it Sequence[T]) Sequence[U]

Converting a nested Sequence to a flat Sequence.

func Limit

func Limit[T any](count int, it Sequence[T]) Sequence[T]

Convert an Sequence to another Sequence that limits the maximum number of iterations.

func Map

func Map[T any, R any](transform func(T) R, it Sequence[T]) Sequence[R]

Use transform to map an Sequence to another Sequence.

func Skip

func Skip[T any](count int, it Sequence[T]) Sequence[T]

Converts an Sequence to another Sequence that skips a specified number of times.

func Step

func Step[T any](count int, it Sequence[T]) Sequence[T]

Converts an Sequence to another Sequence that skips a specified number of times each time.

func Zip

func Zip[T any, U any](left Sequence[T], right Sequence[U]) Sequence[Pair[T, U]]

Compress two Sequences into one Sequence. The length is the length of the shortest Sequence.

type Slice

type Slice[T any] []T

Collection is implemented via Slice, which is isomorphic to the built-in slice.

func ToSlice

func ToSlice[T any](c Collection[T]) Slice[T]

Converts a collection to a Slice.

func (Slice[T]) Count

func (a Slice[T]) Count() int

func (Slice[T]) Iterator

func (a Slice[T]) Iterator() Iterator[T]

type String

type String string

Collection is implemented via String, which is isomorphic to the built-in string.

func (String) Count

func (a String) Count() int

func (String) Iterator

func (a String) Iterator() Iterator[rune]

Jump to

Keyboard shortcuts

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