Created
April 6, 2015 22:06
-
-
Save doronkatz/f2ec5901b46f325032ad to your computer and use it in GitHub Desktop.
Nested 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
private func eatFood(IamHungry: Bool) ->String { | |
return IamHungry? eatDinner(1) : eatSnack(1) | |
} | |
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
private func eatFood(IamHungry: Bool) -> String{ | |
func eatDinner(quantity: Int) -> String{ | |
return "I am eating dinner" | |
} | |
func eatSnack(quantity: Int) -> String{ | |
return "I am eating a snack" | |
} | |
return IamHungry ? eatDinner : eatSnack | |
} | |
let mealDecider = eatFood(true) | |
println(mealDecider) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment