ilyo
ilyo

Reputation: 36391

Trying to use threading macros and getting error

This is my first attempt at using the thread-first macro My goal is to put the vector through map and then filter

(-> [1 2 3 4 5 6 7 8]
    (filter (fn [x] (<= x 3)))
    (map (fn [x] (* 10 x))))

I am getting

   Error: function (x){return (10 * x);
}is not ISeqable
    at Error (<anonymous>)
    at cljs.core.seq 

What does it mean?

Upvotes: 2

Views: 95

Answers (1)

cfrick
cfrick

Reputation: 37008

You would have to use ->>. The doc:

Threads the expr through the forms. Inserts x as the last item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the last item in second form, etc.

Your threaded calls there are filter and map which both take the list as second param. -> puts them as first parameter. So your code there would look like this: (filter [1 2 3 4 5 6 7 8] (fn [x] (<= x 3))), your function is no seq, hence the error.

Upvotes: 6

Related Questions