Skip to content

Commit

Permalink
Fix FirstOrDefault bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mobile46 committed Nov 1, 2023
1 parent 8b2dce0 commit 4aeb86e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/StructLinq/First/StructCollection.First.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ public static bool TryFirst<T, TCollection, TEnumerator>(this TCollection collec
return false;
for (int i = 0; i < collection.Count; i++)
{
first = collection.Get(i);
if (predicate(first))
var current = collection.Get(i);
if (predicate(current))
{
first = current;
return true;
}
}
return false;
}
Expand All @@ -120,9 +123,12 @@ public static bool TryFirst<T, TEnumerator>(this IStructCollection<T, TEnumerato
return false;
for (int i = 0; i < collection.Count; i++)
{
first = collection.Get(i);
if (predicate(first))
var current = collection.Get(i);
if (predicate(current))
{
first = current;
return true;
}
}
return false;
}
Expand All @@ -137,9 +143,12 @@ public static bool TryFirst<T, TCollection, TEnumerator, TFunc>(this TCollection
return false;
for (int i = 0; i < collection.Count; i++)
{
first = collection.Get(i);
var current = collection.Get(i);
if (predicate.Eval(first))
{
first = current;
return true;
}
}
return false;
}
Expand Down

0 comments on commit 4aeb86e

Please sign in to comment.