Thanks
Is there a way to get the name out of a fn
? I.e. one defined with (fn name [args] …)
not easily, no (you can demunge the class name of the function)
@max.giraldo A very similar question was also asked on the Clojure mailing list recently, perhaps there may be some useful information to be discovered there too? <https://groups.google.com/g/clojure/c/Zpc2yaZDxqA>
it would help to know why you want to do this. most of the time, you should not want to do this. (but there are some good reasons in tooling etc)
spec does this
Hm, I was hoping to get access to the actual symbol, not just the string representation. My actual goal is to attach metadata to the fns created by defmethod
that can be retrieved via (methods )
, I’d hoped that I’d be able to do that like so:
(defmethod multi :x ^{:a :b} name [args] ...)
But if the symbol can’t be retrieved that’s a dead endIs there another way to get metadata onto the fn without making my own version of defmethod
?
(defmulti foo :type)
(.addMethod ^clojure.lang.MultiFn foo :default (with-meta (fn [] :default)
{:this-is :a-default}))
(map meta (map val (methods foo)))
=> ({:this-is :a-default})
@max.r.rothman use interop 🙂
I think you're abusing multimethods trying to do this
if you want to report information per method, make another multimethod!
lean on the open invocation
Following up on Alex's comment, an adage that has served me well: "Only invent something new if you have to."
I wonder if it's possible to use https://github.com/juxt/pack.alpha#docker-image to build a docker image for a project that uses lein for dependency management and for building uberjars. I've looked at the readme and I'm not sure if I should add pack.alpha to my dependencies? I'm not cont certain how to use it
pack.alpha is for deps.edn projects only so with Leiningen, Lukasz's example would be enough
The https://github.com/GoogleContainerTools/jib library that the docker support of pack.alpha uses is quite interesting, in that it doesn't require docker daemon for building the image and successive builds, and also pushes to a remote registry are quite fast because dependencies are cached into separate layer.
That said, with deps.edn, the same could be done by arranging copying of dependencies separately, say in a RUN
command (so you get a layer out of this), and also packing source/AOT resources separately. Just that docker daemon is needed for that, but you probably have other uses for running commands at build time also 🙂
The are things like kaniko for building image without docker daemon too. But for the simple case, Lukasz's example very much enough :)
Not sure if you need an extra tool for that - a dockerfile for getting dependencies, building an uberjar and creating final image just with the Java runtime and your application is not that complicated (based on my experience)
@franklineapiyo is what your doing open source? If i could glance at it, i might be able to offer some advice having used pack.alpha before. Keep in mind that Lein can make use of a deps.edn file. I haven't done this before. https://github.com/RickMoynihan/lein-tools-deps But as I believe Lukasz is saying, you might not really need lein.
Oh, I meant the opposite - you just need Lein, everything else happens in Docker, example based on our internal Dockerfiles: https://gist.github.com/lukaszkorecki/ca2786d0da26e653a9c80e54752f78dc (There's more to it than that, but this should work out of the box )