Skip to content

Instantly share code, notes, and snippets.

@ivancorrales
Created December 15, 2018 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivancorrales/19a36f855933d6acff2eb97278468cdd to your computer and use it in GitHub Desktop.
Save ivancorrales/19a36f855933d6acff2eb97278468cdd to your computer and use it in GitHub Desktop.
stream.Reduce
package main
import (
"fmt"
"github.com/wesovilabs/koazee"
)
var numbers = []int{1, 5, 4, 3, 2, 7, 1, 8, 2, 3}
func main() {
fmt.Printf("input: %v\n", numbers)
stream := koazee.StreamOf(numbers)
fmt.Print("stream.Reduce(sum): ")
fmt.Println(stream.Reduce(func(acc, val int) int {
return acc + val
}).Int())
}
/**
go run main.go
input: [1 5 4 3 2 7 1 8 2 3]
stream.Reduce(sum): 36
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment