尝试使用线程宏并出现错误

Trying to use threading macros and getting error

这是我第一次尝试使用线程优先宏 我的目标是将向量通过 map 然后 filter

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

我得到

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

这是什么意思?

您将不得不使用 ->>。文档:

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.

您的线程调用有 filtermap,它们都将列表作为第二个参数。 -> 将它们作为第一个参数。所以你的代码看起来像这样:(filter [1 2 3 4 5 6 7 8] (fn [x] (<= x 3))),你的函数没有序列,因此错误。