public static async Task ForEach <T>(this ITaskEnumerable <T> source, Action <T, ITaskForEachController> action) { if (source == null || action == null) { return; } var controller = new TaskForEachController(); using (var iterator = source.GetEnumerator()) { while (iterator.MoveNext()) { if (controller.CheckContinue()) { continue; } var item = await iterator.Current; action(await iterator.Current, controller); if (controller.CheckBreak()) { break; } } } }
public static ITaskEnumerable <T> Map <T>(this ITaskEnumerable <ITaskEnumerable <T> > source) { if (source == null) { return(Empty <T>()); } return(new MappedTaskEnumerable <T>(source)); }
public static ITaskEnumerable <TResult> Continue <TSource, TResult>(this ITaskEnumerable <TSource> source, Func <Task <TSource>, Task <TResult> > continuation) { if (source == null || continuation == null) { return(Empty <TResult>()); } return(new ContinueTaskEnumerable <TSource, TResult>(source, continuation)); }
public MappedTaskEnumerable(ITaskEnumerable <ITaskEnumerable <T> > source) { this.source = source ?? throw new ArgumentNullException(nameof(source)); }
public ContinueTaskEnumerable(ITaskEnumerable <TSource> source, Func <Task <TSource>, Task <TResult> > continuation) { this.source = source ?? throw new ArgumentNullException(nameof(source)); this.continuation = continuation ?? throw new ArgumentNullException(nameof(continuation)); }