Created
January 2, 2017 00:58
-
-
Save erica/c96834bc27a686f664c2a8a40ed16261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func chargeState(for battery: BatteryService) | |
-> ChargeState | |
{ | |
switch (battery, isCalculating(battery)) { | |
case (.isACPowered, true): | |
return .calculating(isDischarging: false) | |
case (.isACPowered, _) where battery.isCharging: | |
return .charging | |
case (.isACPowered, _): | |
return .power //bypasses error | |
case (_, true): | |
return .calculating(isDischarging: true) | |
default: | |
return .battery | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func chargeState(for battery: BatteryService) | |
--> ChargeState | |
{ | |
let calculating = isCalculating(battery: battery) | |
if battery.isACPowered { | |
if calculating { | |
return .calculating(isDischarging: false) | |
} else if battery.isCharging { | |
return .charging | |
} else if battery.isCharged { | |
return .power | |
} // error here, non-exhaustive tests | |
} else { | |
if calculating { | |
return .calculating(isDischarging: true) | |
} else { | |
return .battery | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment