ClojureDocs

Nav

Namespaces

next

clojure.core

Available since 1.0 (source)
  • (next coll)
Returns a seq of the items after the first. Calls seq on its
argument.  If there are no more items, returns nil.
3 Examples
user=> (next '(:alpha :bravo :charlie))
(:bravo :charlie)

user=> (next (next '(:one :two :three)))
(:three)

user=> (next (next (next '(:one :two :three))))
nil
;; next is used in the recursive call.  (This is a naive implementation for illustration only.  Using `rest` is usually preferred over `next`.)

(defn my-map [func a-list]
  (when a-list
    (cons (func (first a-list))
          (my-map func (next a-list)))))
;; Difference between next and rest:

(next [:a])
;; => nil
(rest [:a])
;; => ()

(next [])
;; => nil
(rest [])
;; => ()

(next nil)
;; => nil
(rest nil)
;; => ()
See Also

Returns a possibly empty seq of the items after the first. Calls seq on its argument.

Added by boxie

Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil...

Added by boxie

Same as (first (next x))

Added by boxie

Returns the nth rest of coll, coll when n is 0.

Added by didibus

Returns the nth next of coll, (seq coll) when n is 0.

Added by didibus
1 Note
    By , created 13.9 years ago, updated 13.9 years ago
    (next aseq) === (seq (rest aseq))

    When writing lazy sequence functions, you should use rest, not next.