Clojure: rest vs. next

前端 未结 5 2084
执笔经年
执笔经年 2020-12-13 08:03

I\'m having a hard time understanding the difference between rest and next in Clojure. The official site\'s page on laziness indicates that the pre

5条回答
  •  臣服心动
    2020-12-13 08:52

    next is like (seq (rest ...)).

    rest will return the remaining piece of a sequence. If that piece of the sequence has not yet been realized, rest doesn't force it. It won't even tell you if there are more elements left in the sequence.

    next does the same thing but then forces at least one element of the sequence to be realized. So if next returns nil, you know there aren't any more elements left in the sequence.

提交回复
热议问题