示例#1
0
文件: Max.cs 项目: AdroDG/babble-cs
        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));
        }
示例#2
0
文件: Max.cs 项目: AdroDG/babble-cs
        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));
        }
示例#3
0
文件: Sum.cs 项目: ctaggart/Rx.NET
        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));
        }
示例#4
0
文件: Count.cs 项目: ctaggart/Rx.NET
        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));
        }
示例#5
0
文件: Sum.cs 项目: ctaggart/Rx.NET
        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));
        }
示例#6
0
文件: Max.cs 项目: AdroDG/babble-cs
        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));
        }
示例#7
0
        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));
        }
示例#8
0
        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));
        }
示例#9
0
        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));
        }
示例#10
0
        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));
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#14
0
 /// <summary>
 /// Ratio aggregation.
 /// </summary>
 public static Task <DecimalRatio> Ratio(this IAsyncEnumerable <DecimalRatio> source, CancellationToken token) => source.Aggregate(new DecimalRatio(), (a, c) => a + c, token);
示例#15
0
 /// <summary>
 /// Ratio aggregation.
 /// </summary>
 public static Task <FloatRatio> Ratio(this IAsyncEnumerable <float> source, CancellationToken token) => source.Aggregate(new FloatRatio(), (a, c) => a + c, token);
示例#16
0
 /// <summary>
 /// Ratio aggregation.
 /// </summary>
 public static Task <Int64Ratio> Ratio(this IAsyncEnumerable <long> source, CancellationToken token) => source.Aggregate(new Int64Ratio(), (a, c) => a + c, token);