Skip to content

Instantly share code, notes, and snippets.

@Athosone
Created October 2, 2018 16:04
Show Gist options
  • Save Athosone/4fde39dfa0ebd4d6524a7b128355b3e4 to your computer and use it in GitHub Desktop.
Save Athosone/4fde39dfa0ebd4d6524a7b128355b3e4 to your computer and use it in GitHub Desktop.
Curry example - ForEach
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