Documentation ¶
Overview ¶
Package order provides helper functions and contraints to allow ordering streams
Index ¶
- Constants
- func AllMatch[T any](input stream[T], predicate func(T) bool) bool
- func AnyMatch[T any](input stream[T], predicate func(T) bool) bool
- func Concat[T any](s1, s2 stream[T]) stream[T]
- func Count[T any](input stream[T]) int
- func Distinct[T comparable](s stream[T]) stream[T]
- func FlatMap[IN, OUT any](input stream[IN], mapper func(IN) stream[OUT]) stream[OUT]
- func ForEach[T any](input stream[T], consumer func(T))
- func Generate[T any](fn func() (T, bool)) stream[T]
- func IgnoreCase(a, b string) int
- func Int[T constraints.Integer](a, b T) int
- func Limit[T any](s stream[T], n int) stream[T]
- func Map[I any, O any](s stream[I], fn func(I) O) stream[O]
- func Max[T any](input stream[T], cmp Comparator[T]) (T, bool)
- func Min[T any](input stream[T], cmp Comparator[T]) (T, bool)
- func Natural[T constraints.Ordered](a, b T) int
- func NoneMatch[T any](input stream[T], predicate func(T) bool) bool
- func Of[T any](elems ...T) stream[T]
- func OfChannel[T any](ch chan T) stream[T]
- func OfSlice[T any](elems []T) stream[T]
- func Peek[T any](input stream[T], consumer func(T)) stream[T]
- func Range[T constraints.Integer](start, end T) stream[T]
- func Reduce[I any, O any](s stream[I], identity O, accumulator func(O, I) O, combiner func(O, O) O) O
- func ReduceSequentially[I any, O any](s stream[I], identity O, accumulator func(O, I) O) O
- func Skip[T any](input stream[T], n int) stream[T]
- func SortSlice[T any](slice []T, comparator Comparator[T])
- func Sorted[T any](s stream[T], comparator Comparator[T]) stream[T]
- type Comparator
Constants ¶
const ParallelMergeSortThreshold = 1 << 12
Variables ¶
This section is empty.
Functions ¶
func AllMatch ¶
AllMatch returns whether all elements of this stream match the provided predicate. If this operation finds an item where the predicate is false, it stops processing the rest of the stream. If the stream is empty then true is returned and the predicate is not evaluated. This function is equivalent to invoking input.AllMatch(predicate) as method
func AnyMatch ¶
AnyMatch returns whether any elements of this stream match the provided predicate. If this operation finds an item where the predicate is true, it stops processing the rest of the stream. If the stream is empty then false is returned and the predicate is not evaluated. This function is equivalent to invoking input.AnyMatch(predicate) as method
func Concat ¶
func Concat[T any](s1, s2 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. The resulting stream is ordered if both of the input streams are ordered, and parallel if either of the input streams is parallel. When the resulting stream is closed, the close handlers for both input streams are invoked.
func Distinct ¶
func Distinct[T comparable](s stream[T]) stream[T]
func FlatMap ¶
func FlatMap[IN, OUT any](input stream[IN], mapper func(IN) stream[OUT]) stream[OUT]
FlatMap returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream is null an empty stream is used, instead.)
Due to the lazy nature of streams, if any of the mapped streams is infinite it will remain unnoticed and some operations (Count, Reduce, Sorted, AllMatch...) will not end.
When both the input and output type are the same, the operation can be invoked as the method input.FlatMap(mapper).
func ForEach ¶
func ForEach[T any](input stream[T], consumer func(T))
--- terminals ForEach invokes the consumer function for each item of the stream. This function is equivalent to invoking input.ForEach(consumer) as method. The behavior of this operation is explicitly nondeterministic. For parallel stream pipelines, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever thread the library chooses. If the action accesses shared state, it is responsible for providing the required synchronization.
func IgnoreCase ¶
IgnoreCase implements order.Comparator for strings, ignoring the case.
func Int ¶
func Int[T constraints.Integer](a, b T) int
Int implements the Comparator for signed integers. This will be usually faster than Natural comparator
func Limit ¶
Limit returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length. This function is equivalent to invoking input.Limit(maxSize) as method.
func Max ¶
func Max[T any](input stream[T], cmp Comparator[T]) (T, bool)
Max returns the maximum element of this stream according to the provided Comparator, along with true if the stream is not empty. If the stream is empty, returns the zero value along with false. This function is equivalent to invoking input.Max(cmp) as method.
func Min ¶
func Min[T any](input stream[T], cmp Comparator[T]) (T, bool)
Min returns the minimum element of this stream according to the provided Comparator, along with true if the stream is not empty. If the stream is empty, returns the zero value along with false. This function is equivalent to invoking input.Min(cmp) as method.
func Natural ¶
func Natural[T constraints.Ordered](a, b T) int
Natural implements the Comparator for those elements whose type has a natural order (numbers and strings)
func NoneMatch ¶
NoneMatch returns whether no elements of this stream match the provided predicate. If this operation finds an item where the predicate is true, it stops processing the rest of the stream. This function is equivalent to invoking input.NoneMatch(predicate) as method.
func Peek ¶
func Peek[T any](input stream[T], consumer func(T)) stream[T]
Peek peturns 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. This function is equivalent to invoking input.Peek(consumer) as method. For parallel stream pipelines, the action may be called at whatever time and in whatever thread the element is made available by the upstream operation. If the action modifies shared state, it is responsible for providing the required synchronization.
func Range ¶
func Range[T constraints.Integer](start, end T) stream[T]
Range returns a stream of integers from start (inclusive) to end (exclusive) The generating process is thread-safe
func Reduce ¶
func Reduce[I any, O any](s stream[I], identity O, accumulator func(O, I) O, combiner func(O, O) O) O
the identity element is both an initial seed value for the reduction and a default result if there are no input elements. The accumulator function takes a partial result and the next element, and produces a new partial result. The combiner function combines two partial results to produce a new partial result.
func ReduceSequentially ¶
ReduceSequentially Performs a reduction on the elements of this stream, using the provided identity value and an associative accumulation function, and returns the reduced value. The identity value must be an identity for the accumulator function. This means that for all t, accumulator.apply(identity, t) is equal to t. The accumulator function must be an associative function.
func Skip ¶
Skip returns a stream consisting of the remaining elements of this stream after discarding the first n elements of the stream. This function is equivalent to invoking input.Skip(n) as method.
func SortSlice ¶
func SortSlice[T any](slice []T, comparator Comparator[T])
SortSlice sorts the given slice according to the criteria in the provided comparator
func Sorted ¶
func Sorted[T any](s stream[T], comparator Comparator[T]) stream[T]
Sorted returns a stream consisting of the elements of this stream, sorted according to the provided Comparator. This function is equivalent to invoking s.Sorted(comparator) as method.
Types ¶
type Comparator ¶
Comparator function compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
func Inverse ¶
func Inverse[T any](cmp Comparator[T]) Comparator[T]
Inverse result of the Comparator function for inverted sorts