Result handing in D: some|none

SealabJaster sealabjaster at gmail.com
Sun Jan 30 16:08:17 UTC 2022


On Sunday, 30 January 2022 at 10:58:33 UTC, 9il wrote:
> ...

Nice work!

Anytime I see things like this it makes me wish D would adopt 
some form of pattern matching.

I've been using F# a lot lately, and I'm in love with how 
expressive it can be in certain cases, i.e.:

```fsharp
let (|Seconds|NotANumber|) (str : string) =
     let mutable value = 0.0
     match Double.TryParse(str, &value) with
     | true -> Seconds value
     | false -> NotANumber

...somewhere in an expression/function

        match model.Duration with
        | Seconds s -> ValidRequest {
                 ...omitted
             }
        | NotANumber -> InvalidRequest "Duration is not a valid 
number"
```



More information about the Digitalmars-d-announce mailing list