The code makes perfect sense to me, but I'm baffled as to why it doesn't work. I did check that I don't have clojure flycheck-mode on, so that's not the problem.
I have an anonymous function to take any catv and match it, to return a mcatv. this works perfectly all alone. p-cat-tap just returns a flattened tree of keys and vectors.
And I use my verified catv-match function to filter it down to what should be one record and if its not the first one should do. I get the key turn it into a string and return it.
(defn get-mcat-fn [pm cats-key]
(let [mcats (p-cat-tap pm cats-key)]
(fn [catv]
(str (name (ffirst (filter #(catv-match (second %) catv) mcats)))))))
;; here's the test to verify that function works.
(fact "We can get the master category for any product category vector; Lego is [159 81]"
(let [get-mcat (get-mcat-fn pm :master-categories)]
(get-mcat [159 81 2 1]) => "lego"
(get-mcat [159 81 6 5]) => "lego"
(get-mcat [159 81 12]) => "lego"
(get-mcat [159 81]) => "lego"
(get-mcat [156 28 12]) => "tinkertoy"))
;; Just for sanity I tried using this function in the query instead, it works just fine.
(defn foo [pcat]
(first pcat))
(defn p-cats
"return a list of pids and mcats"
([pm pk catdata-key]
(let [prods (p-cat-vectors pm pk)
get-mcat (get-mcat-fn pm catdata-key)]
(<- [?pid ?mcat ]
(prods :> ?pid ?pcatv)
(get-mcat ?pcatv :> ?mcat)))))
;; this is essentially the same as this example which we have all done some variation of an uncountable number of times.
(defn square [x]
(* x x))
(def src [1 2 3 4 5])
(def bar (??<- [!x !squared]
(src !x)
(square !x :> !squared)))