Last active
January 9, 2016 21:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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