Skip to content

Commit

Permalink
Update documentation for OnErrorResumeNext
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Oct 31, 2023
1 parent 1347e1a commit a255443
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
uid: SuperLinq.SuperEnumerable.OnErrorResumeNext``1(System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IEnumerable{``0})
example: [*content]
---
The following code example demonstrates how to concatenate multiple sequences, regardless of any errors that may occur, using `OnErrorResumeNext`.
[!code-csharp[](SuperLinq/OnErrorResumeNext/OnErrorResumeNext1.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.OnErrorResumeNext``1(System.Collections.Generic.IEnumerable{``0}[])
example: [*content]
---
The following code example demonstrates how to concatenate multiple sequences, regardless of any errors that may occur, using `OnErrorResumeNext`.
[!code-csharp[](SuperLinq/OnErrorResumeNext/OnErrorResumeNext2.linq#L6-)]

---
uid: SuperLinq.SuperEnumerable.OnErrorResumeNext``1(System.Collections.Generic.IEnumerable{System.Collections.Generic.IEnumerable{``0}})
example: [*content]
---
The following code example demonstrates how to concatenate multiple sequences, regardless of any errors that may occur, using `OnErrorResumeNext`.
[!code-csharp[](SuperLinq/OnErrorResumeNext/OnErrorResumeNext3.linq#L6-)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

// this sequence will throw an exception on the 6th element
var sequence = Enumerable.Range(1, 5)
.Concat(SuperEnumerable.Throw<int>(new InvalidOperationException()));

// Skip over the error and enumerate the second sequence
var result = sequence
.OnErrorResumeNext(
Enumerable.Range(1, 5));

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

// this sequence will throw an exception on the 6th element
var sequence = Enumerable.Range(1, 5)
.Concat(SuperEnumerable.Throw<int>(new InvalidOperationException()));

// Skip over the error and enumerate the second sequence
var result = SuperEnumerable
.OnErrorResumeNext(
sequence,
Enumerable.Range(1, 5));

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Query Kind="Statements">
<NuGetReference>SuperLinq</NuGetReference>
<Namespace>SuperLinq</Namespace>
</Query>

// this sequence will throw an exception on the 6th element
var sequence = Enumerable.Range(1, 5)
.Concat(SuperEnumerable.Throw<int>(new InvalidOperationException()));

// Skip over the error and enumerate the second sequence
var result = new[] { sequence, Enumerable.Range(1, 5), }
.OnErrorResumeNext();

Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");

// This code produces the following output:
// [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
90 changes: 71 additions & 19 deletions Source/SuperLinq/OnErrorResumeNext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,32 @@
public static partial class SuperEnumerable
{
/// <summary>
/// Creates a sequence that concatenates both given sequences, regardless of whether an error occurs.
/// Creates a sequence that concatenates both given sequences, regardless of whether an error occurs.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="first">First sequence.</param>
/// <param name="second">Second sequence.</param>
/// <returns>Sequence concatenating the elements of both sequences, ignoring errors.</returns>
/// <exception cref="ArgumentNullException"><paramref name="first"/> or <paramref name="second"/> is <see
/// langword="null"/>.</exception>
/// <typeparam name="TSource">
/// Source sequence element type.
/// </typeparam>
/// <param name="first">
/// First sequence.
/// </param>
/// <param name="second">
/// Second sequence.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="first"/> or <paramref name="second"/> is <see langword="null"/>.
/// </exception>
/// <returns>
/// Sequence concatenating the elements of both sequences, ignoring errors.
/// </returns>
/// <remarks>
/// <para>
/// <paramref name="first"/> is enumerated until either the sequence completes or an error occurs during
/// enumeration. After either of these events, <paramref name="second"/> is then enumerated in the same way.
/// </para>
/// <para>
/// This operator uses deferred execution and streams its results.
/// </para>
/// </remarks>
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second)
{
Guard.IsNotNull(first);
Expand All @@ -20,13 +38,30 @@ public static IEnumerable<TSource> OnErrorResumeNext<TSource>(this IEnumerable<T
}

/// <summary>
/// Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of the
/// sequences.
/// Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of
/// the sequences.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="sources">Source sequences.</param>
/// <returns>Sequence concatenating the elements of the given sequences, ignoring errors.</returns>
/// <exception cref="ArgumentNullException"><paramref name="sources"/> is <see langword="null"/>.</exception>
/// <typeparam name="TSource">
/// Source sequence element type.
/// </typeparam>
/// <param name="sources">
/// Source sequences.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="sources"/> is <see langword="null"/>.
/// </exception>
/// <returns>
/// Sequence concatenating the elements of the given sequences, ignoring errors.
/// </returns>
/// <remarks>
/// <para>
/// Each sequence of <paramref name="sources"/> is enumerated until either the sequence completes or an error occurs during
/// enumeration. The returned sequence completes when all sub-sequences have been enumerated in this manner.
/// </para>
/// <para>
/// This operator uses deferred execution and streams its results.
/// </para>
/// </remarks>
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(params IEnumerable<TSource>[] sources)
{
Guard.IsNotNull(sources);
Expand All @@ -35,13 +70,30 @@ public static IEnumerable<TSource> OnErrorResumeNext<TSource>(params IEnumerable
}

/// <summary>
/// Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of the
/// sequences.
/// Creates a sequence that concatenates the given sequences, regardless of whether an error occurs in any of
/// the sequences.
/// </summary>
/// <typeparam name="TSource">Source sequence element type.</typeparam>
/// <param name="sources">Source sequences.</param>
/// <returns>Sequence concatenating the elements of the given sequences, ignoring errors.</returns>
/// <exception cref="ArgumentNullException"><paramref name="sources"/> is <see langword="null"/>.</exception>
/// <typeparam name="TSource">
/// Source sequence element type.
/// </typeparam>
/// <param name="sources">
/// Source sequences.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="sources"/> is <see langword="null"/>.
/// </exception>
/// <returns>
/// Sequence concatenating the elements of the given sequences, ignoring errors.
/// </returns>
/// <remarks>
/// <para>
/// Each sequence of <paramref name="sources"/> is enumerated until either the sequence completes or an error occurs during
/// enumeration. The returned sequence completes when all sub-sequences have been enumerated in this manner.
/// </para>
/// <para>
/// This operator uses deferred execution and streams its results.
/// </para>
/// </remarks>
public static IEnumerable<TSource> OnErrorResumeNext<TSource>(this IEnumerable<IEnumerable<TSource>> sources)
{
Guard.IsNotNull(sources);
Expand Down

0 comments on commit a255443

Please sign in to comment.