ComfyUI Node

Select

Filter a LIST without writing Python

By Duanyll·Created 11 months ago·Updated 4 months ago· 2
Select
  • items
  • predicate
  • LIST

Select is filter() for ComfyUI. It walks a list, runs a predicate function on each item, and keeps only the items where the predicate returns True. If you've got a batch of images and you want to drop the ones that fail some check - blurry, too dark, wrong aspect - Select is the node that does it without you writing a line of Python.

The inputs

  • items - the LIST you're filtering (Basic Data Handling's LIST, not the native Data List).
  • predicate - a CLOSURE that takes one item and returns a BOOLEAN. True keeps it, False drops it.
  • output - a LIST of the survivors, in their original order.

Notice what's missing: there's no "keep if False" option and no inverted mode. If you want the rejected items, you build a second predicate that flips the logic - or, if your predicate is simple enough, define one function "is good" and one "is bad." It's a small thing, but it shapes how you structure your checks.

How it works

The standard coroutine loop: iterate the list, yield the predicate call for each item, and append to results only when the predicate returns truthy. Under the hood each predicate call expands that closure's body into real graph nodes - so a predicate that does something expensive (a full analysis pass) costs that analysis per item, no caching. Keep predicates cheap. The COMFYUI_FUNCTIONAL_COROUTINE_LIMIT (default 100) bounds iterations, so a very long list can trip it; raise the env var if you're filtering thousands of items.

The natural pairing

Select shines when it feeds a downstream Map: filter first, then transform only the survivors. Filter → Map → Fold is the pack's version of the classic data pipeline, and it's the pattern the example workflows lean on. Build a LIST, Select the keepers, Map the transform, and you've replaced a pile of manual node-wiring with three nodes and a couple of closures.

Where people get burned

  • Predicate returns a non-boolean - a numeric or string result still "works" via truthiness but produces confusing filters. Return True/False explicitly.
  • Native Data List deadlock - convert to LIST via Basic Data Handling before this node.
  • Expensive predicates - each item re-runs the whole predicate body, uncached. A heavy check over a long list is a slow run, not a bug.

Installing it

Ships in Duanyll/comfyui_functional. ComfyUI Manager: search "Duanyll/comfyui_functional", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/comfyui_functional
# restart ComfyUI

No models, no pip deps; install Basic Data Handling for the LIST type. Select is one of the pack's most approachable nodes - pair it with Map and you've got a real pipeline.

Categoryduanyll/functional/high_order

Inputs (2)

NameTypeDefaultDescription
itemsLIST
predicateCLOSURE

Outputs (1)

NameTypeDescription
LISTLIST