blob: 4158b27f103f458e92ee8da78abedd9bb968223c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
//
// UInt+Counting.swift
// MullvadVPN
//
// Created by Jon Petersson on 2024-11-05.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import Foundation
extension UInt {
/// Determines whether a number has a specific order in a given set.
/// Eg. `6.isOrdered(nth: 3, forEverySetOf: 4)` -> "Is a 6 ordered third in an arbitrary
/// amount of sets of four?". The result of this is `true`, since in a range of eg. 0-7 a six
/// would be considered third if the range was divided into sets of 4.
public func isOrdered(nth: UInt, forEverySetOf set: UInt) -> Bool {
guard nth > 0, set > 0 else {
assertionFailure("Both 'nth' and 'set' must be positive")
return false
}
return self % set == nth - 1
}
}
|