Created
May 7, 2018 14:58
-
-
Save picatz/28eb83224874e4edffc15de50877a3a2 to your computer and use it in GitHub Desktop.
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" | |
var exampleNumbers = []int{1, 2, 3, 4, 5} | |
func sumOfNumbers(numbers []int) <-chan int { | |
var result = make(chan int) | |
go func(ch chan int) { | |
defer close(ch) | |
var sum int | |
for _, number := range numbers { | |
sum += number | |
} | |
ch <- sum | |
}(result) | |
return result | |
} | |
func main() { | |
fmt.Println(<-sumOfNumbers(exampleNumbers)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment