Core.ActForEach - Dmitry-Bychenko/Amphisbaena GitHub Wiki

ActForEach

Copies input into output while executing action on each item in reader whenever condition meets

Declaration (has overloads)

public static ChannelReader<T> ActForEach<T>(this ChannelReader<T> reader,
                                                  Action<T, long> action,
                                                  Func<T, long, bool> condition,
                                                  ChannelParallelOptions options)

Example

using Amphisbaena;
using Amphisbaena.Linq;

...

int[] data = new int[] {1, 2, 3, -1, 4, 5};

int sum = data
  .ToChannelReader()
  .ActForEach((item, index) => Console.WriteLine($"Negative item {item} at {index}!"),
              (item, index) => item < 0)
  .Aggregate((s, a) => s + a); 
⚠️ **GitHub.com Fallback** ⚠️