Where statement on a IAsyncEnumerable
If you would like to use a where statement on an IAsyncEnumerable like
IAsyncEnumerable<company> companyAsyncEnum = _dataRepository.GetCampingsAsync();
The following extension method will help you
public static class AsyncFilterExtensions
{
public static async IAsyncEnumerable Where< C>(this IAsyncEnumerable asyncEnum, Funcbool> filter)
{
await foreach (var item in asyncEnum)
{
if (filter(item))
yield return item;
}
}
}
IAsyncEnumerable<company> companyAsyncEnum = _dataRepository.GetCampingsAsync();
var asyncFiltered = companyAsyncEnum.Where(c => c.Website != null && c.Website.Uri != null);
public static class AsyncFilterExtensions
{
public static async IAsyncEnumerable
{
await foreach (var item in asyncEnum)
{
if (filter(item))
yield return item;
}
}
}
Comments