ScanBack2

Applies a function to each pair of elements of the collections, threading an accumulator argument through the computation.

Take the third argument, and apply the function to it and the last pair of elements of the collections. Then feed this result into the function along with the previous pair of elements and so on.

Returns the collection of intermediate results and the final result.

This method is similar to FoldBack2, but in this case the intermediate results are returned as well.

Usage

Accumulating the bigger value in the same position of these two collections

//IEnumerable<int> source =  { 0, 1, 2, 3, 4, 5 }
//IEnumerable<int> source2 = { 5, 4, 3, 2, 1, 0 }

int result = 
    source.ScanBack2( 
        source2, 
        (_state, element1, element2) =>
             _state + Math.Max(element1, element2),
        10);

//result = { 40, 35, 30, 25, 20, 15 }

Last updated