From 5983eb04026d27615b413c6d7f7f67b5aff03255 Mon Sep 17 00:00:00 2001 From: Joost Diepenmaat Date: Tue, 15 Mar 2011 15:31:21 +0100 Subject: [PATCH 1/2] make blobstore/list-blobs actually lazy --- blobstore/src/main/clojure/org/jclouds/blobstore.clj | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/blobstore/src/main/clojure/org/jclouds/blobstore.clj b/blobstore/src/main/clojure/org/jclouds/blobstore.clj index 0cc67a8144..a410be3cb8 100644 --- a/blobstore/src/main/clojure/org/jclouds/blobstore.clj +++ b/blobstore/src/main/clojure/org/jclouds/blobstore.clj @@ -151,10 +151,17 @@ Options can also be specified for extension modules (list-blobs-chunks container prefix blobstore (.getNextMarker chunk))))))) +(defn- concat-elements + "Make a lazy concatenation of the lazy sequences contained in coll. Lazily evaluates coll. +Note: (apply concat coll) or (lazy-cat coll) are not lazy wrt coll itself." + [coll] + (if-let [s (seq coll)] + (lazy-seq (concat (first s) (concat-elements (next s)))))) + (defn list-blobs "Returns a lazy seq of all blobs in the given container." ([container prefix #^BlobStore blobstore] - (apply concat (list-blobs-chunks container prefix blobstore :start)))) + (concat-elements (list-blobs-chunks container prefix blobstore :start)))) (defn locations "Retrieve the available container locations for the blobstore context." From 23e988ef5a6a314a1e076bbaa52336703ae0bc73 Mon Sep 17 00:00:00 2001 From: Joost Diepenmaat Date: Tue, 15 Mar 2011 15:49:00 +0100 Subject: [PATCH 2/2] make prefix optional for blobstore/list-blobs --- blobstore/src/main/clojure/org/jclouds/blobstore.clj | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/blobstore/src/main/clojure/org/jclouds/blobstore.clj b/blobstore/src/main/clojure/org/jclouds/blobstore.clj index a410be3cb8..d6b9283086 100644 --- a/blobstore/src/main/clojure/org/jclouds/blobstore.clj +++ b/blobstore/src/main/clojure/org/jclouds/blobstore.clj @@ -141,8 +141,10 @@ Options can also be specified for extension modules (defn- list-blobs-chunk [container prefix #^BlobStore blobstore & [marker]] (apply list-container blobstore container - :in-directory prefix (when (string? marker) - [:after-marker marker]))) + (concat (when prefix + [:in-directory prefix]) + (when (string? marker) + [:after-marker marker])))) (defn- list-blobs-chunks [container prefix #^BlobStore blobstore marker] (when marker @@ -161,7 +163,9 @@ Note: (apply concat coll) or (lazy-cat coll) are not lazy wrt coll itself." (defn list-blobs "Returns a lazy seq of all blobs in the given container." ([container prefix #^BlobStore blobstore] - (concat-elements (list-blobs-chunks container prefix blobstore :start)))) + (concat-elements (list-blobs-chunks container prefix blobstore :start))) + ([container #^BlobStore blobstore] + (list-blobs container nil blobstore))) (defn locations "Retrieve the available container locations for the blobstore context."