How to implement filterMap
Christian Köstlin
christian.koestlin at gmail.com
Sat Dec 30 13:25:00 UTC 2023
On Saturday, 30 December 2023 at 01:22:31 UTC, Siarhei Siamashka
wrote:
> 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).
>
> It's probably not a good idea to do this in general. Expecting
> a lot of exceptions handling happening during normal program
> execution (if you want to filter out roughly half of the input
> array) will result in a major performance loss. Exceptions are
> best left to just do error handling on a very rarely used code
> path for troubleshooting purposes.
Thanks for the feedback.
This might be true, but in my example I would parse the input
always with conv.to, so I would need to handle the exception(s).
The "original"
https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.filter_map works with the Option(Some/None) ...
Kind regards,
Christian
More information about the Digitalmars-d-learn
mailing list