Create a map entry in Clojure

Viewed 2496

What is the built-in Clojure way (if any), to create a single map entry?

In other words, I would like something like (map-entry key value). In other words, the result should be more or less equivalent to (first {key value}).

Remarks:

  • Of course, I already tried googling, and only found map-entry? However, this document has no linked resources.
  • I know that (first {1 2}) returns [1 2], which seems a vector. However:
(class (first {1 2}))
; --> clojure.lang.MapEntry
(class [1 2])
; --> clojure.lang.PersistentVector
  • I checked in the source code, and I'm aware that both MapEntry and PersistentVector extend APersistentVector (so MapEntry is more-or-less also a vector). However, the question is still, whether I can create a MapEntry instance from Clojure code.
  • Last, but not least: "no, there is no built in way to do that in Clojure" is also a valid answer (which I strongly suspect is the case, just want to make sure that I did not accidentally miss something).
3 Answers
Related