clj-commons / potemkin

some ideas which are almost good
572 stars 53 forks source link

return a clojure.lang.MapEntry, but only if the key is found in the map #13

Closed joegallo closed 10 years ago

joegallo commented 10 years ago

I found two slight differences in behavior for clojure's maps versus for maps created with AbstractMap.

First, clojure's maps return a clojure.lang.MapEntry, whereas AbstractMap returns a reified class that's pretty similar to what MapEntry is, which isn't a huge deal, but since there's no toString for it, it ends up being weird at the repl. I solved that here by just returning a clojure.lang.MapEntry, but another solution would be to just define a toString.

Second, if the key doesn't exist in a map, then find is supposed to return nil, but the definition of entryAt that AbstractMap provides will always return a MapEntry, even if the key wasn't found. I fixed that by using the ::not-found magic value (which is a little lame, but anything more correct than that would have been a bigger diff, and I thought I'd keep this small).

ztellman commented 10 years ago

Looks good, thanks.