Skip to content

Commit

Permalink
Dry2
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-ridgway committed Apr 21, 2020
1 parent 831e0e3 commit 5a86ab2
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions CalculatorApp/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,12 @@ func help() {
print("Commands: add, subtract, multiply, divide, history or help")
}

func add() {
let result = calculator.add(gatherNumbers())
print("Result: \(result)")
}

func subtract() {
let result = calculator.subtract(gatherNumbers())
print("Result: \(result)")
}

func divide() {
let result = calculator.divide(gatherNumbers())
print("Result: \(result)")
}

func multiply() {
let result = calculator.multiply(gatherNumbers())
print("Result: \(result)")
func mathFunc(_ fn: @escaping ([Double]) -> Double) -> (() -> ()) {
func x() {
let result = fn(gatherNumbers())
print("Result: \(result)")
}
return x;
}

func history() {
Expand All @@ -62,10 +50,10 @@ func history() {
let commands = [
"quit": quit,
"help": help,
"add": add,
"subtract": subtract,
"divide": divide,
"multiply": multiply,
"add": mathFunc(calculator.add),
"subtract": mathFunc(calculator.subtract),
"divide": mathFunc(calculator.divide),
"multiply": mathFunc(calculator.multiply),
"history": history,
]

Expand Down

0 comments on commit 5a86ab2

Please sign in to comment.