stop using exceptions for flow control

This commit is contained in:
zeromus 2021-03-28 03:44:52 -04:00
parent 927a8970d6
commit ac349af9f5
1 changed files with 4 additions and 8 deletions

View File

@ -108,14 +108,10 @@ namespace BizHawk.Common.CollectionExtensions
public static T? FirstOrNull<T>(this IEnumerable<T> list, Func<T, bool> predicate) public static T? FirstOrNull<T>(this IEnumerable<T> list, Func<T, bool> predicate)
where T : struct where T : struct
{ {
try foreach (var t in list)
{ if (predicate(t))
return list.First(predicate); return t;
} return null;
catch (InvalidOperationException)
{
return null;
}
} }
} }
} }