Commits

Meikel Brandmeyer committed abf480c

Implemented LazyMapSeq for lazy maps via genclass

Comments (0)

Files changed (3)

 ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 ; THE SOFTWARE.
 
-(let [classes ["LazyMapEntry"]]
+(let [classes ["LazyMapEntry"
+               "LazyMapSeq"]]
   (doseq cf classes
     (load-file (str "src/de/kotka/lazymap/" cf ".gen.clj"))))

src/de/kotka/lazymap/LazyMapSeq.clj

+;-
+; Copyright 2008 (c) Meikel Brandmeyer.
+; All rights reserved.
+;
+; Permission is hereby granted, free of charge, to any person obtaining a copy
+; of this software and associated documentation files (the "Software"), to deal
+; in the Software without restriction, including without limitation the rights
+; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+; copies of the Software, and to permit persons to whom the Software is
+; furnished to do so, subject to the following conditions:
+;
+; The above copyright notice and this permission notice shall be included in
+; all copies or substantial portions of the Software.
+;
+; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+; THE SOFTWARE.
+
+(clojure/in-ns 'de.kotka.lazymap)
+(clojure/refer 'clojure)
+
+(use    'clojure.contrib.def)
+(import '(clojure.lang Cons)
+        '(de.kotka.lazymap LazyMapSeq LazyMapEntry))
+
+(defn- LazyMapSeq-createSeq
+  [theSeq]
+  (when theSeq
+    (new LazyMapSeq theSeq)))
+
+(defn- LazyMapSeq-init
+  [theSeq]
+  [[] theSeq])
+
+; ISeq
+(defn- LazyMapSeq-first
+  [this]
+  (let [first-val (first (. this theSeq))]
+    (new LazyMapEntry (key first-val) (val first-val))))
+
+(defn- LazyMapSeq-rest
+  [this]
+  (when-let inner-rest (rest (. this theSeq))
+    (new LazyMapSeq inner-rest)))
+
+(defn- LazyMapSeq-cons
+  [this other]
+  (new Cons other this))
+
+; IPersistentCollection
+(defn- LazyMapSeq-count
+  [this]
+  (.. this theSeq (count)))
+
+(defvar- LazyMapSeq-seq identity)
+
+(defn- LazyMapSeq-empty
+  [_]
+  nil)

src/de/kotka/lazymap/LazyMapSeq.gen.clj

+;-
+; Copyright 2008 (c) Meikel Brandmeyer.
+; All rights reserved.
+;
+; Permission is hereby granted, free of charge, to any person obtaining a copy
+; of this software and associated documentation files (the "Software"), to deal
+; in the Software without restriction, including without limitation the rights
+; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+; copies of the Software, and to permit persons to whom the Software is
+; furnished to do so, subject to the following conditions:
+;
+; The above copyright notice and this permission notice shall be included in
+; all copies or substantial portions of the Software.
+;
+; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+; THE SOFTWARE.
+
+(gen-and-save-class "dist" 'de.kotka.lazymap.LazyMapSeq
+  :init         'init
+  :state        'theSeq
+  :implements   [clojure.lang.ISeq]
+  :constructors {[clojure.lang.ISeq] []})