How do I infinitely repeat a sequence in Kotlin? : <p>I want to infinitely repeat <code>T</code> elements in a <code>Sequence&lt;T&gt;</code>. This can't be done using <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/as-sequence.html" rel="noreferrer">kotlin.collections.asSequence</a>. For example:</p>

<pre><code>val intArray = intArrayOf(1, 2, 3)
val finiteIntSequence = intArray.asSequence()
val many = 10
finiteIntSequence.take(many).forEach(::print)
// 123
</code></pre>

<p>This is not what I want. I expected some kind of <code>kotlin.collections.repeat</code> function to exist, but there isn't, so I implemented one myself (e.g. for this <code>IntArray</code>):</p>

<pre><code>var i = 0
val infiniteIntSequence = generateSequence { intArray[i++ % intArray.size] }
infiniteIntSequence.take(many).forEach(::print)
// 1231231231
</code></pre>

<p>This is quite imperative, so I feel there must be a more functional and less verbose way to do this. If it exists, what is/are Kotlin's standard way(s) to repeat collections / arrays a(n) (in)finite amount of times?</p>
