Posts

Showing posts from 2020

Where statement on a IAsyncEnumerable

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