bir atom saatler tüm anahtarları almanın bir yolu var mı?olsaydı Clojure
(get-watches a)
;; => [:watcher :watcher2]
bir atom saatler tüm anahtarları almanın bir yolu var mı?olsaydı Clojure
(get-watches a)
;; => [:watcher :watcher2]
(atom {})
clojure.lang.IRef arabirim uygulayan soyut sınıf clojure.lang.ARef uzanan tip clojure.lang.Atom
bir nesne oluşturur. IRef, ARef'da uygulanan getWatches yöntemini bildirir.
(def a (atom {}))
(add-watch a :watcher println)
(println (-> a .getWatches keys))
O clojure.core
get-watches
yok garip:
İşte çözüm. Yansıtma add-watch
uygulama elde ederiz:
(defn get-watches
"Returns list of keys corresponding to watchers of the reference."
[^clojure.lang.IRef reference]
(keys (.getWatches reference)))
(:watches (bean a))
veya
(keys (:watches (bean a)))
Ivan'ın cevabı JVM üzerinde Clojure için mükemmeldir. ClojureScript'te şu şekilde yapın: