This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-21
Channels
- # aleph (2)
- # beginners (22)
- # boot (7)
- # chestnut (8)
- # cider (4)
- # clara (3)
- # cljs-dev (3)
- # cljs-experience (19)
- # clojure (69)
- # clojure-italy (8)
- # clojure-nl (1)
- # clojure-spec (11)
- # clojure-uk (17)
- # clojurescript (77)
- # cursive (22)
- # datomic (14)
- # events (1)
- # fulcro (78)
- # hoplon (51)
- # jobs (3)
- # keechma (1)
- # lambdaisland (1)
- # lumo (30)
- # off-topic (42)
- # om (22)
- # onyx (5)
- # parinfer (4)
- # portkey (1)
- # re-frame (15)
- # reagent (2)
- # ring (4)
- # spacemacs (1)
- # specter (23)
- # testing (1)
- # unrepl (60)
- # yada (8)
@qqq You probably canโt do it with nil, but check out merge-with
, it accepts a function that governs the merge
Is there anything more fun than building interpreters in Lisp? Nope. I don't think there is https://github.com/cddr/ksml
Returns a seq on the collection. If the collection is
empty, returns nil.
So you could do
(or (-> arg somefn seq) (error handling))
What permissive license is most suitable for clojure libs? Is it affected by clojure itself using EPL?
@leira might as well use if-let
with a seq
then:
(if-let [coll (->> [1 3] (filter even?) seq)]
coll
"error")
=> "error"
(if-let [coll (->> [1 2 3] (filter even?) seq)]
coll
"error")
=> (2)
but that requires not forgetting seq
, which, when present, is not intuitively obvious why is there (unless you really used to it, or use it a lot). So I prefer:
(let [coll (->> [1 2 3] (filter even?))]
(if (empty? coll)
"error"
coll))
the only difference from seq
โ is not-empty
preserves collection type, but you still need to wrap it in if
, etc (in original question context).
that's not the only difference
hm yes it is
If you are writing portable code, (if (seq [1]) 1 2)
is currently slightly faster in ClojureScript than (if (not-empty [1]) 1 2)
, as it avoids a checked if
.
mast-session.core> (source not-empty)
(defn not-empty
"If coll is empty, returns nil, else coll"
{:added "1.0"
:static true}
[coll] (when (seq coll) coll))
nil
there's a when statement in there which is doing the same check you're doing outside. It avoids doing this conditional twice in a row@hyankov Elaboration on it is here http://blog.fikesfarm.com/posts/2015-12-04-boolean-type-hints-in-clojurescript.html
In short, ClojureScript knows to omit a call to cljs.core.truth_
for constructs that produce seqs.
got a question regarding state management libraries like component
and code structure. If you have web request handers that depend on a stateful thing like a DB connection do you define a component that depends on the DB component? The problem with that is that code reloading no longer works because the system will have an instance of my handers with the DB dependency injected. How do you guys usually use state management libraries?
Can't speak for "usually", but I've used ring middleware that injects the system into the request map, and then handlers can access whatever components they need from that. It's worked fine with code reloading, provided your systems sets up component dependencies like http-server <- app <- (db, etc) where "<-" is "depends on".
@akiroz the right way to use component with a handler is to ensure that the http server itself is restarted, using the new components, when you do a restart
(imho)
that is, if I have an http server, and am using component, I start the server from inside a component
(and shut it down when the component shuts down, of course)
Hmm... ok. With multiple handler fns I imagine I'd have a component that returns a map with 1 key per handler fn?
compojure routes and handlers are basically the same thing, and you can't route without also handling
Ahh, alright. I'm not using compojure but I plan on having all my routes on one place anyway so I guess it's ok
I can use it to map uris to keywords, and then have the http component lookup this keywords in itself, and have component assoc the right handlers under the right keywords in the http component
I am trying to use funcool/jdbc, to create server side cursors with oracle database, throws this error: SQLSyntaxErrorException ORA-00933: SQL command not properly ended
reference from this link: http://funcool.github.io/clojure.jdbc/latest/#advanced-usage
can I get some help remembering the name of a clojure library out there that does pretty printing of clojure source code? Not fipp, not clj-fmt is there another one?
or actually, does anyone know of a clojure/cljs pretty printer that can align keys and values in maps with so that every value in the map starts on the same column?
@adamfrey zprint
to the first question, not sure about the second
I'm accessing a dynamic binding, which is uninitialized. i'd like to test if it is uninitialized or not..
bound?
@tbaldridge that's where I've started, but it throws an exaception
`(bound? ring.middleware.anti-forgery/anti-forgery-token) `ClassCastException clojure.lang.Var$Unbound cannot be cast to clojure.lang.Var clojure.core/bound?/fn--5496 (core.clj:5307)
you have to call it with a var, if you call it that way it will try to deref the var
(bound? #'myvar)
@tbaldridge ah damn you are right! thanks ๐