Skip to content

Instantly share code, notes, and snippets.

@AshishKapoor
Last active May 11, 2017 16:23
Show Gist options
  • Save AshishKapoor/8987a53ab68153ae4ff15ac9361b9237 to your computer and use it in GitHub Desktop.
Save AshishKapoor/8987a53ab68153ae4ff15ac9361b9237 to your computer and use it in GitHub Desktop.
Higher Order Functions
import UIKit
// Function as a argument.
/*
Reference: https://www.youtube.com/channel/UC-d1NWv5IWtIkfH47ux4dWA, The Swift Guy
*/
func animorphs(getMutation: (_ sugar: String, _ spice: String) -> String, humanSays: String, animalSays: String) -> String {
return getMutation(humanSays, animalSays)
}
func alexSays(_ firstWord: String,_ secondWord: String) -> String {
return "Alex Says: \(firstWord) -> \(secondWord)"
}
func jakeSays(_ firstWord: String,_ secondWord: String) -> String {
return "Jake Says: \(firstWord) -> \(secondWord)"
}
animorphs(getMutation: jakeSays(_: _:), humanSays: "Hello!", animalSays: "Meow!") // Jake Says: Hello! -> Meow!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment