Is there a recommended idiom for collecting a number of elements (known at compile time, embedded in some type parameter) from an iterable into a Tuple
or SVector
?
I can write a generated function and unroll, but I was hoping for something simple and clean. MWE:
using StaticArrays
struct Fibonacci end
function Base.iterate(::Fibonacci, state = (0, 1))
f1, f2 = state
f0 = f1 + f2
f0, (f0, f1)
end
Base.IteratorEltype(::Type{Fibonacci}) = Base.HasEltype()
Base.eltype(::Type{Fibonacci}) = Int
Base.IteratorSize(::Type{Fibonacci}) = Base.IsInfinite()
# want the result here, without collecting first
SVector{5}(collect(Iterators.take(Fibonacci(), 5)))