doc: add document for stream package

This commit is contained in:
dudaodong committed 2023-04-05 20:17:41 +08:00
1 parent 5b9b4c4344
commit c53d541a6b
4 files changed
+1822 -10

No files matched your search

+2 -2
View File
@@ -51,7 +51,7 @@ type stream[T any] struct {
source []T
}
// Of creates a stream stream whose elements are the specified values.
// Of creates a stream whose elements are the specified values.
// Play: https://go.dev/play/p/jI6_iZZuVFE
func Of[T any](elems ...T) stream[T] {
return FromSlice(elems)
@@ -268,7 +268,7 @@ func (s stream[T]) ForEach(action func(item 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.
// Play: https://go.dev/play/p/g-xkHiuIpTi
// Play: https://go.dev/play/p/6uzZjq_DJLU
func (s stream[T]) Reduce(initial T, accumulator func(a, b T) T) T {
for _, v := range s.source {
initial = accumulator(initial, v)