# collection.allElementsSameLength

{% tabs %}
{% tab title="🌀 Collection" %}
💾 程式： [replit](https://replit.com/@pegasusroe/Swift-Playground#Extenions/Collection+.swift)

````swift
// ┌───────────────────────────────────────────┐
// │    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 }
    }
}
````

{% endtab %}

{% tab title="👥 相關" %}

* used by [collection.columnwidths](https://lochiwei.gitbook.io/ios/swift/collections/collection/collection.columnwidths "mention").
  {% endtab %}

{% tab title="🗣 討論" %}

* [Extending Arrays of Arrays - Swift 4.1](https://stackoverflow.com/questions/49839356/extending-arrays-of-arrays-swift-4-1)
  {% endtab %}
  {% endtabs %}
