Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate with async accumulator #42

Open
mausch opened this issue May 16, 2019 · 1 comment
Open

Aggregate with async accumulator #42

mausch opened this issue May 16, 2019 · 1 comment

Comments

@mausch
Copy link
Contributor

mausch commented May 16, 2019

I have this variant of Aggregate defined in one of my projects, using an async accumulator:

        /// <summary>
        /// Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="seed"></param>
        /// <param name="func"></param>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TAccumulate"></typeparam>
        /// <returns></returns>
        public static async Task<TAccumulate> Aggregate<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, Task<TAccumulate>> func)
        {
            TAccumulate state = seed;
            await source.ForEachAsync(async e =>
            {
                state = await func(state, e);
            });
            return state;
        }

I noticed that the current Aggregate methods here don't have this overload, do you think it's worth adding it? If so, its implementation should probably be optimised etc.

@kind-serge
Copy link
Member

yeah, why not. To my best memory, I added some core LINQ-style extension methods, but not all possible overloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants