Created
January 7, 2016 22:07
-
-
Save nathanhillyer/dc097df0d6238ce706ed to your computer and use it in GitHub Desktop.
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
func reverseAndRepeatString(stringToReverse: String, numberOfReverses: Int) -> String { | |
let reverseString: () -> String = { transformString(stringToReverse, transformation: { String($0.characters.reverse()) }) } | |
let repeatString: (() -> String) -> String = { | |
var repeated = "" | |
for _ in 1...numberOfReverses { | |
repeated += $0() | |
} | |
return repeated | |
} | |
return applyResultsOfClosure(reverseString, toSecondClosure: repeatString) | |
} | |
func transformString(stringToTransform: String, transformation: (String) -> String) -> String { | |
return transformation(stringToTransform) | |
} | |
func applyResultsOfClosure<T, U>(firstClosure: T, toSecondClosure: T -> U) -> U { | |
return toSecondClosure(firstClosure) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment