cognitect / transit-cljs

Transit for ClojureScript
http://transit-format.org
Apache License 2.0
323 stars 20 forks source link

(write) failes when sequence/transducer is passed. #30

Closed kamituel closed 6 years ago

kamituel commented 7 years ago

When using sequence with transducers, transit/write failes with an exception.

Consider:

(def transit-writer
  (transit/writer :json))

(defn transform-map
  [m]
  (assoc m :x 1))

(def data
  [{:a 1} {:a 1}])

(prn "p1. Regular map")
(prn (transit/write transit-writer (map transform-map data)))

(prn "p2. Transducer")
(prn (transit/write transit-writer (sequence (map transform-map) data)))

(prn "p3. Done")

Regular map (p1) will print just fine, however, p2 fails with an exception:

Uncaught Error: Cannot write 
    writer.maybeQuoted @ writer.js:464
    writer.marshalTop @ writer.js:471
    writer.Writer.write @ writer.js:501
    cognitect$transit$write @ transit.cljs?rel=1478250205512:256
    (anonymous function) @ core.cljs?rel=1478251095137:53

Because of that, obviously p3 never gets printed.

Latest transit: 0.8.239. I'm able to reproduce it on ClojureScript 1.9.293 (latest) as well as 1.9.76 (haven't tried other versions).

kamituel commented 7 years ago

For completness:

;; Breaks too.
(prn (transit/write transit-writer (doall (sequence (map transform-map) data))))

;; Works fine.
(prn (transit/write transit-writer (vec (sequence (map transform-map) data))))

;; Works fine.
(prn (transit/write transit-writer (apply list (sequence (map transform-map) data))))
swannodette commented 6 years ago

I can't replicate this with the latest ClojureScript