This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-15
Channels
- # architecture (2)
- # beginners (16)
- # boot (2)
- # cider (4)
- # clara (6)
- # cljs-dev (78)
- # cljsrn (3)
- # clojure (158)
- # clojure-austin (1)
- # clojure-belgium (1)
- # clojure-dusseldorf (19)
- # clojure-italy (8)
- # clojure-russia (3)
- # clojure-spec (77)
- # clojure-uk (61)
- # clojurescript (341)
- # cursive (9)
- # data-science (12)
- # datomic (18)
- # emacs (9)
- # fulcro (109)
- # hoplon (10)
- # juxt (2)
- # leiningen (2)
- # lumo (31)
- # off-topic (1)
- # om (4)
- # onyx (40)
- # parinfer (17)
- # re-frame (36)
- # reagent (19)
- # spacemacs (10)
- # vim (60)
- # yada (20)
Getting to lein repl
on rPi Java 8 is 28s +/- 0.5s measuring error. Getting to clojure.main repl is about 5 seconds.
lein's nREPL session is noticeably laggy
Hey, Clojurians. Is anyone else using Walmart Labs' Lacinia GraphQL library? I'm using it but I'm having trouble understanding how the resolved-values
third parameter of a resolver function signature is supposed to work. Can someone lend me a hand?
I'm referring to this: http://lacinia.readthedocs.io/en/latest/resolve/overview.html#container-s-resolved-value
I don't really see any good reason for them in my particular project, but they're still good to know.
@ghadi What is breaking Boot on JDK 9 RC 1 right now?
for Boot https://github.com/boot-clj/boot-bin/pull/4 and then we'll need a release
Yeah, you'd mentioned both were broken and I was curious whether Boot's issue was similar to Leiningen's...
Thanks!
lein
needs to remove its reliance on the bootclasspath by default. It will be 1.9+ before https://dev.clojure.org/jira/browse/CLJ-2077 lands, if that will land at all (and I don't care if it does)
(I don't see us moving to Java 9 any time soon but I like to keep track of what's happening in Boot-land)
lein landed an option to stop mucking with the bootclasspath, but it still does it by default https://github.com/technomancy/leiningen/blob/master/bin/lein#L204-L206
Hello all, anyone worked with business hours calculation? I need to define something like business hour 09:00am -> 06:00pm, and local time 05:00 + 3 business hour returns 11:00pm next day. If next day is saturday or my business day (saturday can be business day for my business) return it
Hmm, I'm sure someone asked that exact question a week or so ago and there was a library suggested... unfortunately that's further back than the 10k message limit @fabrao
@seancorfield don´t clojurians#slack has old logs repo?
I searched those archives but couldn't find it...
Yeah, I think that was the library that was shared -- thanks @misha
It seems that the output from explain-data
of spec
is not a “real” map, but some object of type #:clojure.spec.alpha
. Unfortunately, it makes cheshire
go nuts. How do I cast it to a plain old map?
(type (s/explain-data ...)) ;;=> clojure.lang.PersistentArrayMap
*clojure-version*
=> {:major 1, :minor 9, :incremental 0, :qualifier "alpha16"}
That's just notation for a map where all of the keys are qualified in the clojure.spec.alpha
namespace.
Anyone ever played with Alia and needed to use PagingState to basically split a larger request into separate pages ?
(I should say that I see that PagingState can be passed to alia's execute
function, though grepping through the source, I can't see how I'm expected to get a com.datastax.driver.core.PagingState
)
@pseud yes - it's easy, and you don't need to directly play with PagingState
https://github.com/mpenet/alia/blob/master/modules/alia-manifold/src/qbits/alia/manifold.clj#L67 and https://github.com/mpenet/alia/blob/master/modules/alia-async/src/qbits/alia/async.clj#L66
are the manifold and core.async implementations respectively which return a channel / stream of results and work with the PagingState in the background
actually, iirc they work with the ResultSetFuture/ResultSet which manage the PagingState for you
the :fetch-size
option lets you control your page-size
@mccraigmccraig digesting.. thanks ! 🙂
yw @pseud - more questions welcome should you need
I have seen people use clojure.core/into
to merge maps instead of clojure.core/merge
. Beyond the fact that into
can operate on many collection types, is there any reason to prefer one over the other when working exclusively with maps?
@hmaurer I personally think it's a bit clearer to use merge
when dealing exclusively with maps. merge
is also variadic, letting you merge multiple maps with one call.
@pseud @mccraigmccraig I am on holiday, but if i recall even alia/execute supports at least :fetch-size and is truly lazy by default (no chunking). But @mccraigmccraig is right the async or manifold interfaces are much better for this kind of things
@mpenet Yup - it returns a non-chunked lazy seq. That said, it still often seemed to cause timeouts when I issued a large query (I bound the result to a var so that the repl wouldn't try to print the response, thus realizing it). But yes, I tried :fetch-size and that seems to suffice for me. 🙂
Hey! Is this the right place to ask for assistance? I am new at Clojure and having some problems.
I have a variable filenames
which is a vector of filenames of .edn files.
(defn read-file-as-edn [filename]
(->> filename
(slurp)
(edn/read-string)))
(let [filenames (list-files)]
(->>
(map read-file-as-edn)
(flatten)
(into [])))
This gives an output of []
, whereas what I want is the edns merged. What's wrong?@kaspern you're missing the first element of the ->>
form
(->> (list-files) (map read-file-as-edn) ...)
, and then you can get rid of the let
or else (->> filenames ...)
(->> (list-files)
(map read-file-as-edn)
(flatten)
(into []))
gives an error of java.lang.RuntimeException: Unmatched delimiter: ]
, seems to be on the (->> (list-files)
-line, same for the (->> filenames ...)
-versionThat would explain many things. I would have liked an error indicating so 😞 But thanks!
Is there a way to get only the part of a map that matched a clojure spec? e.g. if I have (def spec (s/keys :req [:foo/bar]))
and run (s/conform spec {:foo/bar 22 :abc 123})
, the map does conform and so it will be fully returned
I would like to only get the part of the map that conformed, and get rid of the superfluous :abc
key
in the more general case, I want to keep the parts of a data structure that the spec validated, and get rid of everything else
Obviously I could do a select-keys
afterwards if I know the keys, but I’m wondering if there is a way to do this directly from the spec
I don't think it's possible, no. You could use form
and match on the return value to get the keys directly from the spec and then run the select-keys
on that.
(defn how-conform [aspec data]
(let [
c (s/conform aspec data)
c (if (map? c) c (into {} [c]))
r (map (fn [x] (get c x x)) (s/describe aspec))
]
(map vec (partition 2 (rest r)))))
(how-conform (s/keys :req [::a ::b]) {::a 5 ::b 7 ::c 8})
like that ?
=> ([:req [:user/a :user/b]])
@the-kenny @octo221 thanks! that helps
it's not quite what you asked for but it's near
follow-up question: given that the return-value of s/describe
is a form, e.g.
(keys
:req
[:identity/first-name :identity/last-name]
:opt
[:identity/address :identity/user-account])
what would be the cleanest way to convert this into a map with keys :req
and :opt
?e.g. given a form with named arguments, what is the cleanest way to convert it to a map where the keys are the arguments’ names, and the values are the arguments’ values?
hmaurer: well you could write a tuple spec for that & conform on it. Example incoming.
@hmaurer Ugh that got a bit more ugly than anticipated, but should work for any simple s/keys
spec. I'm sure someone out there wrote a nicer version of this 🙂
(->> (s/describe (s/keys :req [::foo]
:opt []))
(s/conform (s/cat :keys-sym #{'keys}
:pairs (s/* (s/cat :kw keyword?
:keys (s/coll-of keyword?)))))
:pairs
(map (juxt :kw :keys))
(into {}))
Why the last expression returns
{:a :foo, :args [{:id :XX}], :id :XX}
instead of:
{:a :foo, :args [], :id :XX}
(require '[clojure.zip :as zip])
(defn my-zipper [tree]
(zip/zipper
(fn branch? [node]
(:args node))
(fn children [node]
(:args node))
(fn make-node [node children]
(assoc node :args (vec children)))
tree))
(def z (my-zipper {:a :foo :args []}))
(loop [loc z]
(if (zip/end? loc)
(zip/node loc)
(recur
(zip/next
(zip/edit loc #(assoc % :id :XX))))))
it looks it is associated with the fact that traversing with zip/next reveals there are 2 nodes :
(zip/node (zip/next z)) ; => nil
(zip/node (zip/next (zip/next z))) ; => {:a :foo :args []}
why is that? There is a single node with empty children so there should be only one node, correct?
@lambder I’ve not used zippers before, but it looks like your test in branch?
is slightly incorrect: that will consider a node with an :args
of []
to be a branch, since it’s not nil
. Changing branch?
to this fixes it, by the looks of things: (fn branch? [node] (seq (:args node)))
(seq [])
is also nil
; that’s the key difference. I guess you would consider a node with an :args
of []
to be a leaf, so it makes sense like that.
the doc says branch? should return true for nodes with empty children as they potentially can have children
Oh, my mistake — that should be children
that’s modified to use seq
(I actually did that in my REPL test…)
Well, it specifically says that it should return a “seq” of its children. A []
can be viewed as a seq, but isn’t a seq by itself.
Right, but the docs say seq. There’s a difference between seq and a sequence (unfortunately)
ok, @chrisjd it looks like this works:
(defn my-zipper [tree]
(zip/zipper
(fn branch? [node]
(:args node))
(fn children [node]
(seq (:args node)))
(fn make-node [node children]
(assoc node :args (vec children)))
tree))
The key point is the distinction between a seq and a sequence. They’re not the same thing.
nil doesn't implement anything, it's not a sequence and it's not sequential, it just behaves as a seq and thus as a seqable
if () is empty seq the why :
(require '[clojure.zip :as zip])
(defn my-zipper [tree]
(zip/zipper
(fn branch? [node]
(:args node))
(fn children [node]
(:args node))
(fn make-node [node children]
(assoc node :args (vec children)))
tree))
(def z (my-zipper {:a :foo :args ()}))
(loop [loc z]
(if (zip/end? loc)
(zip/node loc)
(recur
(zip/next
(zip/edit loc #(assoc % :id :XX))))))
or in other words single node with empty children makes zip/next to traverse the zipper tree as if there were 2 nodes.
I don't have time to look at that zipper code, but arguing that () is not the empty seq is wrong
well, nil behaves as an empty seq on seq operations, but isn't an empty seq in the sense that (seq? nil)
will return false
I’ve answered my own question [here](https://stackoverflow.com/questions/45694351/empty-children-and-clojure-zippers/45695243#45695243)
for the doc “branch? is a fn that, given a node, returns true if can have children, even if it currently doesn’t.”
(zip/next (zip/seq-zip ())) => [nil {:l [], :pnodes [()], :ppath nil, :r nil}]
e.g. not at the end yet
(zip/next (zip/next (zip/seq-zip ()))) => [() :end]
ok after 2 zip/next
s we have reached the end
@lambder there is a ticket about this
@alexmiller thanks
https://dev.clojure.org/jira/browse/CLJ-941 https://dev.clojure.org/jira/browse/CLJ-1317
one or both of those
neither is quite in a state to screen (even all these years later)
I’m happy to move it along if someone pays one or both of those some attention