Created
May 20, 2020 11:43
-
-
Save stevencurtis/72494e3ead36f8080514cf9e72d7cdcb to your computer and use it in GitHub Desktop.
enumcalculator
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 Operand: String { | |
case addition = "+" | |
case subtraction = "-" | |
case multiplication = "*" | |
case division = "/" | |
} | |
func operation (operand: Operand) -> ((Int, Int) -> Int) { | |
func addition (a: Int, b: Int) -> Int { | |
return a + b | |
} | |
func subtraction (a: Int, b: Int) -> Int { | |
return a - b | |
} | |
func multiplication (a: Int, b: Int) -> Int { | |
return a * b | |
} | |
func division (a: Int, b: Int) -> Int { | |
return a / b | |
} | |
switch operand { | |
case .addition: | |
return addition | |
case .subtraction: | |
return subtraction | |
case .multiplication: | |
return multiplication | |
case .division: | |
return division | |
} | |
} | |
var function = operation(operand: Operand.addition) | |
print("1 + 2 = \(function(1,2))") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment