Skip to content

Commit

Permalink
Resolves #6: Use the .NET 9 implementation. Make it .NET 8-only since…
Browse files Browse the repository at this point in the history
… that's all we support, and later versions will have the official version baked in.
  • Loading branch information
jonsagara committed Mar 14, 2024
1 parent 4211e5b commit 4fb411c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>12.0</LangVersion>

<!-- NuGet -->
<Version>2.0.14</Version>
<Version>2.0.15</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<Authors>Jon Sagara</Authors>
Expand Down
23 changes: 21 additions & 2 deletions src/Sagara.Core/Extensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static class IEnumerableExtensions
{
#if NET6_0 || NET7_0 || NET8_0
#if NET8_0
/// <summary>
/// Returns an enumerable that incorporates the element's index into a tuple.
/// </summary>
Expand All @@ -15,7 +15,26 @@ public static class IEnumerableExtensions
{
ArgumentNullException.ThrowIfNull(source);

return source.Select((item, index) => (index, item));
if (source is TSource[] { Length: 0 })
{
return [];
}

return IndexIterator(source);
}

private static IEnumerable<(int Index, TSource Item)> IndexIterator<TSource>(IEnumerable<TSource> source)
{
int index = -1;
foreach (TSource element in source)
{
checked
{
index++;
}

yield return (index, element);
}
}
#endif
}

0 comments on commit 4fb411c

Please sign in to comment.