Created
December 15, 2018 09:04
-
-
Save ivancorrales/3b3ebcdca3922e92a9088afe1ab122e3 to your computer and use it in GitHub Desktop.
stream.ForEach
This file contains 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" | |
) | |
type message struct { | |
user string | |
message string | |
} | |
var messages = []*message{ | |
{user: "John", message: "Hello Jane"}, | |
{user: "Jane", message: "Hey John, how are you?"}, | |
{user: "John", message: "I'm fine! and you?"}, | |
{user: "Jane", message: "Me too"}, | |
} | |
func main() { | |
stream := koazee.StreamOf(messages) | |
stream.ForEach(func(m *message) { | |
fmt.Printf("%s: \"%s\"\n", m.user, m.message) | |
}).Do() | |
} | |
/** | |
go run main.go | |
John: "Hello Jane" | |
Jane: "Hey John, how are you?" | |
John: "I'm fine! and you?" | |
Jane: "Me too" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment