liveBook · Manning

Nfirst

As explained in Clojure: The Essential Reference

nfirst is a Clojure function that returns the sequence obtained after removing the first element of the first nested sequence, or nil when unavailable.

nfirst returns the sequence after removing the first element from the first nested sequence in coll. It accepts a seqable collection or nil and returns nil when no result is available. section 10.1

Nested-sequence example

(nfirst '((0 1 2))) ;; (1 2) Unlike nnext, which skips two elements of the outer sequence, nfirst takes the first outer element and advances inside it. section 10.1

Keep these edge cases in mind:

  • Assumes nested data; unsuitable input can raise IllegalArgumentException. section 10.1
  • Produces a sequence and belongs with first, next, and rest in recursive sequential processing. section 10.1

How Clojure: The Essential Reference covers it

How deep it goes
Defines inputs, outputs, edge cases, and related functions, but stops short of implementation internals.
Examples
Uses nested sequences, nil, and empty collections to show returned sequences and unavailable results.
What it assumes
Assumes familiarity with Clojure sequences and nested data, while identifying seqable inputs and nil behavior.
What you can do after
Apply it to advance inside the first nested sequence while preserving concise sequential-processing code.
How it connects
Connects nfirst with first, next, rest, nnext, ffirst, and fnext.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.