Last active
May 11, 2017 16:23
-
-
Save AshishKapoor/8987a53ab68153ae4ff15ac9361b9237 to your computer and use it in GitHub Desktop.
Higher Order Functions
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
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