ComfyUI Node

_.foldl

_.foldl is reduce, and it has a memo trap

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.foldl
  • obj
  • memo
  • *

_.foldl is the family name for reduce: walk a list left to right, and fold every element into a single accumulated result. It's the Swiss Army knife of list processing - sum the values, build a string, flatten a structure by hand, count matches. Also aliased inject, and the docs spell out the iteratee contract: (memo, value, index) in, memo out.

It's one of the _.* nodes in sfinktah/comfy-ovum, the author's grab-bag pack, wrapping underscore3 (a Python port of Underscore.js). And honestly? This one is where you feel the "work in progress" label most.

The memo trap

The memo is the accumulator - what each step returns and the next step receives. Here's the gotcha I verified against the shipped code: if you don't provide a memo, the default is an empty list, not zero. That's fine for building lists, but it means reduce(lambda m, v: m + v) for a numeric sum will crash on [] + 1. For any numeric accumulation you must seed the memo yourself - memo=0 for a sum, memo=1 for a product, memo="" for string building.

The inputs that matter

  • obj - the collection to reduce (loose *; also accepts a _.CHAIN).
  • memo - the seed value for the accumulator. An ANY input accepting JSON where applicable. Set it; don't rely on the default unless you want a list.

Output is a loose * - the final accumulated value, whatever type it turned into.

The honest catch

Here's the uncomfortable part: the schema ships obj and memo, but not the reduce function itself. There's no iteratee widget and no _json fallback on this node. In practice that means the node is a stub unless you have a way to supply the function - which is exactly the "not ready for production" the README warns about. Treat _.foldl as a placeholder for a capability, not a finished tool.

Install

ComfyUI Manager, search "comfy-ovum", or:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Restart, find it under ovum/underscore. No models, no downloads.

Honest warnings

Family disclaimer applies - and this node more than most. If you actually need a sum or a string fold in a real workflow, reach for a dedicated math/string node or a small custom Python node instead. And the chain rule never changes: feed a _.CHAIN in, get a chain out; unwrap with _.value.

Categoryovum/underscore

Inputs (2)

NameTypeDefaultDescription
objopt*Primary input object. Also accepts _.CHAIN to continue chaining.
memoopt*memo: JSON allowed for arrays/objects where applicable.

Outputs (1)

NameTypeDescription
**