Nodes/comfy-ovum/_.castArray
ComfyUI Node

_.castArray

Guarantee a value is an array, no matter what it is

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

_.castArray is the defensive-programming node: take a value that might or might not already be an array, and return a value that is definitely an array. It's the Underscore.js castArray method surfaced in ComfyUI, and its whole reason to exist is that downstream logic often assumes "a list," while your input is "a list, or a single item, or honestly who knows."

When you'd reach for it

Normalization, basically. You have a value that could arrive as a single scalar, a tuple, or an actual list, and you need uniform array handling before it hits a loop, a join, or any node that expects collection semantics. castArray collapses that uncertainty: if the value is already array-like it passes through; if it's a single item, it comes out as a one-element array.

The node's description is characteristically terse: "Underscore method 'castArray'." That's the whole contract.

How it works

It's part of the pack's underscore family, built on the underscore3 Python port of Underscore.js. Your input goes into the node's machinery (deep-copied, so the original is never mutated), castArray runs, and the result comes back. The primary input is obj (optional, *) - anything, and again, like every node in this family, it accepts a _.CHAIN to continue a chain started by _.chain or another underscore node. Output is wildcard *, since the return shape depends on what you fed in.

The caveat you must read

The pack's own README flags this entire underscore subsystem in terms I won't soften: "These are an absolute disaster to use in production. They are a WORK IN PROGRESS and are not recommended for use in workflows." That's the author's warning, and it applies to _.castArray as much as to _.all and _.any.

Honestly, for a pure normalization move like this one, there's a simpler, more battle-tested option sitting right in the same pack: the ReinterpretCast / ReinterpretAsListCast nodes in the Data category, which do list-shaping without the underscore machinery's WIP baggage. Use _.castArray if you specifically want the Underscore semantic (including chain compatibility); use the cast nodes if you just want the value to come out list-shaped and move on.

Installing it

Part of the comfy-ovum pack:

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

Restart ComfyUI, or ComfyUI Manager → search "comfy-ovum" → Install. The underscore port ships with the pack; nothing extra to fetch.

Common gotchas

  • WIP label applies. The author says not to rely on this family in production. Heed it for anything you can't easily rewire.
  • "Array" here is Underscore's notion. castArray wraps non-array inputs in a list; it doesn't split strings into characters or otherwise reinterpret content. If you expected char-splitting, that's a different operation.
  • Wildcard output means the type checker won't help you. What comes out is whatever it is; wire it into something that handles * and verify the shape downstream.
Categoryovum/underscore

Inputs (1)

NameTypeDefaultDescription
objopt*Primary input object. Also accepts _.CHAIN to continue chaining.

Outputs (1)

NameTypeDescription
**