Core.DetachAttach - Dmitry-Bychenko/Amphisbaena GitHub Wiki

DetachAttach

Being similar to Select, ForEach executes action for each item in reader using parallel options. Note, that order of execution is not guaranteed.

Declaration (has overloads)

public static ChannelReader<T> ForEach<S, T>(this ChannelReader<S> reader,
                                                  Func<S, T> action,
                                                  ChannelParallelOptions options)

Example

using Amphisbaena;
using Amphisbaena.Linq;
...
int[] data = Enumerable
  .Range(0, 10)
  .ToArray();

// 1 - 2 + 3 - 4 + 5 - ... + 9
int actual = await data
  .ToChannelReader()
  .DetachAttach(
     item => item % 2 == 0,
     reader => reader.Select(x => -x)
   )
  .Aggregate((s, a) => s + a);```
⚠️ **GitHub.com Fallback** ⚠️