fold on empty range

Rumbu rumbu at rumbu.ro
Wed Feb 17 11:38:45 UTC 2021


On Wednesday, 17 February 2021 at 10:15:10 UTC, Mitacha wrote:

> it'll use empty string as first element in range.
>
> BTW perheps you could use `joinner` instead of this `fold` to 
> join values with ",".

Thanks for that. I thought to joiner too, but it doesn't work. I 
need fold to take a list of strings and concatenate them. 
Basically I read comma separated keywords from various sources 
and i want to iterate through all of them. If you know other 
method without the involved allocation of fold...

.map!(a => a.hit.stripLeft("[").strip("]"))     //"k1,k2", 
"k3,k4" ...
.fold!((a, b) => a ~ "," ~ b)("")               
//"k1,k2,k3,k4,..."
.splitter(',')                                  //"k1", "k2", 
"k3", "k4", ...,
.map!(a => a.stripLeft("\" '").strip("\" '"))
.filter!(a => a.length && !a.any!(b => b == ' ' || b == '\\' || b 
== '/' || b == ':'))
.array
.sort
.uniq;



More information about the Digitalmars-d-learn mailing list