back

by porridgeraisin·1y ago·view on hn ↗
Yeah 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.

2 comments
It'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.
Is it worth using a custom library so you can do

.flatMap(Maybe::stream)

instead of

.filter(Optional::isPresent).map(Optional::get)

It's useful and very common to use. For example, you could concatenate together command-line argument flags that may or may not be present.