Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanhillyer/dc097df0d6238ce706ed to your computer and use it in GitHub Desktop.
Save nathanhillyer/dc097df0d6238ce706ed to your computer and use it in GitHub Desktop.
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