Asynchronous sequences are tricky because you really have to think about what specifically you want the code to do.
For example, you could want to execute the AsyncMethodCall calls sequentially, and then return all the results:
var result = new List<T>(); foreach (var d in xyz) if (await AsyncMethodCall(d.val)) result.Add(d); return result;
Or, you could execute all the AsyncMethodCall calls concurrently, and then collect and return the results (again, all at once):
var tasks = xyz.Select(async d => new { d, filter = await AsyncMethodCall(d.val) }); var results = await Task.WhenAll(tasks); return results.Where(x => x.filter).Select(x => x.d);
Or, you could execute all the AsyncMethodCall calls sequentially, and produce the results one at a time. This approach is incompatible with IEnumerable<T> (assuming you want to keep the call asynchronous). If you want to produce a sequence where AsyncMethodCall is asynchronously invoked during sequence enumeration, then you would need to change to IAsyncEnumerable<T>. If you want to produce a sequence that is started by the consumer and then produces results on its own, you would need to change to IObservable<T>.
Or, you could execute all the AsyncMethodCall calls concurrently, and produce the results one at a time. This is also incompatible with IEnumerable<T>; you would need to change to IObservable<T>. And you would also need to decide whether to maintain the original ordering, or to produce them in order of AsyncMethodCall completing.
Where()method that accepts a TaskasyncandIEnumerable<>don't mix, becauseTask(the class at the base ofasync) presuppose that the result it contains can be used only when it isCompleted... but here you have that the pieces of the result (the singlexyzelements) can be enumerated "during" the lifetime of theTask, and theTaskisCompletedwhen there are no more elements.asyncandawaitcancel each other out. The same but simpler:.Where(x => AsyncMethodCall(x.val)). This should give you the same error, theWhere()extensions method doesn't accept awaitables.