Skip to content

Commit

Permalink
Add IEnumerable overloads to Block Adding Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Aug 3, 2024
1 parent ccb6769 commit d5b1fd9
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
89 changes: 89 additions & 0 deletions EnumerableToolkit.Builder.Async/AsyncBlockAddingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public static void Concat<T>(this AsyncEnumerableBuilder<T> builder, T firstItem
public static void Concat<T>(this AsyncEnumerableBuilder<T> builder, IAsyncEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncConcatBlock<T>(sequence));

/// <summary>
/// Adds a building block that concatenates the given sequence to the end of the current constructed enumerable sequence.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="sequence">The sequence to concatenate.</param>
public static void Concat<T>(this AsyncEnumerableBuilder<T> builder, IEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncConcatBlock<T>(sequence.ToAsyncEnumerable()));

/// <summary>
/// Adds a building block that inserts the given items after every item that matches the given <paramref name="predicate"/>.
/// </summary>
Expand All @@ -49,6 +58,16 @@ public static void InsertAfterEveryItem<T>(this AsyncEnumerableBuilder<T> builde
public static void InsertAfterEveryItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, int, bool> predicate, IAsyncEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncInsertAfterEveryItemLambdaBlock<T>(predicate, sequence));

/// <summary>
/// Adds a building block that inserts the given sequence after every item that matches the given <paramref name="predicate"/>.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="predicate">A predicate determining whether the <paramref name="sequence"/> of items should be inserted after an item.</param>
/// <param name="sequence">A sequence of items that should be added.</param>
public static void InsertAfterEveryItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, int, bool> predicate, IEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncInsertAfterEveryItemLambdaBlock<T>(predicate, sequence.ToAsyncEnumerable()));

/// <summary>
/// Adds a building block that inserts the given items after every item that matches the given <paramref name="predicate"/>.
/// </summary>
Expand All @@ -70,6 +89,16 @@ public static void InsertAfterEveryItem<T>(this AsyncEnumerableBuilder<T> builde
public static void InsertAfterEveryItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, bool> predicate, IAsyncEnumerable<T> sequence)
=> builder.InsertAfterEveryItem(predicate.Wrap(), sequence);

/// <summary>
/// Adds a building block that inserts the given sequence after every item that matches the given <paramref name="predicate"/>.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="predicate">A predicate determining whether the <paramref name="sequence"/> of items should be inserted after an item.</param>
/// <param name="sequence">A sequence of items that should be added.</param>
public static void InsertAfterEveryItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, bool> predicate, IEnumerable<T> sequence)
=> builder.InsertAfterEveryItem(predicate.Wrap(), sequence.ToAsyncEnumerable());

/// <summary>
/// Adds a building block that inserts the given items after the first item that matches the given <paramref name="predicate"/>.
/// </summary>
Expand All @@ -91,6 +120,16 @@ public static void InsertAfterFirstItem<T>(this AsyncEnumerableBuilder<T> builde
public static void InsertAfterFirstItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, int, bool> predicate, IAsyncEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncInsertAfterFirstItemLambdaBlock<T>(predicate, sequence));

/// <summary>
/// Adds a building block that inserts the given sequence after the first item that matches the given <paramref name="predicate"/>.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="predicate">A predicate determining whether the <paramref name="sequence"/> of items should be inserted after that item.</param>
/// <param name="sequence">A sequence of items that should be added.</param>
public static void InsertAfterFirstItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, int, bool> predicate, IEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncInsertAfterFirstItemLambdaBlock<T>(predicate, sequence.ToAsyncEnumerable()));

/// <summary>
/// Adds a building block that inserts the given items after the first item that matches the given <paramref name="predicate"/>.
/// </summary>
Expand All @@ -112,6 +151,16 @@ public static void InsertAfterFirstItem<T>(this AsyncEnumerableBuilder<T> builde
public static void InsertAfterFirstItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, bool> predicate, IAsyncEnumerable<T> sequence)
=> builder.InsertAfterFirstItem(predicate.Wrap(), sequence);

/// <summary>
/// Adds a building block that inserts the given sequence after the first item that matches the given <paramref name="predicate"/>.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="predicate">A predicate determining whether the <paramref name="sequence"/> of items should be inserted after that item.</param>
/// <param name="sequence">A sequence of items that should be added.</param>
public static void InsertAfterFirstItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, bool> predicate, IEnumerable<T> sequence)
=> builder.InsertAfterFirstItem(predicate.Wrap(), sequence.ToAsyncEnumerable());

