stop using exceptions for flow control
This commit is contained in:
parent
927a8970d6
commit
ac349af9f5
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue