Vavr: Option.map with a method producing null produces Some

Created on 22 Oct 2016  路  3Comments  路  Source: vavr-io/vavr

How to reproduce :

Option.of(/*any value*/)
      .map(/*any method that produces null on the first value*/)
      .map(/*whatever*/) //<--- it crashes here, NPE

The reason is the map method creates a Some, whatever the value is null or not. Maybe the map method should use Option.of instead of Option.some ?

question 芦vavr-control禄

All 3 comments

Hi @Pyeroh, thank you for your question! In fact recently there were similar question and always I answered: Option behaves correct, Optional is broken.

I've done a blog post today because I think your question will not be the last one regarding Some(null):

http://blog.javaslang.io/the-agonizing-death-of-an-astronaut/~~
Update: http://blog.vavr.io/the-agonizing-death-of-an-astronaut/

I will close this ticket. Please don't hesitate to ask me any further questions!

Thank you for your answer, I'll comment your blog post ;)
May any future dev encountering this problem get all the information he needs with this ticket!

Link is now broken, new address is here :
http://blog.vavr.io/the-agonizing-death-of-an-astronaut/

Was this page helpful?
0 / 5 - 0 ratings