Nodes/comfy-ovum/_.filter
ComfyUI Node

_.filter

Keep the values that pass the test

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.filter
  • list_or_dict
  • predicate
  • LIST
predicate_json

_.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 whose enabled attribute 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 _.CHAIN to 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.

Categoryovum/underscore

Inputs (3)

NameTypeDefaultDescription
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_jsonoptSTRINGpredicate_json: JSON or key selector. Used when 'predicate' input is not connected.

Outputs (1)

NameTypeDescription
LISTLIST