Skip to content

Instantly share code, notes, and snippets.

@EJSohn
Created May 2, 2018 12:31
Show Gist options
  • Select an option

  • Save EJSohn/64feec7324f74bcf352641d097f932fb to your computer and use it in GitHub Desktop.

Select an option

Save EJSohn/64feec7324f74bcf352641d097f932fb to your computer and use it in GitHub Desktop.
func evaluate(_ expression: ArithmeticExpression) -> Int {
switch expression {
case let .number(value):
return value
case let .addition(left, right):
return evaluate(left) + evaluate(right)
case let .multiplication(left, right):
return evaluate(left) * evaluate(right)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment