Make our FirstOrDefault ext behave like linq's without predicates
This commit is contained in:
1 parent
3481a36735
commit
616818aa52
1 file changed
+7
-5
@@ -354,11 +354,13 @@
|
||||
return default_rv;
|
||||
}
|
||||
|
||||
public static T FirstOrDefault<T>(this IEnumerable<T> source, params Func<T, bool>[] predicates_ordered_by_preference) {
|
||||
foreach (var p in predicates_ordered_by_preference) {
|
||||
foreach (var el in source) {
|
||||
if (p(el))
|
||||
return el;
|
||||
public static T FirstOrDefault<T>(this IEnumerable<T> source, params Func<T, bool>[] prioritized_predicates) {
|
||||
if (prioritized_predicates.is_null_or_empty()) {
|
||||
return source.FirstOrDefault();
|
||||
}
|
||||
foreach (var p in prioritized_predicates) {
|
||||
if (source.TryGetFirst(p, out var res)) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return default;
|
||||
|
||||
Reference in new issue
Block a user