std.algorithm can not be used inside pure functions?

Szabo Bogdan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 6 06:19:17 PDT 2017


Hi,

I'm trying to write a function that saves some structs as csv 
file:

```
string toCsv(const(StatStorage) storage) {
   return storage.values
     .map!(a => [ a.name, a.begin.toISOExtString, 
a.end.toISOExtString, a.status.to!string ])
     .map!(a => a.join(','))
     .join('\n');
}
```

I think that it's obvious that this function has no external 
state and from my understanding, it should be a pure function. 
But when I declare it as `pure` I get an error `Error: pure 
function 'trial.reporters.stats.toCsv' cannot call impure 
function 'std.array.join!(MapResult!(__lambda3, 
MapResult!(__lambda2, const(Stat)[])), char).join'`.

What am I missing here?


More information about the Digitalmars-d-learn mailing list