Skip to content

Instantly share code, notes, and snippets.

@PaulTaykalo
Last active November 6, 2019 12:28
Show Gist options
  • Select an option

  • Save PaulTaykalo/2ebfe0d7c1ca9fff1938506e910f738c to your computer and use it in GitHub Desktop.

Select an option

Save PaulTaykalo/2ebfe0d7c1ca9fff1938506e910f738c to your computer and use it in GitHub Desktop.
let a: Double? = 1.0
let b: Double? = 2.0
let c: Double? = 3.0
let d: Double? = 4.0
let e: Double? = 5.0
let f: Double? = 6.0
let g: Double? = 7.0
extension Optional {
func `or`(_ value : Wrapped?) -> Optional {
return self ?? value
}
func `or`(_ value: Wrapped) -> Wrapped {
return self ?? value
}
}
//let result = a ?? b ?? c ?? d ?? e ?? f ?? g ?? 1.0 // <--- This will fail to compile
let result = a.or(b).or(c).or(d).or(e).or(f).or(g).or(1.0) // <--- This will not
print(result)
@gsampaio
Copy link
Copy Markdown

Basically the problem is the type checker constrain solver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment