1

I am trying to retrieve data from a DB. The data is coming back in a lazy sequence. I can peek at the data in repl and it looks like this:

({:foo value1, :bar value2})

How can I get at this data? preferably, how can I turn it into a map? I've tried:

(doall sequence (get sequence :foo)) Which just returns nil. And

(apply hash-map user-settings)

which returns

llegalArgumentException No value supplied for key: {:foo value1, :bar value2} clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)

I am very new to clojure and have been stuck on this for way too long. Thanks in advance.

1
  • 1
    The data is coming back in a lazy sequence - A lazy sequence of what? You have a sequence of one record represented by map {:foo value1, :bar value2}. Can you have several such records? How do you want to combine them into a map/table? Is there a key within the record you want to index them by? Commented Dec 16, 2016 at 19:03

2 Answers 2

3

You already have a map, it just happens to be the only item in your list.

(def data (first '({:foo 123 :bar 456})))

(:foo data)  ; => 123
Sign up to request clarification or add additional context in comments.

Comments

2

Sometimes when you want to print lazy seq to see your data use into. For example if you want to see contents of a lazy vector use (into [] your-lazy-vector) or (into {} your-lazy-map).

You can do this uncool conversion within a println function or in a let. However, I recommend removing this kind of debugging aid before release or pull-request.

Lazy sequences are great, most of the time.

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.