0

This is related to Writing a multithreaded mapping iterator in Java but I now want to do the same thing in C#.

I have an IEnumerator<F> defining a sequence of input items, and a Function<F, T> that I want to apply to each item; I want to deliver the results of these functions as an IEnumerator<T>. And I want it to be multithreaded, so that the functions are applied in different threads (we can assume the function is expensive to compute). I'm flexible about things like scheduling policies.

How would you suggest implementing this in C#?

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • 2
    Use AsParallel() – Tarik Apr 27 '21 at 21:52
  • Side note: it is very unusual to look for input/output to be `IEnumerator` instead of `IEnumerable`. Since duplicate addresses regular inputs it does not seem to actually be duplicate of *this* question as asked... Could you please clarify if `IEnumerator` requirement is critical so question can be re-opened if needed? – Alexei Levenkov Apr 27 '21 at 22:09
  • My question isn't an exact duplicate (for example, I need to retain ordering) but the cited answer has pointed me in the right direction, so I don't need it re-opened, thank you. I do need to work with `IEnumerator` rather than `IEnumerable` because some inputs may be streamed such that I can only read them once. – Michael Kay Apr 28 '21 at 07:01
  • I am asking for this to be reopened since the cited duplicate requires an IEnumerable rather than an IEnumerator as input. – Michael Kay May 01 '21 at 22:16

0 Answers0