collection.allElementsSameLength

💾 程式: replitarrow-up-right

// ┌───────────────────────────────────────────┐
// │    Collection + .allElementsSameLength    │
// └───────────────────────────────────────────┘

extension Collection where Element: Collection {
    /// all elements (rows) are of the some length
    /// ```
    /// [[1,2], [3,4]].allElementsSameLength == true
    /// ```
    public var allElementsSameLength: Bool {
        guard !isEmpty else { return true }
        return dropFirst().allSatisfy { $0.count == first!.count }
    }
}

Last updated