Make Qex.split/2 match the behavior of Enum.split/2 rather than :queue.split/2 #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes the behavior of
Qex.split/2
to be less surprising to Elixir devs.When you ask for more elements than your queue currently contains, it will silently return the complete queue as the first item in the tuple, rather than throwing an
ArgumentError
like:queue.split/2
does when you ask for too many items.Thus, instead of matching this behavior:
...it behaves like this:
...giving you:
This is a potentially breaking change, in the sense that somebody could conceivably be depending on an
ArgumentError
to tell them they asked for more than:queue.len/1
elements. (One alternative might be to call this versionsafe_split/2
or something and leave the existingsplit/2
behavior in place.) I suspect there are a great many more folks new to working with queues on the BEAM who are bitten by this unexpectedly raising an error, though.This might controversial, so again, no hard feelings if you don't want it.☺️