4 ms·
> The exception that is raised when an empty Maybe is used is a checked exception so you don't forget to handle it. I think they acknowledged get() should have
by dehrmann 2y ago
> The exception that is raised when an empty Maybe is used is a checked exception so you don't forget to handle it.
I think they acknowledged get() should have been getOrThrow() so it's clear what can happen, but I don't know if making it checked is an improvement.
> It implements the Collection interface, so it can be accessed with a for-loop.
I'm curious what the use cases are for this. I've used Optional, it can be annoying, it's mostly around it being verbose and APIs being inconsistent. It was never wishing I could treat it as a collection.
- kelseyfrog 2y agoI'd imagine it's a poor-man's do notation. When it comes to structured programming, languages without a do syntax are considered incomplete. It's like programming without ifs.
- AtlasBarfed 2y agoFro what language? Is that like groovy with?
- eru 2y agoDo-notation is a thing in eg Haskell.
- hackingonempty 2y agoLike Scala's for-comprehension.
- porridgeraisin 2y agoYeah I don't get the iterator thing either... Saw the implementation and I'm not sure what the usecase would be. They have essentially implement a single element iterator for Some and a zero element iterator for None.
- ai_ 2y agoIt's useful for combinators, like flatMap. For instance if you want to flatten an iterator of optional values into the values of all some elements.
- dehrmann 2y agoIs it worth using a custom library so you can do .flatMap(Maybe::stream) instead of .filter(Optional::isPresent).map(Optional::get)
- sedro 2y agoIt's useful and very common to use. For example, you could concatenate together command-line argument flags that may or may not be present.