_.foldr
_.foldr and why direction matters
- obj
- memo
- *
_.foldr is the right-associative sibling of _.foldl (aka reduceRight in JS). Same job - collapse a list into one accumulated value - but it walks the list from the end and folds backwards. For addition, direction doesn't matter. For string concatenation, reversing direction changes the order of the result. That ordering sensitivity is the whole reason the node exists.
It's part of the _.* family in sfinktah/comfy-ovum, generated as a wrapper around underscore3 (a Python port of Underscore.js). It shares its sibling's shape: obj in, memo in, one loose * out.
The inputs that matter
- obj - the collection to reduce from the right (loose
*; also accepts a_.CHAIN). - memo - the seed accumulator (
ANY, JSON allowed). Same advice as_.foldl: set it explicitly.
Output is a loose * - the folded result.
Why direction matters
Think about building a string from parts: folding left produces "a"+"b"+"c" order; folding right produces "c"+"b"+"a". If you're assembling a filename, a prompt, or a comma-joined list and the order comes out backwards, _.foldr vs _.foldl is likely why. For symmetric operations like numeric sums, the two are interchangeable - direction only shows up in non-commutative folds.
The honest catch
Same as _.foldl, squared: the schema exposes obj and memo but no way to supply the fold function - no iteratee input, no _json fallback. So out of the box it's a stub waiting for a function you can't currently type into a widget. It's the clearest "work in progress" signal in the whole underscore family, and the README's "not for production" disclaimer applies with feeling.
Install
Same pack, same steps. ComfyUI Manager, search "comfy-ovum", or:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart, under ovum/underscore. No models, no downloads.
Honest warnings
Don't build a workflow on _.foldr today. If you genuinely need right-to-left folding, a tiny custom Python node with functools.reduce(..., reverse) is more honest. And remember the memo default is an empty list in this port - seed your accumulator or you'll be debugging [] + value type errors. Chain rule as always: chain in, chain out, _.value to unwrap.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| objopt | * | Primary input object. Also accepts _.CHAIN to continue chaining. | |
| memoopt | * | memo: JSON allowed for arrays/objects where applicable. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |