To avoid using experimental coroutines, use:
generateSequence { setOf("foo", 'b', 'a', 'r') } .flatten()
or, alternatively, if you want to repeat the entire collection several times, just take before smoothing:
generateSequence { setOf("foo", 'b', 'a', 'r') } .take(5)
For the original IntArray question, you IntArray first convert the array to Iterable<Int> (otherwise flatten() not available):
val intArray = intArrayOf(1, 2, 3) generateSequence { intArray.asIterable() } .flatten() .take(10) .joinToString(", ") // Result: "1, 2, 3, 1, 2, 3, 1, 2, 3, 1"
In addition, other types of Array , for example. ByteArray or LongArray , as well as Map not Iterable , but they all implement the asIterable() method, for example IntArray in the example above.