# logic.collect

Lists what reached it: the payloads of the branches wired into it, or the per-item answers of a logic.foreach loop it closes

# logic.collect

```
logic.collect → collect
```

Lists what reached it: the payloads of the branches wired into it, or the per-item answers of a [`logic.foreach`](/nodes/logic/logic.foreach.md) loop it closes. Like every node it runs once, when every edge into it has delivered or been skipped, so a branch not taken is simply missing from the list. Answers one key, `collect: { items, count }` — `items` the delivered payloads in DSL text order — on top of those payloads merged in the same order (a key from a later one wins). Each upstream's answer also stays at `$nodes.<id>.<key>`. After a loop body (`[f]:item -> [x]`, `[x] -> [c]`) it closes the loop: it runs once after every item, `items` in item order, on top of the payload the foreach received; an empty list answers `{ items: [], count: 0 }`.

## Examples

### Wait for two fetches

```
| logic.collect
```

After `[b] -> [d]` and `[c] -> [d]` with `b` declared first: `input.collect.items[0]` is b's payload; `$nodes.b.response` names it too. Had `b` been on a branch not taken, `items` would hold c's payload alone.

It answers:

```json
{
  "response": {
    "status": 200,
    "body": {
      "b": 2
    }
  },
  "collect": {
    "items": [
      {
        "response": {
          "status": 200,
          "body": {
            "a": 1
          }
        }
      },
      {
        "response": {
          "status": 200,
          "body": {
            "b": 2
          }
        }
      }
    ],
    "count": 2
  }
}
```
