You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.1 KiB
27 lines
1.1 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Discord
|
|
{
|
|
/// <summary> An extension class for squashing <see cref="IAsyncEnumerable{T}"/>. </summary>
|
|
/// <remarks>
|
|
/// This set of extension methods will squash an <see cref="IAsyncEnumerable{T}"/> into a
|
|
/// single <see cref="IEnumerable{T}"/>. This is often associated with requests that has a
|
|
/// set limit when requesting.
|
|
/// </remarks>
|
|
public static class AsyncEnumerableExtensions
|
|
{
|
|
/// <summary> Flattens the specified pages into one <see cref="IEnumerable{T}"/> asynchronously. </summary>
|
|
public static async Task<IEnumerable<T>> FlattenAsync<T>(this IAsyncEnumerable<IEnumerable<T>> source)
|
|
{
|
|
return await source.Flatten().ToArrayAsync().ConfigureAwait(false);
|
|
}
|
|
/// <summary> Flattens the specified pages into one <see cref="IAsyncEnumerable{T}"/>. </summary>
|
|
public static IAsyncEnumerable<T> Flatten<T>(this IAsyncEnumerable<IEnumerable<T>> source)
|
|
{
|
|
return source.SelectMany(enumerable => enumerable.ToAsyncEnumerable());
|
|
}
|
|
}
|
|
}
|