-
Notifications
You must be signed in to change notification settings - Fork 440
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
Iterable<A>.toNonEmptyListOrNull()
is broken for nullable A
#3123
Comments
Hey @mjadczak, Thank you for this bug report! 🙌 Ouch, nullability problems 🙈 So easy to sneak through when not using If you're interested in contributing this could be a great contribution! |
mjadczak
pushed a commit
to mjadczak/arrow
that referenced
this issue
Sep 7, 2023
This also ensures that we iterate the iterable only once. This also removes the Set<A> receiver versions of .toNonEmptySetOrNull() and .toNonEmptySetOrNone()
serras
added a commit
that referenced
this issue
Oct 26, 2023
* Add failing tests For case when .toNonEmptyListOrNull and .toNonEmptySetOrNull are called on an iterable starting with null * Fix .toNonEmptyXxxOrNull for nullable types (#3123) This also ensures that we iterate the iterable only once. This also removes the Set<A> receiver versions of .toNonEmptySetOrNull() and .toNonEmptySetOrNone() --------- Co-authored-by: Matt Jadczak <m.jadczak@mwam.com> Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com> Co-authored-by: Alejandro Serrano <trupill@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The current implementation of this function is as follows:
but when
A
is a nullable type, and the first element of the list is null, the function incorrectly returnsnull
!It's also probably not best practice to iterate the iterable twice, just in case it cannot be iterated multiple times, or it is costly to do so.
Here is a proposed replacement, which is admittedly less pretty, but doesn't have the same issue and only iterates the iterable once:
The text was updated successfully, but these errors were encountered: