collection.lengthsOfElements

๐Ÿ’พ ็จ‹ๅผ๏ผš replit

// โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
// โ”‚    Collection + .lengthsOfElements    โ”‚
// โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

extension Collection where Element: Collection {
    /// lengths (element.count) of elements
    /// ```
    ///   [[1,2], [1,2,3]].lengthsOfElements == [2, 3]
    /// ```
    public var lengthsOfElements: [Int] {
        return map { $0.count }
    }
}

Last updated