Core.DetachAttach - Dmitry-Bychenko/Amphisbaena GitHub Wiki
Being similar to Select, ForEach executes action for each item in reader using parallel options. Note, that order of execution is not guaranteed.
public static ChannelReader<T> ForEach<S, T>(this ChannelReader<S> reader,
Func<S, T> action,
ChannelParallelOptions options)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);```