An ordinary way to make a tuple in Julia is like this:
n = 5
t2 = (n,n) # t2 = (5,5)
t3 = (n,n,n)# t3 = (5,5,5)
I want to make a tuple of arbitrary size functionally.
n = 5
someFunction(n,size) = ???
t10 = someFunction(n,10) # t10 = (5,5,5,5,5,5,5,5,5,5)
How can I realize this?
Any information would be appreciated.
f(e, a::Val{X}) where {X} = ntuple(_ -> e, X)
results in a type-stablef( 10, Val(3) )
. The other ways don't have this benefit; the compiler can't figure out that the comprehension(e for _ in 1:X)
and the resulting Tuple must have a fixed length X. – Neuter