public static Task <double> Max(this IAsyncEnumerable <double> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Aggregate(Math.Max, cancellationToken)); }
public static Task <decimal?> Max(this IAsyncEnumerable <decimal?> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Aggregate(default(decimal?), NullableMax, cancellationToken)); }
public static Task <float?> Sum(this IAsyncEnumerable <float?> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Aggregate((float?)0, (x, y) => x + y.GetValueOrDefault(), cancellationToken)); }
public static Task <long> LongCount <TSource>(this IAsyncEnumerable <TSource> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Aggregate(0L, (c, _) => checked (c + 1), cancellationToken)); }
public static Task <decimal> Sum(this IAsyncEnumerable <decimal> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Aggregate(0m, (x, y) => x + y, cancellationToken)); }
public static Task <TSource> Max <TSource>(this IAsyncEnumerable <TSource> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var comparer = Comparer <TSource> .Default; return(source.Aggregate((x, y) => comparer.Compare(x, y) >= 0 ? x : y, cancellationToken)); }
public static Task <TAccumulate> Aggregate <TSource, TAccumulate>(this IAsyncEnumerable <TSource> source, TAccumulate seed, Func <TAccumulate, TSource, TAccumulate> accumulator, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (accumulator == null) { throw new ArgumentNullException(nameof(accumulator)); } return(source.Aggregate(seed, accumulator, x => x, cancellationToken)); }
public static Task <TSource[]> ToArray <TSource>(this IAsyncEnumerable <TSource> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.Aggregate(new List <TSource>(), (list, x) => { list.Add(x); return list; }, list => list.ToArray(), cancellationToken)); }
public static Task <List <TSource> > ToList <TSource>(this IAsyncEnumerable <TSource> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (source is IIListProvider <TSource> listProvider) { return(listProvider.ToListAsync(cancellationToken)); } return(source.Aggregate(new List <TSource>(), (list, x) => { list.Add(x); return list; }, cancellationToken)); }
public static Task <int> Count <TSource>(this IAsyncEnumerable <TSource> source, CancellationToken cancellationToken) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (source is ICollection <TSource> collection) { return(Task.FromResult(collection.Count)); } if (source is IIListProvider <TSource> listProv) { return(listProv.GetCountAsync(false, cancellationToken)); } return(source.Aggregate(0, (c, _) => checked (c + 1), cancellationToken)); }
public async Task Computes_Factorial(IAsyncEnumerable <int> source, Func <int, int, int> accumulator, Task <int> seed) { var actual = await source.Aggregate(seed, accumulator); Assert.Equal(4 * 3 * 2 * 7, actual); }
public async Task Empty_Sequence_Yields_Seed(IAsyncEnumerable <int> source, Func <int, int, int> accumulator, Task <int> seed) { var actual = await source.Aggregate(seed, accumulator); Assert.Equal(19, actual); }
public async Task Aggregate_Can_Compute_Factorial_Plain(IAsyncEnumerable <int> source, Func <int, int, int> accumulator) { var actual = await source.Aggregate(accumulator); Assert.Equal(4 * 3 * 2, actual); }
/// <summary> /// Ratio aggregation. /// </summary> public static Task <DecimalRatio> Ratio(this IAsyncEnumerable <DecimalRatio> source, CancellationToken token) => source.Aggregate(new DecimalRatio(), (a, c) => a + c, token);
/// <summary> /// Ratio aggregation. /// </summary> public static Task <FloatRatio> Ratio(this IAsyncEnumerable <float> source, CancellationToken token) => source.Aggregate(new FloatRatio(), (a, c) => a + c, token);
/// <summary> /// Ratio aggregation. /// </summary> public static Task <Int64Ratio> Ratio(this IAsyncEnumerable <long> source, CancellationToken token) => source.Aggregate(new Int64Ratio(), (a, c) => a + c, token);