1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 5 namespace GodotTools.Utils 6 { 7 public static class CollectionExtensions 8 { 9 public static T SelectFirstNotNull<T>(this IEnumerable<T> enumerable, Func<T, T> predicate, T orElse = null) 10 where T : class 11 { 12 foreach (T elem in enumerable) 13 { 14 T result = predicate(elem); 15 if (result != null) 16 return result; 17 } 18 19 return orElse; 20 } 21 EnumerateLines(this TextReader textReader)22 public static IEnumerable<string> EnumerateLines(this TextReader textReader) 23 { 24 string line; 25 while ((line = textReader.ReadLine()) != null) 26 yield return line; 27 } 28 } 29 } 30