Optional and orElse: design feedback/critique?

Sebastiaan Koppe mail at skoppe.eu
Sat Jul 27 14:10:22 UTC 2019


On Saturday, 27 July 2019 at 13:17:32 UTC, aliak wrote:
> Hi,
>
> Can I ask for feedback on what people expect an optional/maybe 
> type to have, and how to behave. There have been a number of 
> discussions on the forums about it so far, and attempted PRs in 
> phobos. And I currently maintain one that I've been using 
> in-house very happily (backend server with vibe-d). I want to 
> nail it down further and get to a version 1.0.0 so feedback and 
> comments would be highly appreciated.

I think it is an awesome library and I an happy someone is 
spearheading this. Before this I used Optional, but it ain't as 
nice.

> Optional utilities:
> ===================
>
> Two utilities are included. Optional chaining and a match 
> function. Optional chaining allows you to go through an 
> object's hierarchy and get an optional back at the end:
>
> oc(obj).property.function()

In Scala you have to map constantly. This is way much better.

> orElse semantics:
> =================
>
> orElse will either get the front of a range or the range itself 
> depending on the alternative value and also works on reference 
> types.

Nice addition.



More information about the Digitalmars-d mailing list