Skip to content

Conversation

@s3cur3
Copy link
Contributor

@s3cur3 s3cur3 commented Nov 1, 2021

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:

iex(1)> :queue.split(:queue.new(), 3)
** (ArgumentError) argument error
    (stdlib 3.14.1) queue.erl:336: :queue.split({[], []}, 3)

...it behaves like this:

iex(2)> Enum.split(Qex.new(), 3)
{[], []}

...giving you:

iex(3)> Qex.split(Qex.new(), 3)
{#Qex<[]>, #Qex<[]>}

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 version safe_split/2 or something and leave the existing split/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. ☺️

s3cur3 and others added 3 commits October 30, 2021 20:26
…ion (I couldn't figure out why there was no Qex.member?/2)
…the whole queue if you ask for more elements than are available
@princemaple
Copy link
Owner

Gonna think about this one. Breaking change is fine, we can bump to 1.0.

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.

2 participants