Skip to content

Commit 0f18124

Browse files
Update documentation for Generate
1 parent ffa07bc commit 0f18124

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
uid: SuperLinq.SuperEnumerable.Generate``1(``0,System.Func{``0,``0})
3+
example: [*content]
4+
---
5+
The following code example demonstrates how to generate a sequence from a generator function using `Generate`.
6+
[!code-csharp[](SuperLinq/Generate/Generate.linq#L6-)]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Query Kind="Statements">
2+
<NuGetReference>SuperLinq</NuGetReference>
3+
<Namespace>SuperLinq</Namespace>
4+
</Query>
5+
6+
// Generate a sequence using a generator function
7+
var result = SuperEnumerable
8+
.Generate(1, n => n * 2)
9+
.Take(10);
10+
11+
Console.WriteLine(
12+
"[" +
13+
string.Join(", ", result) +
14+
"]");
15+
16+
// This code produces the following output:
17+
// [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]

Source/SuperLinq/Generate.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@
33
public static partial class SuperEnumerable
44
{
55
/// <summary>
6-
/// Returns a sequence of values consecutively generated by a generator function.
6+
/// Returns a sequence of values consecutively generated by a generator function.
77
/// </summary>
8-
/// <typeparam name="TResult">Type of elements to generate.</typeparam>
9-
/// <param name="initial">Value of first element in sequence</param>
8+
/// <typeparam name="TResult">
9+
/// Type of elements to generate.
10+
/// </typeparam>
11+
/// <param name="initial">
12+
/// Value of first element in sequence
13+
/// </param>
1014
/// <param name="generator">
11-
/// Generator function which takes the previous series element and uses it to generate the next element.
15+
/// Generator function which takes the previous series element and uses it to generate the next element.
1216
/// </param>
13-
/// <returns>A sequence containing the generated values.</returns>
14-
/// <exception cref="ArgumentNullException"><paramref name="generator"/> is <see langword="null"/>.</exception>
17+
/// <returns>
18+
/// A sequence containing the generated values.
19+
/// </returns>
20+
/// <exception cref="ArgumentNullException">
21+
/// <paramref name="generator"/> is <see langword="null"/>.
22+
/// </exception>
1523
/// <remarks>
16-
/// This function defers element generation until needed and streams the results.
24+
/// This function defers element generation until needed and streams the results. It is treated as an
25+
/// infinite sequence, and will not terminate.
1726
/// </remarks>
18-
/// <example>
19-
/// <code><![CDATA[
20-
/// var result = SuperEnumerable.Generate(2, n => n * n).Take(5);
21-
/// ]]></code>
22-
/// The <c>result</c> variable, when iterated over, will yield 2, 4, 16, 256, and 65536, in turn.
23-
/// </example>
24-
2527
public static IEnumerable<TResult> Generate<TResult>(TResult initial, Func<TResult, TResult> generator)
2628
{
2729
Guard.IsNotNull(generator);

0 commit comments

Comments
 (0)