im no beginner but this completely stumped me:
(defn metadata [func]
(-> (class func)
(print-str)
(demunge)
(symbol)
(find-var)
(meta)))
(defn- extract-openapi-meta [handler]
(-> (metadata handler)
(dissoc :arglists :line :column :file :name :ns)))
(defn- attach-handler [handler openapi-meta]
(assoc openapi-meta :handler handler))
(->> (extract-openapi-meta units/get-all)
(partial attach-handler (fn [] (prn "prn")))) ;; => #function[clojure.core/partial] ????units/get-all looks like this:
(defn get-all
{:summary "get all units"
:responses (api/success api/GetUnitsResponse)}
[{:keys [ds] :as _request}]
(res/response (units/get-all-units ds)))
trying to extract the metadata of the request, the bottom most thread imo should return a map, not a function. am i not understanding partial?
(->> A (partial B C)) expands to (partial A B C) which of course evaluates to a function
hmmm, so i must have misunderstood then
i guess because ->> is a thread macro it operates on partial and not on the result of partial
i will just use merge instead, seems more appropriate here. thanks sandman!
> expands to (partial A B C)
with thread-last (used here) would be (partial B C A)😉
> thread macro it operates on partial and not on the result of partial
Unsure what would be the intended result of partial if the output of the partial application is not invoked with any additional args (or none of them). I have the impression you'd expect partial to work here like apply would so I wonder if this - apply - would fit your bill 🙂
I'm also a bit lost on using merge rather than partial, maybe merge does what you expect but merge and partial are two very different beasts.
what i should have done was simply
(->> (edxtract-openapi-meta handler)
(attach-handler handler))merge here would remove the need for attach-handler altogether and instead turn it into
(->> (extrac-openapi-meta handler_)
(merge {:handler handler}))so no need for an additional function
I guess that even ->> could go, I mean, from
(->> A (merge B))
to
(merge B A)
I generally don't need partial at all when working inside -> or ->>:
(->> 10
(partial * 7))
;; => #function[clojure.core/partial/fn--5929]
(->> 10
(* 7))
;; => 70
But if you really want partial, you can add extra parentheses. Then ->> will stitch the argument in the right place.
(->> 10
((partial * 7) #_"->> puts 10 here"))
;; => 70I don't undertstand precisely where you're going with your code, but -> works very nicely with maps and map functions like assoc.
(-> {:your "map"}
(assoc :handler #(prn "prn")))
;; => {:your "map", :handler #function[terra.assetwatch/eval11699/fn--11700]}Does anyone know whether docjure supports streaming from an Excel file (or what else to do if it doesn't)? I need to read a really big one into an sqlite database and it kills the jvm
It's not docjure, but if you want to just read an Excel file and put it in a db, then perhaps Java interop with https://github.com/monitorjbl/excel-streaming-reader might work for you.
Thanks!
tbh, I would just use https://duckdb.org/ for what you're describing rather than do it in Clojure
I was thinking about that too, but if I understand it correctly, this would make it a bit inconvenient to store each row in a json - which is what I am trying to do. I am basically using sqlite as a local document database, which iirc is not what DuckDB is optimized for
Not answering the original post, just adding to the DuckDB suggestion: you could use the Excel extension (https://duckdb.org/docs/stable/core_extensions/excel) to read Excel data and save it to SQLite. We do this at work, use DuckDB as a generic way to read data from multiple sources and save it to SQLite databases.
https://duckdb.org/docs/stable/data/json/json_type - DuckDB has a JSON logical type too, I would be surprised if it failed to handle Excel-sized data