Commits

Meikel Brandmeyer  committed 904e8d8

Extend ASeq via proxy

  • Participants
  • Parent commits 363fd20
  • Branches new

Comments (0)

Files changed (1)

File src/main/clojure/de/kotka/lazymap.clj

     clojure.lang.IMapEntry
     clojure.lang.IPersistentMap
     clojure.lang.IPersistentVector
+    clojure.lang.ASeq
     clojure.lang.ISeq
     clojure.lang.Seqable
     clojure.lang.SeqIterator))
   (val           [_] (force v))
   (getValue      [_] (force v))
   Object
-  (toString      [_] (str \[ k \space (force v) \])))
+  (toString      [_] (str \[ (pr-str k) \space (pr-str (force v)) \])))
 
 (defmethod print-method LazyMapEntry
   [this #^java.io.Writer w]
   ([inner-seq]
    (create-lazy-map-seq inner-seq nil))
   ([inner-seq metadata]
-   (reify
-     ISeq
-     (first
-       [this]
+   (proxy [ASeq] [metadata]
+     ; ISeq
+     (first []
        (let [first-val (first inner-seq)]
          (LazyMapEntry. (key first-val) (val first-val))))
-     (next
-       [this]
+     (next []
        (when-let [inner-rest (next inner-seq)]
          (create-lazy-map-seq inner-rest metadata)))
-     (more  [this]   (lazy-seq (.next this)))
-     (cons  [this o] (create-lazy-map-seq (cons o inner-seq) metadata))
-     ; IPersistentCollection
-     (count [this]   (count inner-seq))
-     (empty [this]   ())
-     (seq   [this]   this))))
+     (more [] (lazy-seq (next this))))))
 
 (declare create-lazy-map)