Created
September 28, 2021 18:07
-
-
Save numist/dfbbc59a881301190a66bb73edbaa402 to your computer and use it in GitHub Desktop.
Swift Jigs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension FixedWidthInteger where Self: UnsignedInteger { | |
// Enumerates `self`'s bits from most significant to least | |
var bits: some Sequence { | |
return sequence(state: Self.bitWidth) { i -> Bool? in | |
guard i > 0 else { return nil } | |
i -= 1 | |
return (self & (1 << i) != 0) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment