MapIndexed3

Builds a new collection whose elements are the results of applying the given mapping function to each triples of the elements of the collections.

The integer index passed to the function indicates the index (from 0) of element being transformed.

Parameters

Returns

Func<int, T, T2, T3, TResult> mapping

IEnumerable<T> source

IEnumerable<T2> source2

IEnumerable<T3> source3

IEnumerable<TResult>

Usage

Concatenating values and its index from three collections

//IEnumerable<int> source = { 1, 2, 3, 4, 5 }
//IEnumerable<int> source2 = { 5, 3, 3, 3, 0 }
//IEnumerable<string> source3 = {"Value", "Val", "V" }

IEnumerable<string> result = 
    source.Map3(
        source2,
        source3, 
        (index, value1, value2, value3) => 
            $"{value3} {index}: {value1 + value2}");

//result = { "Value 0: 6", "Val 1: 5", "V 2: 6" }

Last updated