Skip to content

Instantly share code, notes, and snippets.

@jhn

jhn/t.clj Secret

Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhn/bc797e8a107609425919 to your computer and use it in GitHub Desktop.
Save jhn/bc797e8a107609425919 to your computer and use it in GitHub Desktop.
LazySeq into #{}
(def tat (atom #{}))
(class (products)) ; => clojure.lang.LazySeq
; works
(defn go []
(let [ps (products)]
(when-not (empty? ps)
(reset! tat (into #{} ps))))
(go) ; resets tat correctly on every invocation
; crashes
(defn go []
(let [ps (products)
diff (set/difference ps @tat)]
(when-not (empty? ps)
(reset! tat (into #{} ps))))
(go) ; ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IPersistentSet clojure.core/disj (core.clj:1454)
(def tat (atom #{}))
(class (products)) ; => clojure.lang.LazySeq
(defn go []
(let [ps (products)
diff (set/difference ps @tat)]
(when-not (empty? ps)
(reset! tat (into #{} ps))))
(go) ; works fine!
(go) ; ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IPersistentSet clojure.core/disj (core.clj:1454)
(go) ; ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IPersistentSet clojure.core/disj (core.clj:1454)
(def tat (atom #{}))
(go) ; works fine!
(go) ; ClassCastException clojure.lang.LazySeq cannot be cast to clojure.lang.IPersistentSet clojure.core/disj (core.clj:1454)
; etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment