You're viewing version 1.2.0 of next. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (next coll)
Returns a seq of the items after the first. Calls seq on its
argument. If there are no more items, returns nil.

2 Examples top

  • 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)))))
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:55 top

(def
 ^{:arglists '([coll])
   :tag clojure.lang.ISeq
   :doc "Returns a seq of the items after the first. Calls seq on its
  argument.  If there are no more items, returns nil."
   :added "1.0"}  
 next (fn next [x] (. clojure.lang.RT (next x))))
Vars in clojure.core/next: fn

Comments top

1 comment(s) for next.

(next aseq) === (seq (rest aseq))

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

Log in to add a comment.