C# doesn't allow lambda functions to represent iterator blocks (e.g., no "yield return" allowed inside a lambda function). If I wanted to create a lazy enumerable that yielded all the drives at the time of enumeration for example, I'd like to do something like
IEnumerable<DriveInfo> drives = {foreach (var drive in DriveInfo.GetDrives())
yield return drive;};
It took a while, but I figured out this as a way to get that functionality:
var drives = Enumerable.Range(0, 1).SelectMany(_ => DriveInfo.GetDrives());
Is there a more idiomatic way?