Closed ggggggggg closed 6 years ago
using ResumableFunctions
@resumable function fibonnaci(n::Int) :: Int
a = 0
b = 1
for i in 1:n-1
@yield a
a, b = b, a+b
end
a
end
Base.iteratorsize(::Type{T}) where T<:ResumableFunctions.FiniteStateMachineIterator = Base.SizeUnknown()
a = fibonnaci(10)
collect(a)
is a better way to do this.
See docs for
iteratorsize
. Consider the following, which prints "second worked" for me.SizeUnknown()
would be a strict improvement, but it seems like it would be possible to definelength
andsize
correctly for some iterators, such as thefibonnaci
example, but it would require extra syntax.