fold on empty range

Rumbu rumbu at rumbu.ro
Wed Feb 17 09:21:47 UTC 2021


In the expression below:

return matchAll(content, keywordsPattern)
             .map!(a => a.hit.stripLeft("[").strip("]"))
             .fold!((a, b) => a ~ "," ~ b)
             .splitter(',')
             .map!(a => a.stripLeft("\" ").strip("\" "))
             .filter!(a => !a.any!(b => b == ' ' || b == '\\' || b 
== '/' || b == ':'))
             .array
             .sort
             .uniq;


fold is throwing an exception if the result of the previous map 
is empty. Is there any way to express something to convince fold 
to return the empty range received from map?

Of course, I know I can test for empty in a separate expression, 
but I'd like to keep my expression flow as it is.


More information about the Digitalmars-d-learn mailing list