first
Grab the head of a data list — or None if it's empty
- list
- first_element
"Give me the first one." It's the simplest possible question you can ask a list, and first is the node that answers it: one input, one output, the head of the list. It's the counterpart to the pack's last node, and it's so small you could almost skip it - except that in ComfyUI, extracting "the one item I care about" from a batch is a chore you don't want to do by hand.
It's part of Basic data handling, StableLlama's zero-dependency utility pack.
How it works
It indexes the list at position zero and returns that element. There's exactly one behavior worth knowing about, and it's a friendly one: if the list is empty, it returns None instead of erroring. A hard crash on an empty batch would be the worst possible failure mode for a workflow that sometimes produces zero results; this node swallows it gracefully and hands you a None you can branch on.
The input and output
list(*) - the data list.first_element(*) - the first item, orNoneif the list is empty.
Because the output is a plain single value (not a data list), it plugs into anything that accepts the item's type - which is exactly the point: pull one image out of a batch to preview it, take the first seed from a list, grab the head of a prompt list to test a single run.
Installing it
ComfyUI Manager → search "Basic data handling", or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart. No dependencies, no models.
Common issues
- "It returned None and I don't know why." The list was empty. If that's unexpected, trace the source - an upstream filter probably dropped everything. The
Noneis a signal, not a bug. - "I want a specific position, not the head." Use get item in the same pack and set the index. First is only element zero.
- "I want the last one." That's the pack's
lastnode. Pair them when you need both ends of a batch.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| list | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| first_element | * | — |