Created
October 2, 2018 16:04
-
-
Save Athosone/4fde39dfa0ebd4d6524a7b128355b3e4 to your computer and use it in GitHub Desktop.
Curry example - ForEach
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
enum LogLevel: String { | |
case debug | |
case error | |
} | |
func logMessage(level: LogLevel, message: String) { | |
print("[\(level)] \(message)") | |
} | |
// Without Currying | |
let animals: [String] = ["Dog", "Cat", "Horse", "Fish"] | |
animals.forEach { (animal) in | |
logMessage(.debug, animal) | |
} | |
animals.forEach { (animal) in | |
logMessage(.error, animal) | |
} | |
// With Curry | |
let debug = curry(logMessage)(.debug) | |
let error = curry(logMessage)(.error) | |
let animals: [String] = ["Dog", "Cat", "Horse", "Fish"] | |
animals.forEach(debug) | |
animals.forEach(error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment