Created
June 12, 2020 14:50
-
-
Save pavankataria/6e4752fdedff9ec0d2137e851aa7dc87 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
let balanceToConvert: String? | |
... | |
if let inputEntry = balance, inputEntry.sign == .negative { | |
balanceToConvert = Int(inputEntry.input) // Can return nil | |
.flatMap(Int.init) // Convert to Int if not nil | |
.flatMap { $0 * -1 } // flip sign if not nil | |
.flatMap(String.init) // convert back to String if not nil | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment