How to implement filterMap
Alexandru Ermicioi
alexandru.ermicioi at gmail.com
Sat Dec 30 18:08:55 UTC 2023
On Friday, 29 December 2023 at 23:10:47 UTC, Christian Köstlin
wrote:
> Is there a way to implement filterMap (meaning do mapping of a
> range, but if something happens during the map, leave this
> element out of the resulting range).
Perhaps try map to null cases that exception is thrown then
filter out those, and then unwrap from nullable type:
```d
myRange.map!(e => e.to!T.asNullForException).filter!(e =>
!e.isNull).map!(e => e.get).myOtherAlgorithm()
```
where asNullForException will return empty `Nullable` in case
conversion fails.
More information about the Digitalmars-d-learn
mailing list