# Repeatable

{% tabs %}
{% tab title="🅿️ Repeatable" %}
````swift
// 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 {}
````
{% endtab %}

{% tab title="💈範例" %}
* [testsvgfe](../../swiftui/view/layout/grids/scrollvgridforeach/testsvgfe "mention") - to repeat [griditem](../../swiftui/view/layout/grids/griditem "mention").
{% endtab %}

{% tab title="⬇️ 應用" %}
* is an [op](../../swift/op "mention").
* used to generate [griditem](../../swiftui/view/layout/grids/griditem "mention") arrays.
{% endtab %}
{% endtabs %}
