_.filter
Keep the values that pass the test
- list_or_dict
- predicate
- LIST
_.filter is the workhorse of the underscore family: it walks a collection, keeps every value that passes a truth test, and returns the survivors as a list. The author's description: "Looks through each value in the list, returning an array of all the values that pass a truth test (predicate)." Where _.every asks "do all of them pass?" and _.detect grabs the first match, _.filter returns everything that passes - which makes it the node you reach for when a list needs trimming by a rule.
Think: "only the prompts that mention 'anime'", "only the configs with enabled: true", "only the seeds above 1000." If the condition is expressible, _.filter is the filter.
How it works
Generated wrapper around underscore3, the bundled Python port of Underscore.js. The predicate is the flexible part, and like _.countBy and _.every it supports Underscore's shorthand forms:
- Key string:
predicate = "enabled"keeps elements whoseenabledattribute is truthy. - Object shorthand: a JSON object like
{"type": "anime"}keeps elements matching it. - Function: a Python callable via a
PY_FUNC-style socket, if you've exported one.
The predicate_json widget is the text-box fallback - the tooltip says it's a "JSON or key selector, used when 'predicate' input is not connected." Most of the time you'll type a property name or a small JSON object there. Original order is preserved, and the input collection isn't mutated.
Inputs and output
list_or_dict(any type) - the collection to filter. For dicts it filters values. Accepts a_.CHAINto continue a chain.predicate(any type) - optional socket override.predicate_json(STRING, multiline) - the widget you'll actually set: key name or JSON object.- Output:
LIST- the passing values.
Installing it
Part of sfinktah/comfy-ovum ("comfy-ovum"):
- ComfyUI Manager: search "comfy-ovum", install, restart.
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/sfinktah/comfy-ovum, restart.
No model downloads; light dependencies; underscore3 bundled in the repo.
Where it shines
_.filter is the most genuinely useful node in this whole family - it's the one you'll actually reach for. Use it right before a batch operation to trim inputs, or to build a shortlist that a conditional then consumes. The traps are the usual iteratee ones: leave predicate_json empty and nothing connected and it keeps only truthy values (which is a valid filter on its own), and remember dict inputs filter by value, not key. And while the README's "work in progress" warning applies to the family, _.filter with a plain key selector is predictable enough to lean on for real work.
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 | — |