I think the argument has been that although nth might work on any seq,
it would be very inefficient for some collections (lists, maps, etc.)
compared to vectors where nth operates in constant time.
Do you have a use case in mind? It seems odd to me to try to use nth
on a map, where the order isn't meaningful and may not be stable. I
think in drewr's case it turned out he was actually trying to
destructure a MapEntry, not a map. Destructuring (and nth) work fine
for map entries:
user=> (def entry (find {:a 1} :a))
#'user/entry
user=> (nth entry 0)
:a
user=> (let [[k v] entry] (str "Key is " k ", val is " v))
"Key is :a, val is 1"
--Chouser
I think the argument has been that although nth might work on any seq,
On Fri, Aug 22, 2008 at 3:59 PM, Shawn Hoover <shawn....@gmail.com> wrote:
> While thinking about drewr's map destructuring question on IRC, I found that
> nth doesn't work on maps. Other group emails state this fact but I can't
> find that it's by design. (doc nth) says it works on sequences. Maps do work
> with seq, first, rest, etc, so it seems like nth should accept maps.
it would be very inefficient for some collections (lists, maps, etc.)
compared to vectors where nth operates in constant time.
Do you have a use case in mind? It seems odd to me to try to use nth
on a map, where the order isn't meaningful and may not be stable.