How to work around the infamous dual-context when using delegates together with std.parallelism
Christian Köstlin
christian.koestlin at gmail.com
Thu May 27 12:17:36 UTC 2021
Thanks for the proposed solution. It also works in my slightly bigger
program (although I do not like to make servers more global).
I tried also the following (which unfortunately also does not work as
intended):
```D
import std;
string doSomething(string[] servers, string user) {
return user ~ servers[0];
}
int main()
{
auto users = ["u1", "u2", "u3"];
auto servers = ["s1", "s2", "s3"];
auto usersWithServers = users.map!(user => tuple!("user",
"servers")(user, servers)).array;
writeln(map!(userWithServers =>
userWithServers.servers.doSomething(userWithServers.user))(usersWithServers));
writeln(taskPool.amap!(userWithServers =>
userWithServers.servers.doSomething(userWithServers.user))(usersWithServers));
return 0;
}
```
Here I try to put the data I need together into one tuple ("manually")
and then pass it all to amap. 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
More information about the Digitalmars-d-learn
mailing list