Commits

Meikel Brandmeyer committed 017d09b

Added lazy-struct-map and lazy-struct

Comments (0)

Files changed (1)

src/de/kotka/lazymap/lazymap.clj

   is a sorted map."
   [& kvs]
   (make-map sorted-map kvs))
+
+(defmacro lazy-struct-map
+  "<lazy-struct-map> creates a map. The values are not evaluated before their
+  first retrieval. Each value is evaluated at most once. The underlying map
+  is a struct map according to the provided structure s."
+  [s & kvs]
+  (make-map `(fn [& kvs#] (apply struct-map ~s kvs#)) kvs))
+
+(defmacro lazy-struct
+  "<lazy-struct> creates a map. The values are not evaluated before their
+  first retrieval. Each value is evaluated at most once. The underlying map
+  is a struct map according to the provided structure s. As with Clojure's
+  <struct> the values have to appear in the order of the keys in the structure."
+  [s & vs]
+  (let [vs (map (fn [v] `(delay ~v)) vs)]
+    `(new LazyMapClass (struct ~s ~@vs))))