public static BackgroundGenerator <T> FromEnumerator(IEnumerator <T> Generator, int MaxCache = -1, bool AutoStart = true) { return(BackgroundGenerator <T> .FromFunc(() => { Generator.MoveNext(); return Generator.Current; }, MaxCache, AutoStart)); }
public static BackgroundGenerator <T> FromFuncWithCarryover <R>(Func <R, Tuple <T, R> > CarryoverGenerateNext, int MaxCache = -1, bool AutoStart = true) { R ClosureCarryover = default(R); return(BackgroundGenerator <T> .FromFunc(() => { var tup = CarryoverGenerateNext(ClosureCarryover); ClosureCarryover = tup.Item2; return tup.Item1; })); }
public BackgroundGenerator <R> Chain <R>(Func <T, R> GenerateNext, int MaxCache = -1, bool AutoStart = true) { return(BackgroundGenerator <R> .FromFunc(() => { if (this.MoveNext()) { return GenerateNext(this.Current); } else { throw new OperationCanceledException("End of background generator reached"); } }, MaxCache, AutoStart)); }
public static BackgroundGenerator <T> Chain <R>(Func <R, T> GenerateNext, IEnumerator <R> Source, int MaxCache = -1, bool AutoStart = true) { return(BackgroundGenerator <T> .FromFunc(() => { if (Source.MoveNext()) { return GenerateNext(Source.Current); } else { throw new OperationCanceledException("End of background generator reached"); } }, MaxCache, AutoStart)); }
public static BackgroundGenerator <T> ForEach <A>(IEnumerable <A> Data, Func <A, T> Body, int MaxCache = -1, bool AutoStart = true) { return(BackgroundGenerator <T> .FromEnumerator(Data.Select(Body).GetEnumerator(), MaxCache, AutoStart)); }
public static BackgroundGenerator <T> AsBackgroundGenerator <T>(this IEnumerable <T> Base, int MaxCache = -1) { return(BackgroundGenerator <T> .FromEnumerator(Base.GetEnumerator(), MaxCache)); }