No, itโs something weirder than that:
(prn (first (errors-from (:new (second errors)))))
{:unexpected :except, :expected #{":only" ":rename" ":exclude" :eof}}
=> nil
(prn {:unexpected :except, :expected #{":only" ":rename" ":exclude" :eof}})
{:unexpected :except, :expected #{":only" ":rename" ":exclude" :eof}}
=> nil
(contains? common-errors (first (errors-from (:new (second errors)))))
=> false
(= {:unexpected :except, :expected #{":only" ":rename" ":exclude" :eof}} (first (errors-from (:new (second errors)))))
=> false
Arg, one of those keywords is an AST class which prints as the actual keyword:
(->> (tree-seq #(or (sequential? %) (map? %)) identity (first (errors-from (:new (second errors)))))
(mapv #(vector % (class %))))
=>
[[{:unexpected :except, :expected #{":only" ":rename" ":exclude" :eof}} clojure.lang.PersistentArrayMap]
[[:unexpected :except] clojure.lang.MapEntry]
[:unexpected clojure.lang.Keyword]
[:except cursive.psi.impl.ClEditorKeyword]
[[:expected #{":only" ":rename" ":exclude" :eof}] clojure.lang.MapEntry]
[:expected clojure.lang.Keyword]
[#{":only" ":rename" ":exclude" :eof} clojure.lang.PersistentHashSet]]
That would do it ๐
They donโt normally do that but I defined a print-method for them for some testing a while back.
it was tricky printing like I thought!
Indeed it was!
Are there any tools/libraries that help moving/renaming namespaces in bulk, including references? I found clojure.tools.namespace.move
but I'm wondering if anything better has come along since, since it just does a naive regex replace
I heard that Cursive was great for this sort of thing. I'm not a cursive user myself, but it maybe worth taking a look at how it is handling such refactors.
use cursive for it, as mentioned above
Clj-refactor was able to do it too - bot sure if thatโs using clojure.tools
A little something about protocols: My first question is: is this the correct way to type-hint the return type of a fn in a protocol?:
(defprotocol Foo
(^String foo [this]))
;; foo should be typehinted to return a String
This seems correct to me, but I'm not familiar nor comfortable with type-hints.
Second question. Given a multi-arity protocol function, is this the correct way to type-hint it?
(defprotocol Bar
(^String bar
[this]
[this that]))
Follow up question (which I'm not sure is very sensical, is there a way to have a different return type on these two fns?
Third or fourth question, depending, when I look at the macroexpand of the Foo protocol, there's a lot going on, but I find this bit interesting:
(gen-interface
:name
typehints.protocols.Foo
:methods
([foo [] Object]))
So even though I've type-hinted foo
to return a String
, it seems like the interface method is generated with a return type of Object
?I have to go but I may write more in a bit when I'm back, hope that helps at least
It does, thanks!
Hey folks, how can I use interleave
such that lists of different lengths zip with nil? e.g. (partition 2 (interleave [1 2 3] [4 5]))
=> ((1 4) (2 5) (3 nil))
oops, fixed
Hello folks ๐ Does anyone happen to have worked with .HAR files in Clojure? is there any libraries ready to use? I haven't found any
I wrote my one version of interleave)
(defn exhaustive-interleave
"Same as clojure.core/interleave but continue until any input is not empty"
{:added "1.0"
:static true}
([] ())
([c1] (lazy-seq c1))
([c1 c2]
(lazy-seq
(let [s1 (seq c1) s2 (seq c2)]
(when (or s1 s2)
(cons (first s1) (cons (first s2)
(exhaustive-interleave (rest s1) (rest s2))))))))
([c1 c2 & colls]
(lazy-seq
(let [ss (map seq (conj colls c2 c1))]
(when (some identity ss)
(concat (map first ss) (apply exhaustive-interleave (map rest ss))))))))
Do you mean this one? https://en.wikipedia.org/wiki/HAR_(file_format)
yes
technically it's just a JSON ๐ but i wonder if there's anything beyond only parsing it as JSON
When I read the spec correctly, it is json based. If thatโs the case, you could process with e.g. cheshire
Ah, now I get you. What things beyond parsing do you have in mind?
๐ค thanks
here's a one-liner that does the zip: (defn zip [[a & as] [b & bs]] (lazy-seq (cons [a b] (when (some seq [as bs]) (zip as bs)))))
Honestly i don't know, but if anyone made anything i'd like to check it out before reinventing the wheel
maybe i'll find out while building my solution ๐
(concat shorter-end (repeat nil))
then interleave as normal
Do you miss Leiningen templates when using cli-tools?
I've been using Clojure CLI this year after about 9 years of using Leiningen and it's templates. At first I missed a few templates until I realised I could just create a deps.edn file and copy over the dependencies. I don't miss using Leiningen plugins. They were useful when I started learning, but did hide away details of how things worked. I'm now creating my own templates for Clojure CLI tools, it seems very straightforward when using clj-new template, a template to create templates.
If you do full-stack development do you make it one big project (backend+frontend) or separate them?
Unless there is reason to create a monolithic full stack app, I will separate front from back. This encourages development of a good API around the backend and allows greater flexibility in the architecture. It's also easier to scale separate parts for their own specific needs
I get your point, thanks
you can still use leiningen templates with the cli tools with clj-new
@gr.evocatus https://github.com/seancorfield/clj-new is what Alex is referring to. See a list of CLI tools here https://github.com/clojure/tools.deps.alpha/wiki/Tools
(cond-> {:foo "foo"}
true (assoc :bar "bar")
true (update :foo str "123")
some-bool? (assoc :baz "baz"))
How would I go about making this a bit nicer? Specifically avoid the true
s for the default operations.mix ->
and cond->
(-> {:foo "foo"}
(assoc :bar "bar")
(update :foo str "123")
(cond-> some-bool? (assoc :baz "baz"))
Does that play nicely with multiple conditions? e.g:
(cond-> {:foo "foo"}
true (assoc :bar "bar")
true (update :foo str "123")
some-bool? (assoc :baz "baz")
some-other-bool? (assoc :quux "quux"))
I guess I'd end up with:
(-> {:foo "foo"}
(assoc :bar "bar")
(update :foo str "123")
(cond-> some-bool? (assoc :baz "baz")
some-other-bool? (assoc :quux "quux")))
Looks good to me! Thanks @ghadi
np. @curlyfry a little of that can go a long way
Could also do this:
(cond-> {:foo "foo123" :bar "bar"}
some-bool? (assoc :baz "baz"))
The things that are always true
can just be included in the initialization step fo the map.Without more context on how dynamic you need it to be, Iโm not sure. But the general principle holds that anything in a static true
section should be moveable into the initial map.
@curlyfry alternatively merge
:
(merge {:foo "foo"}
{:bar "bar"
:foo "123"}
(when some-bool?
{:baz "baz"})
(when some-other-bool?
{:quux "quux"}))
Requires that you explicitly get update
values, but itโs extremely straightforward:
(let [{foo :foo} mah-map]
(merge {:bar "bar"
:foo (str foo "123")}
(when some-bool?
{:baz "baz"})
(when some-other-bool?
{:quux "quux"})))