stream

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map

func Map[T, R any](source []T, f func(T) R) []R

Types

type Compare

type Compare[T any] func(a T, b T) int

Compare a and b

if a > b return number > 0

if a == b return 0

if a < b return number < 0

type Filter

type Filter[T any] func(T) bool

type ForEach

type ForEach[T any] func(T)

type Match

type Match[T any] func(T) bool

type Stream

type Stream[T any] interface {
	// Filter returns a stream consisting of the elements of this stream that match the given predicate
	Filter(Filter[T]) Stream[T]
	// ForEach performs an action for each element of this stream
	ForEach(ForEach[T])
	// Reverse returns a stream consisting of the elements of this stream, reverse the order of elements
	Reverse() Stream[T]
	// Count returns the count of elements in this stream
	Count() int
	// ToSlice return slice containing the elements of this stream
	ToSlice() []T
	// Limit returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length
	Limit(int) Stream[T]
	// Min returns the minimum element of this stream according to the provided Comparator
	Min(Compare[T]) T
	// Max returns the maximum element of this stream according to the provided Comparator
	Max(Compare[T]) T
	// Skip returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream
	// If this stream contains fewer than do nothing
	Skip(int) Stream[T]
	// Sorted Returns a stream consisting of the elements of this stream, sorted according to the given method
	Sorted(Compare[T]) Stream[T]
	// Peek returns a stream consisting of the elements of this stream,
	// additionally performing the provided action on each element as elements are consumed from the resulting stream
	Peek(ForEach[T]) Stream[T]
	// AnyMatch returns whether any elements of this stream match the provided predicate.
	// May not evaluate the predicate on all elements if not necessary for determining the result.
	// If the stream is empty then false is returned and the predicate is not evaluated
	AnyMatch(Match[T]) bool
	// AllMatch returns whether all elements of this stream match the provided predicate.
	// May not evaluate the predicate on all elements if not necessary for determining the result.
	// If the stream is empty then true is returned and the predicate is not evaluated
	AllMatch(Match[T]) bool
	// NoneMatch returns whether no elements of this stream match the provided predicate.
	// May not evaluate the predicate on all elements if not necessary for determining the result.
	// If the stream is empty then true is returned and the predicate is not evaluated
	NoneMatch(Match[T]) bool
	// FindAny returns an element that matches the given method, or any empty value if the stream is empty or not match
	FindAny(Match[T]) T
	// FindFirst returns an element describing the first element of this stream, or an empty value if the stream is empty
	FindFirst() T
	// FindLast returns an element describing the last element of this stream, or ant empty value if the stream is empty
	FindLast() T
}

func New

func New[T any](arr []T) Stream[T]

Jump to

Keyboard shortcuts

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