next

added
1.0

ns
clojure.core

type
function

(next coll)

Returns a seq of the items after the first. Calls seq on its
argument.  If there are no more items, returns nil.

                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)
;; => ()