๐Ÿ…ฟ๏ธRepeatable

// 2022.02.15
// 2022.02.22 (+) conformance: GridItem

import SwiftUI

// ---------------------
//     ๐Ÿ…ฟ๏ธ Repeatable
// ---------------------

public protocol Repeatable {
    /// `a * 3` -> `[a, a, a]`
    static func * (item: Self, n: Int) -> [Self]
}

// โญ๏ธ default behaviors
extension Repeatable {
    /// generate an array from self.
    /// ```
    /// extension String: Repeatable  // conformance
    /// "a" * 3 == ["a", "a", "a"]    // default implementation
    /// ```
    public static func * (item: Self, n: Int) -> [Self] {
        Array(repeating: item, count: n)
    }
}

// โญ๏ธ default conformance
extension GridItem: Repeatable {}

Last updated