Is there any function in Julia which does this?
f(x, n) = vcat(repeat(x, div(n, length(x))), x[1:rem(n, length(x))])
f([1,3,2], 10)
10-element Vector{Int64}:
1
3
2
1
3
2
1
3
2
1
I want to know whether a known function exists which does the same.
The usecase is sort of niche, so there is no dedicated function (what would that be called?)
But you can combine some simple calls like this:
f(v, n) = first(Iterators.cycle(v), n)
This is also faster than the other alternatives.
There is in fact an even more lightweight option. If you do
g(v, n) = Iterators.take(Iterators.cycle(v), n)
then this takes virtually zero time, since it's completely lazy, and only does real work when you either collect
it or iterate over it. So it depends on what you need. Do you need a fully collected vector, or do you just need something to iterate over?