Skip to content

Commit

Permalink
Update documentation for ForEach
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Sep 4, 2023
1 parent bc43d2e commit b661798
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 16 deletions.
13 changes: 13 additions & 0 deletions Docs/SuperLinq.Docs/apidoc/SuperLinq.SuperEnumerable.ForEach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
uid: SuperLinq.SuperEnumerable.ForEach``1(System.Collections.Generic.IEnumerable{``0},System.Action{``0})
example: [*content]
---
The following code example demonstrates how to immediately execute an action on every element of a sequence using `ForEach`.
[!code-csharp[](SuperLinq/ForEach/ForEach1.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.ForEach``1(System.Collections.Generic.IEnumerable{``0},System.Action{``0,System.Int32})
example: [*content]
---
The following code example demonstrates how to immediately execute an action on every element of a sequence using `ForEach`.
[!code-csharp[](SuperLinq/ForEach/ForEach2.linq#L6-)]
13 changes: 13 additions & 0 deletions Docs/SuperLinq.Docs/apidoc/SuperLinq/ForEach/ForEach1.linq
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = Enumerable.Range(1, 5);

// Fold a sequence into a single value.
sequence
.ForEach(x => Console.Write($"{x}, "));

// This code produces the following output:
// 1, 2, 3, 4, 5,
13 changes: 13 additions & 0 deletions Docs/SuperLinq.Docs/apidoc/SuperLinq/ForEach/ForEach2.linq
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

var sequence = Enumerable.Range(1, 5);

// Fold a sequence into a single value.
sequence
.ForEach((x, i) => Console.Write($"({x}, {i}), "));

// This code produces the following output:
// (1, 0), (2, 1), (3, 2), (4, 3), (5, 4),
46 changes: 30 additions & 16 deletions Source/SuperLinq/ForEach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
public partial class SuperEnumerable
{
/// <summary>
/// Immediately executes the given action on each element in the source sequence.
/// Immediately executes the given action on each element in the source sequence.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the sequence</typeparam>
/// <param name="source">The sequence of elements</param>
/// <param name="action">The action to execute on each element</param>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="action"/> is <see
/// langword="null"/>.</exception>
/// <typeparam name="TSource">
/// The type of the elements in the sequence
/// </typeparam>
/// <param name="source">
/// The sequence of elements
/// </param>
/// <param name="action">
/// The action to execute on each element
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="source"/> or <paramref name="action"/> is <see langword="null"/>.
/// </exception>
/// <remarks>
/// This operator executes immediately.
/// This operator executes immediately.
/// </remarks>
public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource> action)
{
Expand All @@ -23,17 +30,24 @@ public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSo
}

/// <summary>
/// Immediately executes the given action on each element in the source sequence. Each element's index is used in
/// the logic of the action.
/// Immediately executes the given action on each element in the source sequence. Each element's index is used
/// in the logic of the action.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the sequence</typeparam>
/// <param name="source">The sequence of elements</param>
/// <param name="action">The action to execute on each element; the second parameter of the action represents the
/// index of the source element.</param>
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="action"/> is <see
/// langword="null"/>.</exception>
/// <typeparam name="TSource">
/// The type of the elements in the sequence
/// </typeparam>
/// <param name="source">
/// The sequence of elements
/// </param>
/// <param name="action">
/// The action to execute on each element; the second parameter of the action represents the index of the source
/// element.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="source"/> or <paramref name="action"/> is <see langword="null"/>.
/// </exception>
/// <remarks>
/// This operator executes immediately.
/// This operator executes immediately.
/// </remarks>
public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource, int> action)
{
Expand Down

0 comments on commit b661798

Please sign in to comment.