> For the complete documentation index, see [llms.txt](https://gabriel-schade-cardoso.gitbook.io/tango/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gabriel-schade-cardoso.gitbook.io/tango/modules/collection/scan2.md).

# Scan2

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

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

Returns the collection of intermediate results and the final result.

This method is similar to [`Fold2`](https://github.com/gabrielschade/tango/tree/379cc4a38ae47796971eb875ec66e7dc053a9081/Modules/Collection/fold2.html), but in this case the intermediate results are returned as well.

| Parameters                                                                                                                | Returns |
| ------------------------------------------------------------------------------------------------------------------------- | ------- |
| <p>Func\<TState, T, T2, TState> folder</p><p>TState state</p><p>IEnumerable\<T> source</p><p>IEnumerable\<T2> source2</p> | TState  |

## Usage

&#x20;**Accumulating an individual property of each element through a collection**&#x20;

```csharp
//IEnumerable<int> source = { 1, 2, 3 }
//IEnumerable<int> source2 = { 3, 2, 1 }

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

//result = {15, 17, 20 }
```

When the type of elements in your collection are: `int`, `decimal`, `double`, `string` or `bool` you can also use this function combined with the `Operations` described in [operations section](https://github.com/gabrielschade/tango/tree/379cc4a38ae47796971eb875ec66e7dc053a9081/Operations/Introduction.html) as folder functions.

&#x20;**Using an operation as a folder**&#x20;

```csharp
//IEnumerable<int> source = { 2, 3, 5, 0 }
//IEnumerable<int> source2 = { 3, 2, 0, 5 }

source.Scan2(source2, 30, IntegerOperations.Add3);

//result = { 35, 40, 45, 50}
```
