Created
June 30, 2017 15:02
-
-
Save dudarenko-io/79da3c7e301c2c233e2e9c827c3604b0 to your computer and use it in GitHub Desktop.
Functions are functors too. Map function implemented to concatenate functions
This file contains hidden or 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
func map<T,S,U>(_ f: @escaping (T)->S, _ g: @escaping (S)->U) -> (T) -> U { | |
return {x in g(f(x)) } | |
} | |
let countNumberOfDigits = map( { (n: Int) in "\(n)" }, { (str: String) in str.characters.count } ) | |
countNumberOfDigits(12345) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment