1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 08:42:29 +08:00

doc: add document for stream package

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

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)