Skip to content

Instantly share code, notes, and snippets.

@bwoods
Created November 21, 2022 23:06
Show Gist options
  • Save bwoods/1ababf85ba936cff787896668b2c4abd to your computer and use it in GitHub Desktop.
Save bwoods/1ababf85ba936cff787896668b2c4abd to your computer and use it in GitHub Desktop.
Swift .not “operator”
public extension Bool {
    static func not(_ exp: @autoclosure () -> Bool) -> Bool {
        !exp()
    }
}

Usage:

guard .not(/* code goes in here */) else { return nil }

Ta-da!

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