Skip to content

Commit

Permalink
v1.7.6 ForEachContinue
Browse files Browse the repository at this point in the history
  • Loading branch information
smabuk committed Nov 28, 2024
1 parent 342166c commit c361b4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Smab.Helpers/LinqHelpers/ForEach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ public static void ForEach<T>(this IEnumerable<T> items, Action<T> action) {
action(item);
}
}

public static IEnumerable<T> ForEachContinue<T>(this IEnumerable<T> items, Action<T> action) {
foreach (T? item in items) {
action(item);
yield return item;
}
}
}
2 changes: 1 addition & 1 deletion src/Smab.Helpers/Smab.Helpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>
<PropertyGroup>
<PackageReleaseNotes>.NET 9.0</PackageReleaseNotes>
<VersionPrefix>1.7.5</VersionPrefix>
<VersionPrefix>1.7.6</VersionPrefix>
<Preview></Preview>
<VersionSuffix Condition="'$(Preview)' != '' And '$(BUILD_BUILDNUMBER)' == ''">$(Preview).$([System.DateTime]::get_Now().get_Year())$([System.DateTime]::get_Now().get_Month().ToString("D2"))$([System.DateTime]::get_Now().get_Day().ToString("D2"))-$([System.DateTime]::get_Now().get_Hour().ToString("D2"))$([System.DateTime]::get_Now().get_Minute().ToString("D2"))</VersionSuffix>
<VersionSuffix Condition="'$(Preview)' != '' And '$(BUILD_BUILDNUMBER)' != ''">$(Preview).$(BUILD_BUILDNUMBER)</VersionSuffix>
Expand Down
12 changes: 11 additions & 1 deletion tests/Smab.Helpers.Tests/LinqHelperTests/ForEach.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Smab.Helpers.Tests.LinqHelperTests;
public class ForEach {
private static readonly IEnumerable<int> ints = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
private static readonly IEnumerable<int> ints = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];

[Fact]
public void ForEach_Ints_Should_Return() {
Expand All @@ -17,4 +17,14 @@ public void ForEach_Ints_Arrray_Should_Return() {
actual.ShouldBe(66);
}


[Fact]
public void ForEachContinue_Ints_Arrray_Should_Return() {
int[] intArray = [.. ints];
int actual = 0;
int[] actualArray = [..intArray.ForEachContinue(i => { actual += i; })];
actual.ShouldBe(66);
actualArray.Length.ShouldBe(12);
}

}

0 comments on commit c361b4c

Please sign in to comment.