stream

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stream

type Stream[T any] struct {
	// contains filtered or unexported fields
}

func Concat

func Concat[T any](a, b Stream[T]) Stream[T]

Concat creates a lazily concatenated Stream whose elements are all the elements of the first Stream followed by all the elements of the second Stream.

func FromChannel

func FromChannel[T any](source <-chan T) Stream[T]

FromChannel creates Stream from channel.

func FromRange

func FromRange[T constraints.Integer | constraints.Float](start, end, step T) Stream[T]

FromRange creates a number Stream from start to end. both start and end are included. [start, end]

func FromSlice

func FromSlice[T any](source []T) Stream[T]

FromSlice creates Stream from slice.

func Generate

func Generate[T any](generator func() func() (item T, ok bool)) Stream[T]

Generate Stream where each element is generated by the provided generater function

func Of

func Of[T any](elems ...T) Stream[T]

Of creates a Stream whose elements are the specified values.

func (Stream[T]) AllMatch

func (s Stream[T]) AllMatch(predicate func(item T) bool) bool

AllMatch returns whether all elements of this Stream match the provided predicate.

func (Stream[T]) AnyMatch

func (s Stream[T]) AnyMatch(predicate func(item T) bool) bool

AnyMatch returns whether any elements of this Stream match the provided predicate.

func (Stream[T]) Count

func (s Stream[T]) Count() int

Count returns the count of elements in the Stream.

func (Stream[T]) Distinct

func (s Stream[T]) Distinct() Stream[T]

Distinct returns a Stream that removes the duplicated items.

func (Stream[T]) Filter

func (s Stream[T]) Filter(predicate func(item T) bool) Stream[T]

Filter returns a Stream consisting of the elements of this Stream that match the given predicate.

func (Stream[T]) FindFirst

func (s Stream[T]) FindFirst() (T, bool)

FindFirst returns the first element of this Stream and true, or zero value and false if the Stream is empty.

func (Stream[T]) FindLast

func (s Stream[T]) FindLast() (T, bool)

FindLast returns the last element of this Stream and true, or zero value and false if the Stream is empty.

func (Stream[T]) ForEach

func (s Stream[T]) ForEach(action func(item T))

ForEach performs an action for each element of this Stream.

func (Stream[T]) Limit

func (s Stream[T]) Limit(maxSize int) Stream[T]

Limit returns a Stream consisting of the elements of this Stream, truncated to be no longer than maxSize in length.

func (Stream[T]) Map

func (s Stream[T]) Map(mapper func(item T) T) Stream[T]

Map returns a Stream consisting of the elements of this Stream that apply the given function to elements of Stream.

func (Stream[T]) Max

func (s Stream[T]) Max(less func(a, b T) bool) (T, bool)

Max returns the maximum element of this Stream according to the provided less function. less: a > b

func (Stream[T]) Min

func (s Stream[T]) Min(less func(a, b T) bool) (T, bool)

Min returns the minimum element of this Stream according to the provided less function. less: a < b

func (Stream[T]) NoneMatch

func (s Stream[T]) NoneMatch(predicate func(item T) bool) bool

NoneMatch returns whether no elements of this Stream match the provided predicate.

func (Stream[T]) Peek

func (s Stream[T]) Peek(consumer func(item 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.

func (Stream[T]) Range

func (s Stream[T]) Range(start, end int) Stream[T]

Range returns a Stream whose elements are in the range from start(included) to end(excluded) original Stream.

func (Stream[T]) Reduce

func (s Stream[T]) Reduce(initial T, accumulator func(a, b T) T) T

Reduce performs a reduction on the elements of this Stream, using an associative accumulation function, and returns an Optional describing the reduced value, if any.

func (Stream[T]) Reverse

func (s Stream[T]) Reverse() Stream[T]

Reverse returns a Stream whose elements are reverse order of given Stream.

func (Stream[T]) Skip

func (s Stream[T]) Skip(n int) Stream[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 n elements then an empty Stream will be returned.

func (Stream[T]) Sorted

func (s Stream[T]) Sorted(less func(a, b T) bool) Stream[T]

Sorted returns a Stream consisting of the elements of this Stream, sorted according to the provided less function.

func (Stream[T]) ToSlice

func (s Stream[T]) ToSlice() []T

ToSlice return the elements in the Stream.

Jump to

Keyboard shortcuts

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