SuperLinq SuperLinq
SuperLinq SuperLinq
DocFX + Singulink = ♥

Search Results for

    Method ZipMap

    | Edit this page

    ZipMap<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>)

    Applies a function to each element in a sequence and returns a sequence of tuples containing both the original item as well as the function result.

    Declaration
    public static IEnumerable<(TSource item, TResult result)> ZipMap<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
    Parameters
    Type Name Description
    IEnumerable<TSource> source

    A sequence of values to invoke a transform function on

    Func<TSource, TResult> selector

    A transform function to apply to each source element

    Returns
    Type Description
    IEnumerable<(TSource item, TResult result)>

    An IEnumerable<T> whose elements are a tuple of the original element and the item returned from calling the selector on that element.

    Type Parameters
    Name Description
    TSource

    The type of the elements of source

    TResult

    The type of the value returned by selector

    Remarks

    This operator uses deferred execution and streams its results.

    Examples

    The following code example demonstrates how to generate a sequence of values and a projection of that value using ZipMap.

    var sequence = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", };
    
    // Filter a sequence based on a leading value
    var result = sequence
        .ZipMap(x => x.ToString().Length);
    
    Console.WriteLine(
        "[" +
        string.Join(", ", result) +
        "]");
    
    // This code produces the following output:
    // [(one, 3), (two, 3), (three, 5), (four, 4), (five, 4), (six, 3), (seven, 5), (eight, 5), (nine, 4), (ten, 3)]
    
    Exceptions
    Type Condition
    ArgumentNullException

    source or selector is null.

    © SuperLinq Authors. All rights reserved.