ComfyUI Node

_.maxBy

Max by a key — and why you'll probably use _.max instead.

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

_.maxBy is supposed to be the "biggest by this key" sibling of _.max - the convenient form where you say "give me the item with the highest score" without building a function. The idea is right. The wiring, in the current version of this pack, is not. This is one of those nodes where knowing the workaround matters more than the happy path.

What it is

Part of the ovum/underscore family in sfinktah/comfy-ovum, wrapping the maxBy method of underscore3, a Python port of Underscore.js. Here's the core issue: the port implements it as max(self.obj, key=key) - it passes the key value straight to Python's built-in max as the key function. That means key must be a callable. A string like "score" is not a callable.

Inputs and the mismatch

The node exposes two inputs:

  • obj (type *) - the list to search.
  • key (STRING, default "") - described as a key string.

The mismatch should be obvious: the schema hands you a text box for something the underlying code expects to be a function. If you type "score" into that box and run it, the call into max(..., key="score") raises a TypeError - a string isn't callable. There's no iteratee socket here to hand it a real function, and no JSON key-selector path like _.max has. Output is typed * (ANY), and chain mode technically works, but you'll struggle to reach a successful result through the normal UI.

What to actually do

Reach for _.max instead. It does the same job through a working path: feed it the list, set iteratee_json to "score", and you get the highest-scoring item back - cleanly, and in a form that survives saves. _.maxBy is a half-finished sibling, the kind of thing the README's "work in progress" label exists for. By all means poke at it to see if a pack update has made key accept a callable or a selector, but don't build a workflow around the current behavior.

Installing comfy-ovum

You'll still want the pack for the working members of the family. ComfyUI Manager: search for comfy-ovum, install, restart. Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
pip install -r comfy-ovum/requirements.txt

Restart and you're done. No model downloads, no CUDA - pure-Python utilities. And if you hit TypeError: 'str' object is not callable from this node, you now know exactly why.

Categoryovum/underscore

Inputs (2)

NameTypeDefaultDescription
objopt*Primary input object. Also accepts _.CHAIN to continue chaining.
keyoptSTRINGkey (string)

Outputs (1)

NameTypeDescription
**