Last active
December 15, 2018 09:11
-
-
Save ivancorrales/05bdae777afa29490fc266e43fe7709b to your computer and use it in GitHub Desktop.
stream.Take / stream.Filter / stream.RemoveDuplicates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/wesovilabs/koazee" | |
) | |
var animals = []string{"lynx", "dog", "cat", "monkey", "dog", "fox", "tiger", "lion"} | |
func main() { | |
fmt.Print("input: ") | |
fmt.Println(animals) | |
stream := koazee.StreamOf(animals) | |
fmt.Print("stream.Take(1,4): ") | |
fmt.Println(stream.Take(1, 4).Out().Val()) | |
fmt.Print("stream.Filter(len==4): ") | |
fmt.Println(stream. | |
Filter( | |
func(val string) bool { | |
return len(val) == 4 | |
}). | |
Out().Val(), | |
) | |
fmt.Print("stream.RemoveDuplicates(): ") | |
fmt.Println(stream.RemoveDuplicates().Out().Val()) | |
} | |
/** | |
go run main.go | |
input: [lynx dog cat monkey dog fox tiger lion] | |
stream.Take(1,4): [dog cat monkey dog] | |
stream.Filter(len==4): [lynx lion] | |
stream.RemoveDuplicates(): [lynx dog cat monkey fox tiger lion] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment