import std.algorithm : map; import std.array : array; import std.range : iota; auto res = iota(100) .parallelMap!(i => 2 * i) .array; assert(res == iota(100).map!(i => 2 * i).array);
import std.algorithm : isPermutation, map; import std.array : array; import std.random : uniform; import std.range : iota; import core.time : msecs; import vibe.core.core : sleep; // forcing a random computation result order still results in the same // output order auto res = iota(100) .parallelMap!((i) { sleep(uniform(0, 100).msecs); return 2 * i; }) .array; assert(res == iota(100).map!(i => 2 * i).array);
parallelUnorderedMap
Processes a range of items in worker tasks and returns them as an ordered range.
The items of the returned stream are in the same order as input. Note that this may require dynamic buffering of results, so it is recommended to use unordered mapping if possible.