liveBook · Manning

Ffirst

As explained in Clojure: The Essential Reference

ffirst is a Clojure function that returns the first element of the first nested sequence or nil when it is unavailable.

ffirst returns the first element of the first nested sequence. It accepts a sequential input or nil and returns one value, or nil when no value is available. section 10.1

Use ffirst when nested data makes first (first coll) more verbose:

  • On nil or an empty collection, ffirst returns nil; malformed non-nested input can raise IllegalArgumentException. section 10.1

Processing nested records

For message data such as [["A" 1 28] ["H" 37 82 11]], (ffirst xs) extracts the current record's item, while (fnext xs) supplies the successor record. A lazy process can emit {:item "A", :succ ["H" 37 82 11]}.

How Clojure: The Essential Reference covers it

How deep it goes
Defines inputs, outputs, nil behavior, nested-input assumptions, and exceptions, then demonstrates recursive use.
Examples
Demonstrates nested numeric sequences, nil and empty collections, and lazy message processing.
What it assumes
Assumes familiarity with Clojure sequences and first, while identifying sequential or seqable inputs and nested-data requirements.
What you can do after
Apply ffirst in Clojure code to extract nested leading values and handle unavailable results with nil.
How it connects
Relates ffirst to first, fnext, nfirst, nnext, rest, and next as compact sequential-processing operations.

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.