Created
January 13, 2015 07:15
-
-
Save sharplet/04ee7fbcc8717f79092b to your computer and use it in GitHub Desktop.
Mapping with methods
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
/// Convert a free method into a regular funcion accepting an instance as the first parameter. | |
func method<A, B>(m: A -> () -> B) -> A -> B { | |
return { m($0)() } | |
} | |
let strings = ["1", "2", "3", "foo"] | |
strings.map(method(String.toInt)) | |
// => [{Some 1}, {Some 2}, {Some 3}, nil] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment