1

I would like to create a lazy-seq containing another lazy-seq using clojure.

The data structure that I aready have is a lazy-seq of map and it looks like this:

({:a 1 :b 1})

Now I would like to put that lazy-seq into another one so that the result would be a lazy-seq of a lazy-seq of map:

(({:a 1 :b 1}))

Does anyone know how to do this? Any help would be appreciated

Regards,

2
  • Can you add a few steps to your final expected output, i cant fully understand the sense of your requirements Commented Nov 15, 2013 at 13:26
  • Hi tangrammer. Thx for your replying. I actually want no output at this point. The point is that there is another function with takes as argument a seq of seq of maps, that` s to say (({:a 1 :b 1})). Commented Nov 15, 2013 at 13:31

2 Answers 2

1

Here is an example of creating a list containing a list of maps:

=> (list (list {:a 1 :b 1}))
(({:a 1, :b 1}))

It's not lazy, but you can make both lists lazy with lazy-seq macro:

=> (lazy-seq (list (lazy-seq (list {:a 1 :b 1}))))

or the same code with -> macro:

=> (-> {:a 1 :b 1} list lazy-seq list lazy-seq)

Actually, if you'll replace lists here with vectors you'll get the same result:

=> (lazy-seq [(lazy-seq [{:a 1 :b 1}])])
(({:a 1, :b 1}))

I'm not sure what you're trying to do and why do you want both lists to be lazy. So, provide better explanation if you want further help.

Sign up to request clarification or add additional context in comments.

1 Comment

Thx Leonid. And you were right that there is no need to make both lists lazy. It was an error in my reasoning ;-)
0

generally, there's nothing special about having a lazy-seq containing many lazy-seq's, so i dont understand exactly what it is you are really after.

you could always do

(map list '({:a 1 :b 1}))   ;; gives (({:a 1, :b 1}))

we can even verify that it maintains laziness:

(def a
  (concat
   (take 5 (repeat {:a 1 :b 2}))
   (lazy-seq
    (throw (Exception. "too eager")))))

(println (take 5 (map list a))) ;; works fine
(println (take 6 (map list a))) ;; throws an exception

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.