Last active
September 20, 2020 15:22
-
-
Save steipete/e2ed747f41e0148de9cfb21e0e99908b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public var byteRange: [Range<UInt64>]? { | |
// Guaranteed to be in pairs. Example: | |
// - 0 : 0 | |
// - 1 : 71826 | |
// - 2 : 83948 | |
// - 3 : 34223 | |
guard let boxedRange = __byteRange else { return nil } | |
let range = boxedRange.map { $0.uint64Value } | |
var ranges: [Range<UInt64>] = [] | |
for rangeIndex in stride(from: 0, to: range.count, by: 2) { | |
let lower = range[rangeIndex] | |
let count = range[rangeIndex + 1] | |
ranges.append(Range(uncheckedBounds: (lower: lower, upper: lower + count))) | |
} | |
return ranges | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure if this meets the bar of readability and maintainability but personally I think it improves readability to define fluent extensions:
I think it's mildly easier to parse visually than the stride initializer