Unexpected behavior of `Some(None)`
See original GitHub issueI expect the Some
“constructor” (actually just a function) to only return Some
s.
However, given None
:
>>> from returns.maybe import Some
>>> Some(None)
<returns.maybe._Nothing object at 0x7f345dcaa1c8>
For reference, another language that has null pointers, Java, raises an exception on Optional.of(null)
.
In general, I expect the explicitly requested creation of a Some
to fail if no actual value to wrap in it is supplied.
If one explicitly wants to let Maybe
decide whether to create a Some
or None
given a thing, there still is Maybe.new
(to which Some
just delegates).
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
cypher - Unexpected Behavior Chaining Any() and None() in Neo4j ...
What I'm trying to get is nodes having certain property values for any property name (key) and not having some other values for...
Read more >Unexpected behavior with Option · Issue #263 · pureconfig ...
I'm seeing some inconsistent and unexpected behavior with Option. When a field is optional in a config class, it defaults to None, ...
Read more >What are Expected and Unexpected Behaviours? - Twinkl
That is, there are expected and unexpected behaviours. ... Some children, including children with autism, thrive when classroom rules are clear and easily ......
Read more >Unexpected Behavior with Conditional Logic - WordPress.org
I had to use conditional logic to determine whether or not to show certain species traits depending on which species gets selected, and...
Read more >Expected And Unexpected Behaviors Teaching Resources | TPT
Teaching expected and unexpected behaviors throughout the school day is an essential part of any social emotional learning program.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My idea was that you might sometime need to explicitly represent that real
None
exists somewhere. Think of this example:We can see that ‘b’ and ‘c’ are different. And previously it was impossible to tell this difference. Now it is.
Nope, this won’t do.
Because in real life
md('b').unwrap()
would beNone
. And I don’t want to haveMaybe[Optional[int]]
this is really ugly.Proposed solution: use
Result
when you care about value /None
/ error things. Like so:We would have:
Success(1)
orSuccess(None)
for'a'
and'b'
Failure(KeyError)
for'c'
We can always use
result_to_maybe
ormaybe_to_result
converters.