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:58:28 UTC 2021


On 2021-05-27 14:48, sighoya wrote:
> 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));
> }
> ```
> 
That looks nice, but unfortunately my data for servers and users in the 
real world is not static but comes from a config file.


More information about the Digitalmars-d-learn mailing list