public void PumpWithBufferingRequired() { // This will keep track of how many we've consumed already int consumed = 0; DataProducer <int> producer = new DataProducer <int>(); IDataProducer <int> ordered = producer.OrderBy(x => x); var selected = ordered.Select(x => new { X = x, Consumed = consumed }); int[] data = new int[] { 1, 0, 4, 2, 3, 5 }; var results = producer.PumpProduceAndEnd(data, selected); int count = 0; foreach (var result in results) { Assert.AreEqual(count, result.X); count++; // Nothing will be yielded until we end everything, at which point // everything will have been buffered internally before we can increment Consumed Assert.AreEqual(0, result.Consumed); consumed++; } Assert.AreEqual(count, 6); }
/// <summary> /// Returns a future to the minumum of a sequence of values that are /// obtained by taking a transform of the input sequence, using the default comparer /// </summary> /// <remarks>Null values are removed from the minimum</remarks> public static IFuture <TResult> Min <TSource, TResult> (this IDataProducer <TSource> source, DotNet20.Func <TSource, TResult> selector) { source.ThrowIfNull("source"); selector.ThrowIfNull("selector"); return(source.Select(selector).Min()); }
/// <summary> /// Returns a projection on the data-producer, using a transformation to /// map each element into a new form. /// </summary> /// <typeparam name="TSource">The source type</typeparam> /// <typeparam name="TResult">The projected type</typeparam> /// <param name="source">The source data-producer</param> /// <param name="projection">The transformation to apply to each element.</param> public static IDataProducer <TResult> Select <TSource, TResult>(this IDataProducer <TSource> source, DotNet20.Func <TSource, TResult> projection) { projection.ThrowIfNull("projection"); return(source.Select((t, index) => projection(t))); }