From 599250092ba58f22a81c0f9c283528f47469a9a2 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Mon, 13 Jul 2020 10:48:08 +0200 Subject: [PATCH] Example #19: Improper combination of more stream manipulators --- lesson7/lazy_streams/19_combinations_error.go | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lesson7/lazy_streams/19_combinations_error.go diff --git a/lesson7/lazy_streams/19_combinations_error.go b/lesson7/lazy_streams/19_combinations_error.go new file mode 100644 index 0000000..b6a7dcf --- /dev/null +++ b/lesson7/lazy_streams/19_combinations_error.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "github.com/wesovilabs/koazee" +) + +func printInt(x int) { + fmt.Printf("%d\n", x) +} + +func doubleValue(x int) int { + return x * 2 +} + +func negate(x int) int { + return -x +} + +func evenValue(x int) bool { + return x%2 == 0 +} + +func divisibleBy3(x int) bool { + return x%3 == 0 +} + +func main() { + values1 := []int{1, 2, 3} + fmt.Printf("input #1: %v\n", values1) + + stream1 := koazee.StreamOf(values1). + Filter(evenValue). + Filter(divisibleBy3). + Map(negate). + Map(doubleValue) + stream1.ForEach(printInt).Do() +}