public static IAsyncEnumerable <TValue> Empty <TValue>() { return(Create(() => Create <TValue>( ct => TaskExt.Return(false, ct), () => { throw new InvalidOperationException(); }, () => { }) )); }
public Task <bool> MoveNext(CancellationToken cancellationToken) { if (_disposed) { return(TaskExt.Return(false, CancellationToken.None)); } return(_moveNext(cancellationToken)); }
public static IAsyncEnumerable <TResult> Repeat <TResult>(TResult element) { return(Create(() => { return Create( ct => TaskExt.Return(true, ct), () => element, () => { } ); })); }
public static IAsyncEnumerable <TResult> Generate <TState, TResult>(TState initialState, Func <TState, bool> condition, Func <TState, TState> iterate, Func <TState, TResult> resultSelector) { if (condition == null) { throw new ArgumentNullException("condition"); } if (iterate == null) { throw new ArgumentNullException("iterate"); } if (resultSelector == null) { throw new ArgumentNullException("resultSelector"); } return(Create(() => { var i = initialState; var started = false; var current = default(TResult); return Create( ct => { var b = false; try { if (started) { i = iterate(i); } b = condition(i); if (b) { current = resultSelector(i); } } catch (Exception ex) { return TaskExt.Throw <bool>(ex, ct); } if (!b) { return TaskExt.Return(false, ct); } if (!started) { started = true; } return TaskExt.Return(true, ct); }, () => current, () => { } ); })); }