Is there a better way to write this if-statement, which has ultimately four outcomes among three variables?
I looked into guard and switch but I'm not sure if either of those capture the joined boolean states well? I could individually list the four outcomes as joined boolean statements (eg, isPartialResult == true && calculated == nil, so on..) but that isn't necessarily more readable or efficient (more to type). Thanks!
case .BinaryOperation(let function):
if isPartialResult == true {
if calculated == nil {
log += (" \(accumulator) \(symbol)") // add new op
} else {
log += (" \(symbol)") // add symbol to calculated, prepare for new op
calculated = nil
}
} else {
if log.characters.count <= 1 {
log += (" \(accumulator) \(symbol)") // start from beginning
} else {
log += (" \(symbol)") // restart from equal
}
}
executePendingBinaryOperation()
pending = pendingBinaryOperationInfo(binaryFunction: function, firstOperand: accumulator)
isPartialResult = true
Aucun commentaire:
Enregistrer un commentaire