Skip to content

Instantly share code, notes, and snippets.

@campoy
Created February 12, 2018 17:31
Show Gist options
  • Save campoy/e3d2381be01dfcb499a0495d069f3b8d to your computer and use it in GitHub Desktop.
Save campoy/e3d2381be01dfcb499a0495d069f3b8d to your computer and use it in GitHub Desktop.
gist 1 for episode 28 of justforfunc
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