/// <summary>
/// Adds a building block that inserts the given items before every item that matches the given <paramref name="predicate"/>.
/// </summary>
Expand All @@ -133,6 +182,16 @@ public static void InsertBeforeEveryItem<T>(this AsyncEnumerableBuilder<T> build
public static void InsertBeforeEveryItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, int, bool> predicate, IAsyncEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncInsertBeforeEveryItemLambdaBlock<T>(predicate, sequence));

/// <summary>
/// Adds a building block that inserts the given sequence before every item that matches the given <paramref name="predicate"/>.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="predicate">A predicate determining whether the <paramref name="sequence"/> of items should be inserted before an item.</param>
/// <param name="sequence">A sequence of items that should be added.</param>
public static void InsertBeforeEveryItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, int, bool> predicate, IEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncInsertBeforeEveryItemLambdaBlock<T>(predicate, sequence.ToAsyncEnumerable()));

/// <summary>
/// Adds a building block that inserts the given items before every item that matches the given <paramref name="predicate"/>.
/// </summary>
Expand All @@ -154,6 +213,16 @@ public static void InsertBeforeEveryItem<T>(this AsyncEnumerableBuilder<T> build
public static void InsertBeforeEveryItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, bool> predicate, IAsyncEnumerable<T> sequence)
=> builder.InsertBeforeEveryItem(predicate.Wrap(), sequence);

/// <summary>
/// Adds a building block that inserts the given sequence before every item that matches the given <paramref name="predicate"/>.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="predicate">A predicate determining whether the <paramref name="sequence"/> of items should be inserted before an item.</param>
/// <param name="sequence">A sequence of items that should be added.</param>
public static void InsertBeforeEveryItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, bool> predicate, IEnumerable<T> sequence)
=> builder.InsertBeforeEveryItem(predicate.Wrap(), sequence.ToAsyncEnumerable());

/// <summary>
/// Adds a building block that inserts the given items before the first item that matches the given <paramref name="predicate"/>.
/// </summary>
Expand All @@ -175,6 +244,16 @@ public static void InsertBeforeFirstItem<T>(this AsyncEnumerableBuilder<T> build
public static void InsertBeforeFirstItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, int, bool> predicate, IAsyncEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncInsertBeforeFirstItemLambdaBlock<T>(predicate, sequence));

/// <summary>
/// Adds a building block that inserts the given sequence before the first item that matches the given <paramref name="predicate"/>.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="predicate">A predicate determining whether the <paramref name="sequence"/> of items should be inserted before that item.</param>
/// <param name="sequence">A sequence of items that should be added.</param>
public static void InsertBeforeFirstItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, int, bool> predicate, IEnumerable<T> sequence)
=> builder.AddBuildingBlock(new AsyncInsertBeforeFirstItemLambdaBlock<T>(predicate, sequence.ToAsyncEnumerable()));

/// <summary>
/// Adds a building block that inserts the given items before the first item that matches the given <paramref name="predicate"/>.
/// </summary>
Expand All @@ -196,6 +275,16 @@ public static void InsertBeforeFirstItem<T>(this AsyncEnumerableBuilder<T> build
public static void InsertBeforeFirstItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, bool> predicate, IAsyncEnumerable<T> sequence)
=> builder.InsertBeforeFirstItem(predicate.Wrap(), sequence);

/// <summary>
/// Adds a building block that inserts the given sequence before the first item that matches the given <paramref name="predicate"/>.
/// </summary>
/// <typeparam name="T">The type of the items in the generated sequence.</typeparam>
/// <param name="builder">The enumerable builder to add the building block to.</param>
/// <param name="predicate">A predicate determining whether the <paramref name="sequence"/> of items should be inserted before that item.</param>
/// <param name="sequence">A sequence of items that should be added.</param>
public static void InsertBeforeFirstItem<T>(this AsyncEnumerableBuilder<T> builder, Func<T, bool> predicate, IEnumerable<T> sequence)
=> builder.InsertBeforeFirstItem(predicate.Wrap(), sequence.ToAsyncEnumerable());

/// <summary>
/// Adds a building block that filters the current sequence based on the given <paramref name="predicate"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="README.md" />
<None Include="README.md" Pack="True" PackagePath="" />
<!--<None Include="..\Icon.png" Pack="true" PackagePath="" /> -->
</ItemGroup>

Expand All @@ -28,6 +28,5 @@

<ItemGroup>
<ProjectReference Include="..\EnumerableToolkit.Async\EnumerableToolkit.Async.csproj" />
<ProjectReference Include="..\EnumerableToolkit\EnumerableToolkit.csproj" />
</ItemGroup>
</Project>

0 comments on commit d5b1fd9

Please sign in to comment.