SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method Evaluate

    | Edit this page

    Evaluate<T>(IEnumerable<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> Evaluate<T>(this IEnumerable<Func<T>> functions)
    Parameters
    Type Name Description
    IEnumerable<Func<T>> functions

    The functions to evaluate.

    Returns
    Type Description
    IEnumerable<T>

    A sequence with results from invoking each function in the functions sequence.

    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 evaluated multiple times too.

    Examples

    The following code example demonstrates how to project a sequence of functions into their return values using Evaluate.

    int Func1() => 3;
    int Func2() => 5;
    int Func3() => 1;
    
    // Execute an action for each element
    var result = SuperEnumerable
        .Evaluate(new[] { Func1, Func2, Func3 });
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [3, 5, 1]
    
    Exceptions
    Type Condition
    ArgumentNullException

    functions is null.

    © SuperLinq Authors. All rights reserved.