First Draft: opUnwrapIfTrue

Per Nordlöw per.nordlow at gmail.com
Thu May 7 12:44:05 UTC 2026


On Thursday, 26 February 2026 at 13:53:41 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> The DIP: 
> https://gist.github.com/rikkimax/21242118e3bc1bf5f28024c2cdc33557

I really want this. I believe a new distinct syntax that triggers 
the call to `opUnwrapIfTrue` is needed. My suggestion is 
something that involves the question mark symbol. For instance,

```d
if (auto value ?= result) {}
```

or

```d
if (auto value =? result) {}
```

. Alternatively, what about extending the `foreach` to allow

```d
foreach (auto value; result)
```

when

```d
typeof(result).opUnwrapIfTrue
```

exists? A bit longer to type, though.


More information about the dip.development mailing list