# Scan2

Aplica a função `folder` em cada um par de elementos na mesma posição nas duas coleções, acumulando o resultado enquanto a percorre.

Este método considera o valor em `state` como valor inicial e o resultado acumulado enquanto percorre as duas coleções.

Este método é semelhante ao [`Fold2`](https://github.com/gabrielschade/tango-br/tree/973dafe9d6a8dbad594ebb5c6d71c46ff5727a5a/Modules/Collection/fold2.html), mas neste caso os resultados intermediários também são retornados.

| Parâmetros                                                                                                                | Retorno |
| ------------------------------------------------------------------------------------------------------------------------- | ------- |
| <p>Func\<TState, T, T2, TState> folder</p><p>TState state</p><p>IEnumerable\<T> source</p><p>IEnumerable\<T2> source2</p> | TState  |

## Como usar

&#x20;**Acumulando o maior valor na mesma posição de duas coleções**&#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 }
```

Para operações comuns entre valores `int`, `decimal`, `double`, `string` e `bool` você pode utilizar as [operações](https://github.com/gabrielschade/tango-br/tree/973dafe9d6a8dbad594ebb5c6d71c46ff5727a5a/Operations/Introduction.html) como `folder`.

&#x20;**Utilizando uma operação como 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}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gabriel-schade-cardoso.gitbook.io/tango-br/modulos/collection/scan2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
