-
Notifications
You must be signed in to change notification settings - Fork 33
mergesorted - function to merge together 2 sorted iterators #62
Conversation
* if hd1 < hd2, hd1 is emitted | ||
* if hd1 > hd2, hd2 is emitted | ||
* if hd1 == hd2, hd1 is emitted and hd2 is discarded (so no duplicates | ||
is produced) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
e8e8069
to
7771bde
Compare
I noticed that tests were failing for Julia 0.5, so I've rewritten them to be more similar to existing ones. I also modified |
|
||
function next(it::MergedIter, s::MergedState) | ||
lt = it.lt | ||
if done(it, s) throw(ArgumentError("Iterator is done")) end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually do not throw an error for calling next after done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really have a strong opinion here, but I'm curious what's the conventional approach to handle next()
after done(...) == true
?
I know that for objects like ranges we can just continue producing new elements. However, for IO-based iterators (e.g. iterator over a file) we can't really produce anything else after the end of EOF. So what is supposed to be an appropriate result for calls to next()
for such iterators?
(In fact, I'm working on one such iterator right now, so would be glad to make it using best practices)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conventional approach is to assume that one only calls next after having called done
before to make sure that the iterator is not terminated.
Please, check #63 for a version of PR that takes into account some of comments in this thread. |
Closing as the least valuable implementation, see improved versions in #63 |
Function to merge 2 sorted iterators of unique values. Example:
(Note that
:d
presents in both iterators, but only single occurrence is emitted)