Skip to content

Instantly share code, notes, and snippets.

@samirGuerdah
Created April 17, 2016 16:47
Show Gist options
  • Save samirGuerdah/aa4f27761503e4ec65b7560813569101 to your computer and use it in GitHub Desktop.
Save samirGuerdah/aa4f27761503e4ec65b7560813569101 to your computer and use it in GitHub Desktop.
Sample flatMap function as extension in Array
extension Array {
func sg_flatMap<U>(transform: (Generator.Element) -> [U]) -> [U] {
var result = [U]()
for item in self {
result.appendContentsOf(transform(item))
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment