Skip to content
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

Merged
merged 6 commits into from
Feb 28, 2023
Merged

Write nullable vs option document #28

merged 6 commits into from
Feb 28, 2023

Conversation

nomisRev
Copy link
Member

Updating original Option documentation, and including a section on why Arrow has Option.

Comment on lines +38 to +48
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
Copy link
Member Author

@nomisRev nomisRev Feb 23, 2023

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 🙏

@nomisRev
Copy link
Member Author

Screenshot 2023-02-23 at 18 10 09

This is pretty cool stuff!

content/learn/nullable-and-option.md Outdated Show resolved Hide resolved
content/learn/nullable-and-option.md Outdated Show resolved Hide resolved
Co-authored-by: David Vega Lichacz <7826728+realdavidvega@users.noreply.github.com>
Co-authored-by: Francisco Diaz <francisco.d@47deg.com>
@nomisRev
Copy link
Member Author

Thank you @franciscodr & @realdavidvega! Great suggestions 🙏

Copy link
Contributor

@franciscodr franciscodr left a 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>
@nomisRev
Copy link
Member Author

Merging this, all feedback or suggestions are still welcome of course ☺️ Thanks for the reviews, and feedback 🙏

@nomisRev nomisRev merged commit b143dac into main Feb 28, 2023
@nomisRev nomisRev deleted the sv-nullable-vs-option branch February 28, 2023 09:04
i-walker added a commit that referenced this pull request Feb 28, 2023
nomisRev pushed a commit that referenced this pull request Feb 28, 2023
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.

None yet

5 participants