Skip to content

Instantly share code, notes, and snippets.

@jpavley
Last active September 24, 2015 15:47
Show Gist options
  • Save jpavley/085db3b177e3398c6a4e to your computer and use it in GitHub Desktop.
Save jpavley/085db3b177e3398c6a4e to your computer and use it in GitHub Desktop.
code from CS193P: Developing iOS 8 Applications with Swift that longer compiles with the solution
// bad code
func performOperationWith(operation: (Double, Double) -> Double) {
if operandStack.count >= 2 {
displayValue = operation(operandStack.removeLast(), operandStack.removeLast())
enter()
}
}
func performOperation(operation: Double -> Double) {
if operandStack.count >= 1 {
displayValue = operation(operandStack.removeLast())
enter()
}
}
// good code
func performOperationWithTwoOperands(operation: (Double, Double) -> Double) {
if operandStack.count >= 2 {
displayValue = operation(operandStack.removeLast(), operandStack.removeLast())
enter()
}
}
func performOperationWithOneOperand(operation: Double -> Double) {
if operandStack.count >= 1 {
displayValue = operation(operandStack.removeLast())
enter()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment