Created
October 17, 2018 11:52
-
-
Save islishude/4f20935ca54b77ea055fd0dd581f3168 to your computer and use it in GitHub Desktop.
goroutine with pipeline
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" | |
) | |
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