         }
     }
 }
+
+private extension String {
+    var doubleValue: Double {
+        guard let double = Double(self) else {
+           return Double.infinity
+        }
+        return double
+    }
+}

            return state.mapScreen { "\((Double($0) ?? 0.0) / 100.0)" }
        case .operation(let o):
            switch state {
            case let .oneOperand(_, screen):
                return .oneOperandAndOperator(operand: Double(screen) ?? 0.0, operator: o, screen: "0", lastCommandIsOperator: true)
            case let .oneOperandAndOperator(operand, oldOperator, screen, lastCommandIsOperator):
                if lastCommandIsOperator {
                    return .oneOperandAndOperator(operand: operand, operator: o, screen: screen, lastCommandIsOperator: true)
                } else {
                    return .oneOperandAndOperator(operand: oldOperator.perform(operand, Double(screen) ?? 0.0), operator: o, screen: "0", lastCommandIsOperator: true)
                }
            }
        case .equal:
            switch state {
            case let .oneOperandAndOperator(lhs, o, screen, _):
                let result = o.perform(lhs, Double(screen) ?? 0.0)
                return .oneOperand(operand: result, screen: String(result))
            default:
                return state
            }

}

enum CalculatorState {
    case oneOperand(screen: String)
    case oneOperandAndOperator(operand: Double, operator: Operator)
    case twoOperandsAndOperator(operand: Double, operator: Operator, screen: String)
}

extension CalculatorState {
    static let initial = CalculatorState.oneOperand(screen: "0")

    func mapScreen(transform: (String) -> String) -> CalculatorState {
        switch self {
        case let .oneOperand(screen):
            return .oneOperand(screen: transform(screen))
        case let .oneOperandAndOperator(operand, operat):
            return .twoOperandsAndOperator(operand: operand, operator: operat, screen: transform("0"))
        case let .twoOperandsAndOperator(operand, operat, screen):
            return .twoOperandsAndOperator(operand: operand, operator: operat, screen: transform(screen))
        }
    }

    var screen: String {
        switch self {
        case let .oneOperand(screen):
            return screen
        case .oneOperandAndOperator:
            return "0"
        case let .twoOperandsAndOperator(_, _, screen):
            return screen
        }
    }

    var sign: String {
        switch self {
        case .oneOperand:
            return ""
        case let .oneOperandAndOperator(_, o):
            return o.sign
        case let .twoOperandsAndOperator(_, o, _):
            return o.sign
        }
    }
