go-stream is a Go library for working with streamed data. It is inspired by the Java 8 Stream API.
go get github.com/r-evolve/go-stream
package main
import (
"fmt"
"github.com/r-evolve/go-stream"
)
func main() {
// Create a stream from a slice
stream := go_stream.New([]int{1, 2, 3, 4, 5})
// Filter the stream
stream = stream.Filter(func(i int) bool {
return i > 2
})
// Map the stream
stream = stream.Map(func(i int) int {
return i * 2
})
// Reduce the stream
sum := stream.Reduce(func(a, b int) int {
return a + b
}, 0)
// Print the result
fmt.Println(sum)
}
package main
import (
"fmt"
"github.com/r-evolve/go-stream"
)
func main() {
// Create a stream from a slice
stream := go_stream.New([]int{1, 2, 3, 4, 5})
// Print the result
fmt.Println(stream.Filter(func(i int) bool {
return i > 2
}).Map(func(i int) int {
return i * 2
}).Reduce(func(a, b int) int {
return a + b
}, 0))
}
package main
import (
"fmt"
"github.com/r-evolve/go-stream"
)
func main() {
// Create channels from single values
_ = go_stream.Of(1, 2, 3, 4, 5).ToChannel()
}