closeable-map icon indicating copy to clipboard operation
closeable-map copied to clipboard

`close-with` doesn't work on Java objects

Open piotr-yuxuan opened this issue 2 years ago • 4 comments

It uses ::fn meta and as such needs a Clojure object. The implementation should change so that it attach the fn to the map and not the object.

piotr-yuxuan avatar Mar 27 '22 12:03 piotr-yuxuan

I think it does qualify as a bug, but it's quite telling that nobody reported it ^_^ Another explanation is nobody actually tried to use ::fn.

piotr-yuxuan avatar Mar 30 '22 16:03 piotr-yuxuan

Actually ::closeable-map/fn is more for custom close function, for example with reporting and so on. In such case indeed a custom function may be added in the metadata of the containing map. However, closeable-map may be taught to close any object instances by extending the ::closeable-map/close! method.

(import '(clojure.lang Atom))
(defmethod c/close! Atom [x] (reset! x nil))

(import '(clojure.core.async.impl.protocols Channel))
(defmethod c/close! Channel [x] (async/close! x))

This should be added as examples.

piotr-yuxuan avatar Sep 16 '22 11:09 piotr-yuxuan

As long as Java objects are concerned, user can make use of the star pattern, that is to say a closeable* within a closeable-map*. In effect this does register this Java object in the metadata of the container.

piotr-yuxuan avatar Sep 17 '22 08:09 piotr-yuxuan

I'm reluctant to change close-with. Very happy to hear a different opinion about it.

piotr-yuxuan avatar Sep 17 '22 08:09 piotr-yuxuan