Skip to content

Instantly share code, notes, and snippets.

@Pearapps
Last active January 9, 2016 21:34
Show Gist options
  • Save Pearapps/cbbb23fad41c4917621e to your computer and use it in GitHub Desktop.
Save Pearapps/cbbb23fad41c4917621e to your computer and use it in GitHub Desktop.
Map over an array of instances by currying an class method and then invoking the resulting functions
extension String {
func toUpperCase() -> String {
return uppercaseString
}
}
extension SequenceType {
@warn_unused_result
func mapByCalling<T>(@noescape transformer: (Self.Generator.Element) throws -> (() -> T)) rethrows -> [T] {
return try self.map(transformer).map({ $0() })
}
}
["hello", "kednny"].mapByCalling(String.toUpperCase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment