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

Use Enumerator to model occurrences in Schedule #203

Merged
merged 1 commit into from
Jan 23, 2014

Conversation

igraves
Copy link
Contributor

@igraves igraves commented Nov 23, 2013

I've been encountering some use-cases where I need to deal with infinite lists of recurring events in a manageable way. Using an Enumerator to do this in a less-eager fashion seems like a good way to approach the problem. I replaced find_occurrences() in Schedule with enumerate_occurrences() and rewrote all the calls to find_occurrences() accordingly. Additionally, I added two methods that emit the underlying enumerator so one can use an enumerator to manage a (potentially infinite) list of occurrences.

@avit
Copy link
Collaborator

avit commented Nov 23, 2013

I ❤️ this! I've been thinking about doing this for a long time. Let me review, I'll add some inline comments.

@seejohnrun
Copy link
Collaborator

+1

@igraves
Copy link
Contributor Author

igraves commented Nov 25, 2013

Thanks for the feedback! Let me know if/what you need from me moving forward on this, if anything.

block_given? ? block.call(res) : (answers << res)
answers.shift if tail_limit && answers.length > tail_limit
break if limit && answers.length == limit
e = Enumerator.new do |yielder|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit: the Enumerator is implicitly returned, the e is an unused variable.

@igraves
Copy link
Contributor Author

igraves commented Jan 18, 2014

Thanks for the catch, ches. Sorry to wake this thread back up. I wasn't sure if there was anything else I needed to do with this. I don't make pull requests often (this might be my first one) so I'm a bit flimsy on the process.

@seejohnrun
Copy link
Collaborator

@igraves thanks for the pull request and sorry for the delay. great PR

seejohnrun added a commit that referenced this pull request Jan 23, 2014
Use Enumerator to model occurrences in Schedule
@seejohnrun seejohnrun merged commit e3a35ea into ice-cube-ruby:master Jan 23, 2014
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

Successfully merging this pull request may close these issues.

4 participants