Skip to content

Instantly share code, notes, and snippets.

@ivancorrales
Created December 15, 2018 09:04
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/3b3ebcdca3922e92a9088afe1ab122e3 to your computer and use it in GitHub Desktop.
Save ivancorrales/3b3ebcdca3922e92a9088afe1ab122e3 to your computer and use it in GitHub Desktop.
stream.ForEach
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