[英]is there a way of getting all the keys of the watches in clojure
如果有一个原子:
(def a (atom {}))
配有以下手表
(add-watch a :watcher println)
(add-watch a :watcher2 println)
有这样的功能吗?
(get-watches a)
;; => [:watcher :watcher2]
(atom {})
创建一个clojure.lang.Atom
类型的对象,它扩展了实现clojure.lang.IRef接口的抽象类clojure.lang.ARef 。 IREF声明方法getWatches是在实施阿里夫 。
这是解决方案:
(def a (atom {}))
(add-watch a :watcher println)
(println (-> a .getWatches keys))
很奇怪clojure.core
没有get-watches
。 镜像add-watch
实现我们得到:
(defn get-watches
"Returns list of keys corresponding to watchers of the reference."
[^clojure.lang.IRef reference]
(keys (.getWatches reference)))
(:watches (bean a))
要么
(keys (:watches (bean a)))
Ivan对JVM上的Clojure很有帮助。 以下是您在ClojureScript中的使用方法:
(keys (.-watches a))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.