liveBook · Manning

Nthnext

As explained in Clojure: The Essential Reference

nthnext is a Clojure function that returns the sequence after a specified number of elements, or nil when that many elements are unavailable.

nthnext returns the sequence after removing a specified number of elements from the front of a sequential input. Unlike nthrest, it returns nil when that many elements are unavailable. section 10.2

Use nthnext with these expectations:

  • Pass the collection and required number n as (nthnext coll n). section 10.2
  • Treat negative n as zero; expect nil when n extends beyond the input. section 10.2

Selecting a later sequence

The sequential-selection family includes both (nthrest xs n) and (nthnext xs n); nthnext is the boundary-sensitive choice when exceeding the input should produce nil.

How Clojure: The Essential Reference covers it

How deep it goes
Defines arguments, negative offsets, sequential inputs, and nil behavior, but provides no implementation internals.
Examples
Shows nthnext in an API listing and contrasts it with nthrest in a compact sequence-function comparison.
What it assumes
Assumes familiarity with sequential inputs and sequence functions while defining nthnext's argument contract explicitly.
What you can do after
Apply nthnext to obtain a sequence tail while distinguishing unavailable offsets from nthrest's non-nil result.
How it connects
Connects nthnext with nthrest, drop, take, drop-last, take-last, and sequential processing.

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.