ClojureDocs

导航

命名空间

nthnext

clojure.core

自 1.0 起可用 (源代码)
  • (nthnext coll n)
Returns the nth next of coll, (seq coll) when n is 0.
2 Examples
(nthnext (range 10) 3)
;;=> (3 4 5 6 7 8 9)

(nthnext [] 3)
;;=> nil

(nthnext [1 2 3 4 5 6 7] 4)
;;=> (5 6 7)

;; drop is also similar, but different 
(nthnext (range 10) 5)   ;;=> (5 6 7 8 9)
(drop    5 (range 10))   ;;=> (5 6 7 8 9)

;; here is a case where the results differ
(nthnext [] 3)  ;;=> nil
(drop    3 [])  ;;=> ()   ; a lazy sequence
See Also

Returns the value at the index. get returns nil if index out of bounds, nth throws an exception un...

Added by Havvy

Returns a lazy sequence of all but the first n items in coll. Returns a stateful transducer when n...

Added by Havvy

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

Added by TimMc
1 Note
    By , created 13.9 years ago, updated 13.9 years ago

    nthnext is similar to drop. But nthnext is eager, while drop is lazy.

    Also parameters are in opposite order.