ComfyUI Node

_.head

First-with-n, and the one-element list quirk

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

_.head is _.first wearing a different hat. It returns the first element of an array - and if you pass n, it returns the first n elements as a list. It's aliased as head and take, and it carries a default fallback for the empty case. If you've seen _.first and wondered why both exist: head is the take-style flavor with the guard behavior and the fallback baked in.

It's one of the _.* nodes in sfinktah/comfy-ovum, the auto-generated wrappers around underscore3 (a Python port of Underscore.js). Display name _.head, class UnderscoreHead, under ovum/underscore.

The inputs that matter

  • obj - the array (loose *; also accepts a _.CHAIN).
  • n - count, an INT, default 1.
  • default - an ANY fallback, JSON allowed, for when the list is empty.

Output is a loose * - either a single element or a list, depending on n.

The n quirk - read this

The docs call out a subtlety that will absolutely trip you: not passing n returns the first item; passing n=1 returns a list containing only the first item. Same number, different shape. If you set n=1 expecting one value and get [value], that's not a bug - it's underscore semantics. Verified against the port: first()1, first(1)[1], first(2)[1, 2]. This is the single most likely source of confusion with this node.

Why you'd reach for it

Same "peel off the front" job as _.first, with two upgrades: an n that behaves like take, and a default so an empty list doesn't hand you a null. If you want "the first three seeds" or "first item, or this fallback," head covers both in one node.

Install

ComfyUI Manager, search "comfy-ovum", or:

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

Restart, under ovum/underscore. No models, no downloads.

Honest warnings

Family disclaimer: work in progress, "an absolute disaster to use in production." Mind the n/no-n shape difference above. And the chain rule: feed a _.CHAIN in, get a chain out; _.value to unwrap.

Categoryovum/underscore

Inputs (3)

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

Outputs (1)

NameTypeDescription
**