There's something missing in the macro with threads in Clojure.
I have a map with values, which are also maps, and I would like to find it as a result of another search. Let the mapping be simple {:a {:b 2}} - first I want to find the key :a , which will give {:b 2} , then look at b , the result will be 2 . The key for the second search should be the result of the function.
((fn [x] (get x :b)) ({:a {:b 2} } :a )) => 2
Ok, make it more readable with a stream macro.
(-> {:a {:b 2} } :a (fn [x] (get x :b)))
those. apply :a as a function on the map, then apply another function. Well, this does not work: CompilerException java.lang.IllegalArgumentException: Parameter declaration :a should be a vector
Oddly enough, if an anonymous function is retrieved to a named one, then it works fine:
(defn f [x] (get x :b)) (-> {:a {:b 2} } :af) => 2
Or even:
(def f (fn [x] (get x :b)) ) (-> {:a {:b 2} } :af) => 2
Why is there a difference between how named and anonymous functions work?
macros anonymous-function clojure
Mate varga
source share