Nodes/comfy-ovum/_.firstOr
ComfyUI Node

_.firstOr

_.firstOr returns a fallback

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

_.firstOr is _.first with a safety net: give it an array and a default, and you get the first element - or the default when the list is empty. One less "my workflow died because a list came back empty" moment, which is exactly the kind of small kindness this family could use more of.

It's part of the _.* set in sfinktah/comfy-ovum, the auto-generated wrappers around underscore3 (a Python port of Underscore.js). Note the name - firstOr isn't a stock Underscore.js method; it's an addition in the Python port, so don't go looking for it in the JS docs.

The inputs that matter

  • obj - the array (loose *; also accepts a _.CHAIN).
  • default - the fallback. An ANY input that accepts JSON where applicable, so you can hand it a string, a number, or even a nested array/object.

Output is a loose *: the first element when there is one, otherwise whatever you put in default. Because the output type is loose, wiring it into a downstream node is forgiving - the node doesn't try to force a type.

Why you'd reach for it

The empty-list problem is real in ComfyUI pipelines: an upstream node can return [] when a folder's empty, a search matches nothing, or a batch produces zero items, and the next node chokes. _.firstOr lets you substitute a sane default and keep the run alive. It's the defensive-programming version of _.first - same "peel one off the top" job, but with a guaranteed non-null result.

Install

Same pack, same ritual. ComfyUI Manager, search "comfy-ovum", or:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Restart, then it's under ovum/underscore. Nothing to download.

Honest warnings

The family disclaimer from the README: work in progress, "an absolute disaster to use in production." Don't mistake the fallback for type coercion - it returns your default as-is, and if you pass n-style arguments you won't find them here (this node has no count parameter; that's _.first's job). And the usual chain rule: feed a _.CHAIN in and you'll get a chain out, so unwrap with _.value before you wire the result onward.

Categoryovum/underscore

Inputs (2)

NameTypeDefaultDescription
objopt*Primary input object. Also accepts _.CHAIN to continue chaining.
defaultopt*default: JSON allowed for arrays/objects where applicable.

Outputs (1)

NameTypeDescription
**