-
Notifications
You must be signed in to change notification settings - Fork 22
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
Write nullable vs option document #28
Conversation
listOf(null, 2, 3).firstOrElse { -1 } shouldBe null | ||
} | ||
``` | ||
<!--- KNIT example-option-02.kt --> | ||
<!--- TEST lines.first().startsWith("Exception in thread \"main\" java.lang.AssertionError: Expected null but actual was -1") --> | ||
|
||
Now we're executing the function on a list that `isNotEmpty`, so we expect it to return the first element of value `null`. | ||
Instead however it returns `-1`, which is the default value we specified in case the list `isEmpty`! | ||
|
||
``` | ||
Exception in thread "main" java.lang.AssertionError: Expected null but actual was -1 |
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 felt it was super hard to find a good example of nested nullability problem 😅
Happy I found one, even though it can be fixed with if(isEmpty())
😓
Any suggestions on any of the examples, or content is very welcome 🙏
Co-authored-by: David Vega Lichacz <7826728+realdavidvega@users.noreply.github.com> Co-authored-by: Francisco Diaz <francisco.d@47deg.com>
Thank you @franciscodr & @realdavidvega! Great suggestions 🙏 |
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.
Thanks, @nomisRev!
Co-authored-by: Alejandro Serrano <trupill@gmail.com>
Merging this, all feedback or suggestions are still welcome of course |
Updating original
Option
documentation, and including a section on why Arrow hasOption
.