Skip to content

Instantly share code, notes, and snippets.

@efremidze
Created June 15, 2017 21:28
Show Gist options
  • Save efremidze/243578365098424c48a14f4115d300b4 to your computer and use it in GitHub Desktop.
Save efremidze/243578365098424c48a14f4115d300b4 to your computer and use it in GitHub Desktop.
precedencegroup OptionalAssignmentPrecedence {
associativity: right
lowerThan: AssignmentPrecedence
}
infix operator ?= : OptionalAssignmentPrecedence
public func ?=<T>(optional: inout T?, defaultValue: @autoclosure () -> T?) {
if optional == nil {
optional = defaultValue()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment