Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pavankataria/6e4752fdedff9ec0d2137e851aa7dc87 to your computer and use it in GitHub Desktop.
Save pavankataria/6e4752fdedff9ec0d2137e851aa7dc87 to your computer and use it in GitHub Desktop.
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