_.partition
Split a List Into the Passers and the Failers
- list_or_dict
- predicate
- LIST
_.partition runs a truth test over a list and hands you back two lists: everything that passed, and everything that failed. One predicate, two buckets. It's the "sort my candidates into keep and discard" node, and it saves you from running filter twice in opposite directions.
How it works
You give it a collection and a predicate - the truth test. Every element gets checked; the passers go in the first list, the failers in the second. The output is a single LIST that contains two lists: [[elements that passed], [elements that failed]]. I verified the shape: partition [1,2,3,4,5] on "is even" and you get [[2,4], [1,3,5]].
Here's the gotcha that catches people: there's only one output slot, and it's a list of lists. To actually use either half, you need a node that can index into it - take [0] for the passers or [1] for the failers. The pack's pystructure list utilities or any list-index/slice node will do it. Beginners see "two buckets" and expect two wires; it's one wire carrying both.
The inputs:
list_or_dict- the collection (or a_.CHAIN)predicate- anANYsocket that can take a function, a property-name string, or an objectpredicate_json- a multiline text widget used when the socket isn't connected
The predicate shorthand
This is where the family gets clever. The predicate doesn't have to be a function. The port runs it through underscore's iteratee machinery, so you can feed it shorthand:
- A property name string like
"active"- each element passes if itsactivevalue is truthy - An object like
{"active": true}- matcher shorthand, passes elements whose fields match
That makes partition usable without ever touching a function node, which is the difference between this node being practical and it being theoretical. The predicate_json widget is how you type that shorthand without a socket: a JSON object or a plain key string.
Where it fits
Partitioning is a two-branch routing pattern: "these keep going, those get dropped or handled separately." It's also genuinely useful for validation - split a list of generated results into the ones that meet a criterion and the ones that need a re-roll. The output shape takes a moment to get used to, but once you've got an index node wired up it's a clean one-node decision.
Installing
Part of comfy-ovum. ComfyUI Manager → search comfy-ovum → Install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart ComfyUI. No models, no extra pip packages for the underscore nodes - the port is bundled in the repo.
The bottom line
One predicate, two buckets - but the buckets arrive as a single list-of-lists, so keep an index node handy. And try the string-key shorthand before you reach for a function node; it usually does the job.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| list_or_dictopt | * | Primary input object (expected collection). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining. | |
| predicateopt | * | predicate: ANY input to override widget. Accepts function, key string, or object shorthand. | |
| predicate_jsonopt | STRING | predicate_json: JSON or key selector. Used when 'predicate' input is not connected. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LIST | LIST | — |