This page is not created by, affiliated with, or supported by Slack Technologies, Inc.


An interesting extra case in nth, right before it resorts to linear-traversal-nth, would be to check if it supports IReduce and to get the n th value without forcing the collection being held by coll to be realized. I think this is really only useful as a memory-perf optimization when using some of the newer directly reducible sequence generators on master. To do that would probably look like something along these lines:

(implements? IReduce coll)
      (if (neg? n)
        (throw (js/Error. "Index out of bounds"))
        (transduce (drop n)
          (fn ([z] (if (= z ::ioob) (throw (js/Error. "Index out of bounds")) z))
              ([_ x] (reduced x)))
          ::ioob coll))