Skip to content

Instantly share code, notes, and snippets.

@manas-sharma-1683
Created February 25, 2021 22:51
Show Gist options
  • Save manas-sharma-1683/422fa1ea015b3f792271ab2a4cc2083b to your computer and use it in GitHub Desktop.
Save manas-sharma-1683/422fa1ea015b3f792271ab2a4cc2083b to your computer and use it in GitHub Desktop.
??? operator in swift.
infix operator ???
func ???<T> (_ value: @autoclosure () -> T?, _ error: @autoclosure () -> Error) throws -> T {
guard let value = value() else {
throw error()
}
return value
}
do {
let value = Optional(20) ??? NSError()
print(value)
} catch {
print(error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment