Documentation ¶
Index ¶
- func Collect[T, A any](st Stream[T], identity A, accumulator func(A, T)) A
- func Distinct[T comparable]() func(T) bool
- func DistinctUsing[T any, C comparable](mapper func(T) C) func(T) bool
- func NaturalOrder[T constraints.Ordered](a, b T) bool
- func ReverseOrder[T constraints.Ordered](a, b T) bool
- type Stream
- func FlatMap[T, R any](st Stream[T], mapper func(element T) Stream[R]) Stream[R]
- func Generate[T any](generator func() T) Stream[T]
- func Iterate[T any](seed T, operator func(T) T) Stream[T]
- func Map[T, R any](st Stream[T], mapper func(element T) R) Stream[R]
- func Of[T any](x ...T) Stream[T]
- func Slice[T any](x []T) Stream[T]
- func While[T any](hasNext func() bool, supplier func() T) Stream[T]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Distinct ¶
func Distinct[T comparable]() func(T) bool
Example ¶
package main import ( "fmt" "github.com/AlexanderYastrebov/stream" ) func print[T any](x T) { fmt.Println(x) } func main() { stream.Of("a", "bb", "bb", "a", "ccc", "a", "dddd"). Filter(stream.Distinct[string]()). ForEach(print[string]) }
Output: a bb ccc dddd
func DistinctUsing ¶
func DistinctUsing[T any, C comparable](mapper func(T) C) func(T) bool
Example ¶
package main import ( "fmt" "strings" "github.com/AlexanderYastrebov/stream" ) func print[T any](x T) { fmt.Println(x) } func main() { concat := func(s []string) string { return strings.Join(s, " ") } stream.Of( []string{"a"}, []string{"b", "b"}, []string{"b", "b"}, []string{"a"}, []string{"c", "c", "c"}, []string{"a"}, []string{"d", "d", "d", "d"}). Filter(stream.DistinctUsing(concat)). ForEach(print[[]string]) }
Output: [a] [b b] [c c c] [d d d d]
func NaturalOrder ¶
func NaturalOrder[T constraints.Ordered](a, b T) bool
func ReverseOrder ¶
func ReverseOrder[T constraints.Ordered](a, b T) bool
Types ¶
type Stream ¶
type Stream[T any] interface { Filter(predicate func(element T) bool) Stream[T] Map(mapper func(element T) T) Stream[T] FlatMap(mapper func(element T) Stream[T]) Stream[T] Peek(consumer func(element T)) Stream[T] Limit(n int) Stream[T] Skip(n int) Stream[T] Sorted(less func(T, T) bool) Stream[T] Append(Stream[T]) Stream[T] ForEach(consumer func(element T)) Reduce(accumulator func(T, T) T) (T, bool) AllMatch(predicate func(element T) bool) bool AnyMatch(predicate func(element T) bool) bool NoneMatch(predicate func(element T) bool) bool FindFirst() (T, bool) Min(less func(T, T) bool) (T, bool) Max(less func(T, T) bool) (T, bool) Count() int ToSlice() []T // contains filtered or unexported methods }
func FlatMap ¶
Example ¶
package main import ( "fmt" "github.com/AlexanderYastrebov/stream" ) func print[T any](x T) { fmt.Println(x) } func main() { runes := func(s string) stream.Stream[rune] { return stream.Slice([]rune(s)) } s := stream.Of("a", "bb", "ccc", "dddd") stream.FlatMap(s, runes). Limit(4). ForEach(print[rune]) }
Output: 97 98 98 99
func Generate ¶
Example ¶
package main import ( "fmt" "github.com/AlexanderYastrebov/stream" ) func print[T any](x T) { fmt.Println(x) } func main() { stream.Generate(func() string { return "a" }). Limit(3). ForEach(print[string]) }
Output: a a a
func Iterate ¶
Example ¶
package main import ( "fmt" "github.com/AlexanderYastrebov/stream" ) func print[T any](x T) { fmt.Println(x) } func main() { stream.Iterate(3, func(x int) int { return x + 2 }). Limit(4). ForEach(print[int]) }
Output: 3 5 7 9
Click to show internal directories.
Click to hide internal directories.