How to work around the infamous dual-context when using delegates together with std.parallelism
sighoya
sighoya at gmail.com
Thu May 27 12:48:19 UTC 2021
On Thursday, 27 May 2021 at 12:17:36 UTC, Christian Köstlin wrote:
> Can you explain me, where here a double context is needed?
> Because all data now should be passed as arguments to amap?
>
> Kind regards,
> Christian
I believe D's type system isn't smart enough to see independence
between context and closure, otherwise your original example
would also work as users and servers are context independent.
What about:
```D
string doSomething(string[] servers, string user) {
return user ~ servers[0];
}
void main() {
static servers = ["s1", "s2", "s3"];
static users = ["u1", "u2", "u3"];
static lambda = (string user) => servers.doSomething(user);
writeln(map!(user => servers.doSomething(user))(users));
writeln(taskPool.amap!(lambda)(users));
}
```
More information about the Digitalmars-d-learn
mailing list