Skip to content

Instantly share code, notes, and snippets.

@islishude
Created October 17, 2018 11:52
Show Gist options
  • Save islishude/4f20935ca54b77ea055fd0dd581f3168 to your computer and use it in GitHub Desktop.
Save islishude/4f20935ca54b77ea055fd0dd581f3168 to your computer and use it in GitHub Desktop.
goroutine with pipeline
package main
import (
"fmt"
)
func main() {
data := []int{1, 2, 3, 4}
// data |> time |> plus
ret := plus(time(data))
fmt.Println(ret)
}
func time(data []int) (c chan int) {
c = make(chan int)
go func() {
defer close(c)
for _, v := range data {
c <- v * 2
}
}()
return
}
func plus(data chan int) (ret []int) {
for n := range data {
ret = append(ret, n+1)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment