コード例 #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
ファイル: ToCollection.cs プロジェクト: akarnokd/Rx.NET
        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);
        }
コード例 #13
0
        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);