Clojure: rest vs. next

前端 未结 5 2088
执笔经年
执笔经年 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:51

    As the page you linked described, next is stricter than (the new behaviour of) rest because it needs to evaluate the structure of the lazy cons to know whether to return nil or a seq.

    rest on the other hand always returns a seq, so nothing needs to be evaluated until you actually use the result of rest. In other words, rest is more lazy than next.

提交回复
热议问题