Method From
| Edit this page View SourceFrom<T>(Func<T>)
Returns a single-element sequence containing the result of invoking the function.
Declaration
public static IEnumerable<T> From<T>(Func<T> function)
Parameters
Type | Name | Description |
---|---|---|
Func<T> | function | The function to evaluate. |
Returns
Type | Description |
---|---|
IEnumerable<T> | A sequence with the value resulting from invoking |
Type Parameters
Name | Description |
---|---|
T | The type of the object returned by the function. |
Remarks
This operator uses deferred execution and streams the results. If the resulting sequence is enumerated multiple times, the function will be invoked multiple times too.
Examples
The following code example demonstrates how to project a sequence of functions into their return values using From
.
int Func1() => 3;
// Execute an action for each element
var result = SuperEnumerable
.From(Func1);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [3]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
From<T>(Func<T>, Func<T>)
Returns a sequence containing the result of invoking each parameter function in order.
Declaration
public static IEnumerable<T> From<T>(Func<T> function1, Func<T> function2)
Parameters
Type | Name | Description |
---|---|---|
Func<T> | function1 | The first function to evaluate. |
Func<T> | function2 | The second function to evaluate. |
Returns
Type | Description |
---|---|
IEnumerable<T> | A sequence with the values resulting from invoking |
Type Parameters
Name | Description |
---|---|
T | The type of the object returned by the functions. |
Remarks
This operator uses deferred execution and streams the results. If the resulting sequence is enumerated multiple times, the functions will be invoked multiple times too.
Examples
The following code example demonstrates how to project a sequence of functions into their return values using From
.
int Func1() => 3;
int Func2() => 5;
// Execute an action for each element
var result = SuperEnumerable
.From(Func1, Func2);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [3, 5]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
From<T>(Func<T>, Func<T>, Func<T>)
Returns a sequence containing the result of invoking each parameter function in order.
Declaration
public static IEnumerable<T> From<T>(Func<T> function1, Func<T> function2, Func<T> function3)
Parameters
Type | Name | Description |
---|---|---|
Func<T> | function1 | The first function to evaluate. |
Func<T> | function2 | The second function to evaluate. |
Func<T> | function3 | The third function to evaluate. |
Returns
Type | Description |
---|---|
IEnumerable<T> | A sequence with the values resulting from invoking |
Type Parameters
Name | Description |
---|---|
T | The type of the object returned by the functions. |
Remarks
This operator uses deferred execution and streams the results. If the resulting sequence is enumerated multiple times, the functions will be invoked multiple times too.
Examples
The following code example demonstrates how to project a sequence of functions into their return values using From
.
int Func1() => 3;
int Func2() => 5;
int Func3() => 1;
// Execute an action for each element
var result = SuperEnumerable
.From(Func1, Func2, Func3);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [3, 5, 1]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
From<T>(params Func<T>[])
Returns a sequence containing the values resulting from invoking (in order) each function in the source sequence of functions.
Declaration
public static IEnumerable<T> From<T>(params Func<T>[] functions)
Parameters
Type | Name | Description |
---|---|---|
Func<T>[] | functions | The functions to evaluate. |
Returns
Type | Description |
---|---|
IEnumerable<T> | A sequence with the values resulting from invoking all of the |
Type Parameters
Name | Description |
---|---|
T | The type of the object returned by the functions. |
Remarks
This operator uses deferred execution and streams the results. If the resulting sequence is enumerated multiple times, the functions will be invoked multiple times too.
Examples
The following code example demonstrates how to project a sequence of functions into their return values using From
.
int Func1() => 3;
int Func2() => 5;
int Func3() => 1;
int Func4() => 7;
// Execute an action for each element
var result = SuperEnumerable
.From(Func1, Func2, Func3, Func4);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [3, 5, 1, 7]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|