Skip to content

Instantly share code, notes, and snippets.

@kongtomorrow
Created July 31, 2014 19:08
Show Gist options
  • Save kongtomorrow/4adaf4c3ebc93b6e789b to your computer and use it in GitHub Desktop.
Save kongtomorrow/4adaf4c3ebc93b6e789b to your computer and use it in GitHub Desktop.
unwrap-or
operator infix !|| { associativity right precedence 100 } // associativity/precedence copied from ternary ? :
@infix func !||<T>(lhs:T?, rhs:@auto_closure ()->T) -> T {
switch lhs {
case nil: return rhs()
case _: return lhs!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment