Skip to content

Commit 9eb27ce

Browse files
Update documentation for ScanRight
1 parent 7cad7a9 commit 9eb27ce

File tree

4 files changed

+99
-39
lines changed

4 files changed

+99
-39
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
uid: ScanRight``1(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``0,``0})
3+
example: [*content]
4+
---
5+
The following code example demonstrates how to execute a right-associative post-fix scan by key on a sequence using `ScanRight`.
6+
[!code-csharp[](SuperLinq/ScanBy/ScanBy1.linq#L6-)]
7+
8+
---
9+
uid: ScanRight``2(System.Collections.Generic.IEnumerable{``0},``1,System.Func{``0,``1,``1})
10+
example: [*content]
11+
---
12+
The following code example demonstrates how to execute a right-associative post-fix scan by key on a sequence using `ScanRight`.
13+
[!code-csharp[](SuperLinq/ScanBy/ScanBy2.linq#L6-)]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
var sequence = Enumerable.Range(1, 5)
7+
.Select(x => x.ToString());
8+
9+
// execute a scan of the sequence
10+
var result = sequence
11+
.ScanRight((a, b) => $"({a}+{b})");
12+
13+
Console.WriteLine(
14+
"[ \"" +
15+
string.Join("\", \"", result) +
16+
"\" ]");
17+
18+
// This code produces the following output:
19+
// [ "(1+(2+(3+(4+5))))", "(2+(3+(4+5)))", "(3+(4+5))", "(4+5)", "5" ]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
var sequence = Enumerable.Range(1, 5);
7+
8+
// execute a scan of the sequence
9+
var result = sequence
10+
.ScanRight(
11+
"6",
12+
(a, b) => $"({a}+{b})");
13+
14+
Console.WriteLine(
15+
"[ \"" +
16+
string.Join("\", \"", result) +
17+
"\" ]");
18+
19+
// This code produces the following output:
20+
// [ "(1+(2+(3+(4+(5+6)))))", "(2+(3+(4+(5+6))))", "(3+(4+(5+6)))", "(4+(5+6))", "(5+6)", "6" ]

Source/SuperLinq/ScanRight.cs

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,31 @@ namespace SuperLinq;
55
public static partial class SuperEnumerable
66
{
77
/// <summary>
8-
/// Performs a right-associative scan (inclusive prefix) on a sequence of elements.
9-
/// This operator is the right-associative version of the
10-
/// <see cref="Scan{TSource}(IEnumerable{TSource}, Func{TSource, TSource, TSource})"/> LINQ operator.
8+
/// Performs a right-associative scan (inclusive prefix) on a sequence of elements. This operator is the
9+
/// right-associative version of the <see cref="Scan{TSource}(IEnumerable{TSource}, Func{TSource, TSource,
10+
/// TSource})"/> LINQ operator.
1111
/// </summary>
12-
/// <typeparam name="TSource">Type of elements in source sequence.</typeparam>
13-
/// <param name="source">Source sequence.</param>
12+
/// <typeparam name="TSource">
13+
/// Type of elements in source sequence.
14+
/// </typeparam>
15+
/// <param name="source">
16+
/// Source sequence.
17+
/// </param>
1418
/// <param name="func">
15-
/// A right-associative accumulator function to be invoked on each element.
16-
/// Its first argument is the current value in the sequence; second argument is the previous accumulator value.
19+
/// A right-associative accumulator function to be invoked on each element. Its first argument is the current
20+
/// value in the sequence; second argument is the previous accumulator value.
1721
/// </param>
18-
/// <returns>The scanned sequence.</returns>
19-
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
20-
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
21-
/// <example>
22-
/// <code><![CDATA[
23-
/// var result = Enumerable.Range(1, 5).Select(i => i.ToString()).ScanRight((a, b) => $"({a}+{b})");
24-
/// ]]></code>
25-
/// The <c>result</c> variable will contain <c>[ "(1+(2+(3+(4+5))))", "(2+(3+(4+5)))", "(3+(4+5))", "(4+5)", "5" ]</c>.
26-
/// </example>
22+
/// <returns>
23+
/// The scanned sequence.
24+
/// </returns>
25+
/// <exception cref="ArgumentNullException">
26+
/// <paramref name="source"/> or <paramref name="func"/> is <see langword="null"/>.
27+
/// </exception>
2728
/// <remarks>
28-
/// This operator uses deferred execution and streams its results.
29-
/// Source sequence is consumed greedily when an iteration of the resulting sequence begins.
29+
/// <para>
30+
/// This method is implemented by using deferred execution. However, <paramref name="source"/> will be consumed
31+
/// in it's entirety immediately when first element of the returned sequence is consumed.
32+
/// </para>
3033
/// </remarks>
3134
public static IEnumerable<TSource> ScanRight<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func)
3235
{
@@ -99,29 +102,34 @@ public override void CopyTo(T[] array, int arrayIndex)
99102
}
100103

101104
/// <summary>
102-
/// Performs a right-associative scan (inclusive prefix) on a sequence of elements.
103-
/// The specified seed value is used as the initial accumulator value.
104-
/// This operator is the right-associative version of the
105-
/// <see cref="Scan{TSource, TState}(IEnumerable{TSource}, TState, Func{TState, TSource, TState})"/> LINQ operator.
105+
/// Performs a right-associative scan (inclusive prefix) on a sequence of elements. This operator is the
106+
/// right-associative version of the <see cref="Scan{TSource}(IEnumerable{TSource}, Func{TSource, TSource,
107+
/// TSource})"/> LINQ operator.
106108
/// </summary>
107-
/// <typeparam name="TSource">The type of the elements of source.</typeparam>
108-
/// <typeparam name="TAccumulate">The type of the accumulator value.</typeparam>
109-
/// <param name="source">Source sequence.</param>
110-
/// <param name="seed">The initial accumulator value.</param>
111-
/// <param name="func">A right-associative accumulator function to be invoked on each element.</param>
112-
/// <returns>The scanned sequence.</returns>
113-
/// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
114-
/// <exception cref="ArgumentNullException"><paramref name="seed"/> is <see langword="null"/>.</exception>
115-
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
116-
/// <example>
117-
/// <code><![CDATA[
118-
/// var result = Enumerable.Range(1, 4).ScanRight("5", (a, b) => string.Format("({0}/{1})", a, b));
119-
/// ]]></code>
120-
/// The <c>result</c> variable will contain <c>[ "(1+(2+(3+(4+5))))", "(2+(3+(4+5)))", "(3+(4+5))", "(4+5)", "5" ]</c>.
121-
/// </example>
109+
/// <typeparam name="TSource">
110+
/// Type of elements in source sequence.
111+
/// </typeparam>
112+
/// <param name="source">
113+
/// Source sequence.
114+
/// </param>
115+
/// <param name="func">
116+
/// A right-associative accumulator function to be invoked on each element. Its first argument is the current
117+
/// value in the sequence; second argument is the previous accumulator value.
118+
/// </param>
119+
/// <param name="seed">
120+
/// The initial accumulator value.
121+
/// </param>
122+
/// <returns>
123+
/// The scanned sequence.
124+
/// </returns>
125+
/// <exception cref="ArgumentNullException">
126+
/// <paramref name="source"/> or <paramref name="func"/> is <see langword="null"/>.
127+
/// </exception>
122128
/// <remarks>
123-
/// This operator uses deferred execution and streams its results.
124-
/// Source sequence is consumed greedily when an iteration of the resulting sequence begins.
129+
/// <para>
130+
/// This method is implemented by using deferred execution. However, <paramref name="source"/> will be consumed
131+
/// in it's entirety immediately when first element of the returned sequence is consumed.
132+
/// </para>
125133
/// </remarks>
126134
public static IEnumerable<TAccumulate> ScanRight<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TSource, TAccumulate, TAccumulate> func)
127135
{

0 commit comments

Comments
 (0)