There's something I must be missing about the threading macro in Clojure.
I have a map with values that are maps as well, and I'd like to a lookup in the result of another lookup. Let the map be a simple {:a {:b 2}} -- first I want to look up the key :a, that's going to yield {:b 2}, then look up b, the result is 2. The key for the second lookup needs to be a result of a function.
((fn [x] (get x :b)) ({:a {:b 2} } :a ))
=> 2
Ok, let's make it more readable with the threading macro.
(-> {:a {:b 2} } :a (fn [x] (get x :b)))
I.e. apply :a as a function on the map then apply another function. Well, this doesn't work:
CompilerException java.lang.IllegalArgumentException: Parameter declaration :a should be a vector
Oddly enough, if the anonymous function is extracted to a named one, then it works fine:
(defn f [x] (get x :b))
(-> {:a {:b 2} } :a f)
=> 2
Or even:
(def f (fn [x] (get x :b)) )
(-> {:a {:b 2} } :a f)
=> 2
Why is there a difference between how named and anonymous functions work?