Details
-
Type:
Defect
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
Here's the definition of `cons` for caches:
clojure.lang.IPersistentCollection
(cons _# elem#
(clojure.core/cons ~base-field elem#))
This seems wrong to me. Note first that the arguments to `clojure.core/cons` are in the wrong order. As a result, the result of (for example) conj is incorrect. Consider this:
user=> (def starts-with-a (cache/fifo-cache-factory {:a 1} :threshold 3))
#'user/starts-with-a
user=> starts-with-a
{:a 1}
user=> (conj starts-with-a [:c 3])
({:a 1} :c 3)
Even if the argument order was correct, the result would still be a sequence rather than the type of the base field. I think you want something more like
clojure.lang.IPersistentCollection
(cons this# elem#
(apply assoc this# elem#))
After all, this particular collection is an IPersistentMap, so its `conj` and `into` behavior should be the same as other objects for which `map?` is true.