Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Length of iterators #41

Open
baggepinnen opened this issue Nov 15, 2019 · 2 comments
Open

Length of iterators #41

baggepinnen opened this issue Nov 15, 2019 · 2 comments

Comments

@baggepinnen
Copy link

It would be convenient if was possible to supply the length of a resumable function if the length is known. A lot of functions around the ecosystem do not work if they can't ask for the length.
E.g.,

@resumable n myfun(n)
    for i = 1:n
        @yield i
    end
end
@BenLauwens
Copy link
Collaborator

Hi

This could be implemented by having a @Resumable macro with two inputs.
I will put it on my todo list;)

Kind regards

Ben

@SyxP
Copy link

SyxP commented Dec 26, 2019

The length of the iterators may be highly non-trivial to compute at times. I propose the following syntax with the second shorthand. This is slightly longer, but I think covers a wider range of cases. (Ill try to look at the internals and see if I can implement it)

@length myfun(n)
     # computation of length
     return length
end

@length myfun2(n) = n

So in the case of baggepinnen, we would write instead

@resumable myfun(n)
    for i in 1:n
        @yield i
    end
end
@length myfun(n) = n

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants