Nest
Repeat a step N times, no list required
- function
- x
- *
Nest is the "do this exactly N times" node. Where Map loops over a list and Fold accumulates over a list, Nest loops over nothing - it takes one starting value, applies the same function to it depth times, and hands you the result. No list required. It's the fixed-count for loop of this pack.
The inputs
function- aCLOSUREtaking one argument, the current value.x- the starting value, any type.depth- how many times to apply the function. Default 1, range 1–100.- output - the value after
depthapplications, same type asx.
Classic use: a function that sharpens an image, and you want to decide "how many sharpen passes" with one integer. Nest handles it - depth 3 means three consecutive sharpen applications. It's also the natural home for iterative refinement loops where you don't have a list at all, just "run this pass N times."
How it works
The coroutine machinery again, but simpler than Map: a for _ in range(depth) loop that yields (function, [x]) each iteration, feeds the result back as the new x, and returns the final value. Each iteration expands the function body into real graph nodes with fresh IDs, so - the pack's recurring theme - every iteration re-runs, no caching. Cost multiplies by depth; a depth of 50 on a cheap transform is fine, a depth of 50 on a full sampler pass is fifty sampler runs.
The COMFYUI_FUNCTIONAL_COROUTINE_LIMIT (default 100) applies here too: since the UI caps depth at 100 and the coroutine limit defaults to 100, a maxed-out Nest can sit right on the edge. If you're doing genuinely deep nesting, raise the env var.
The trap: depth is the only brake
Nest has no predicate and no termination check - it runs exactly depth times and stops. That's the feature, but it's also the reason Nest is the safe loop in this pack while NestWhile is the dangerous one: you can't write an infinite Nest. If a Nest workflow behaves unexpectedly, check depth first - it's the only thing that controls how long this runs.
Where people get burned
- Depth from a wrong source - if depth is wired to a value that's bigger than you think, the run just takes longer. No error, just slower.
- State loss - Nest only carries the single
xforward. If your function needs side inputs (a seed, a strength), bundle them into the value or capture them; don't assume they persist between iterations. - Native Data List - still the pack-wide deadlock if you route lists through ComfyUI's built-in type. Convert via Basic Data Handling.
Installing it
Ships in Duanyll/comfyui_functional. ComfyUI Manager: search "Duanyll/comfyui_functional", or:
cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/comfyui_functional
# restart ComfyUI
No models, no pip deps; install Basic Data Handling for LIST support. Nest is the loop you reach for when there's no list to iterate - just a count.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| function | CLOSURE | — | |
| x | * | — | |
| depth | INT | 11–100 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |