✅ Early return with yield

How to i early return despite using yield

The method goes like
IEnumerable<int> ProcessXml(string path)
{
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(path);
    var nodes = xmlDoc.SelectNodes("//DataBlob");

   if(nodes == null){
        return [];
   }

   foreach(var dataBlob in nodes.Cast<XmlNode>()) 
    {
         var data = DataProcessor.Parse(dataBlob InnerText;
         yield return DataProcessor.Process(data);
    }
}


Mixed returns aren't allowed, how would you style this?
Wrap the foreach in an ≠null if ?
Or eagerly evaluate rather slow data pro
cessing?
Is there another XML query method that returns a non-nullable collection?
Was this page helpful?