Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created December 17, 2015 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkhl/2874e0797cee3c7ad1a0 to your computer and use it in GitHub Desktop.
Save mkhl/2874e0797cee3c7ad1a0 to your computer and use it in GitHub Desktop.
Power“sets” of Sequences in Swift
func power<Sequence: SequenceType>(items: Sequence) -> [[Sequence.Generator.Element]] {
return items.reduce([[]]) { (arrays, item) in
return arrays + arrays.map { (var array) in
array.append(item)
return array
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment