Created
February 12, 2018 17:31
-
-
Save campoy/e3d2381be01dfcb499a0495d069f3b8d to your computer and use it in GitHub Desktop.
gist 1 for episode 28 of justforfunc
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
func mergeRec(chans ...<-chan int) <-chan int { | |
switch len(chans) { | |
case 0: | |
c := make(chan int) | |
close(c) | |
return c | |
case 1: | |
return chans[0] | |
default: | |
m := len(chans) / 2 | |
return mergeTwo( | |
mergeRec(chans[:m]...), | |
mergeRec(chans[m:]...)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment