Range to Nullable conversion
Antonio
antonio at abrevia.net
Fri Jun 10 17:22:53 UTC 2022
Is there any alternative to ***range front*** that returns a
Nullable (i.e. **frontAsMonad** or **frontAsNullable**)?
I'm using Vibe.d and Nullable is the standard way to return an
optional element:
```d
@safe Nullable!Item getItem(int _id)
{
import std.algorithm : filter;
with (items.filter!(item => item.id == _id))
{
if (empty)
return Nullable!Item.init;
else
return front.nullable;
}
}
```
Can this code be written as a **simple** expression? (without
having to write helper methods).
More information about the Digitalmars-d-learn
mailing list