Skip to content

Instantly share code, notes, and snippets.

@sharplet
Created February 9, 2015 10:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharplet/1134d06523b37adcdc9a to your computer and use it in GitHub Desktop.
Save sharplet/1134d06523b37adcdc9a to your computer and use it in GitHub Desktop.
Generic concatenation of sequences in Swift
func + <S: SequenceType, E where S.Generator.Element == E> (lhs: S, rhs: S) -> GeneratorOf<E> {
var (g, h) = (lhs.generate(), rhs.generate())
return GeneratorOf {
g.next() ?? h.next()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment