This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-07
Channels
- # aws (2)
- # bangalore-clj (4)
- # beginners (62)
- # boot (74)
- # cider (408)
- # cljsrn (17)
- # clojure (117)
- # clojure-dusseldorf (1)
- # clojure-russia (21)
- # clojure-spec (17)
- # clojure-uk (15)
- # clojurescript (154)
- # cursive (3)
- # datomic (16)
- # emacs (33)
- # funcool (3)
- # hoplon (99)
- # off-topic (7)
- # om (10)
- # overtone (3)
- # portland-or (1)
- # protorepl (9)
- # re-frame (83)
- # reagent (11)
- # remote-jobs (1)
- # ring-swagger (24)
- # specter (10)
- # untangled (1)
- # yada (11)
are namespaces first class objects in clojure? can I pass a namespace to a function, then have the function lookup a function in the namespace? (I realize this is probably bad convention, but I'm doing some macro magic funkiness)
you can dynamically fiddle with namespaces and do all kinds of stuff, but the clojure runtime is pretty static in how it works, it does all its lookups, etc, at compile time, which can be at odds with what people expect if they can poke at namespaces
(for [[k v] some-magica-list]
(context k [] #'v/app-routes))
^^ I'm trying to do something like the above, where k = string, and v = a namespace, so I take a list of (string, namespace) pairs, and I generate the compojure routes from that -- is this something reasonable, or is this something that will just be causing me lots of headaches if I attempt it?https://github.com/hiredman/graft/blob/master/src/graft/core.clj might be something to look at (but I don't really recommend using it)
@hiredman: graft = handler already defined, and you're adding new routes to it at compile time?
what’s a good way to remove nils from a nested collection of maps and lists? (remove-nils {:a [1 2 nil [4 nil 1]]}) => {:a [1 2 [4 1]]}
(remove nil? coll)
nested
oops..
I think you should try some version of postwalk
i would also question why you need to remove them
or even why they are in your collection
but if you are writing a helper/library function then ignore that
writing a view template parser where the template is a map. some sections have conditionals which return nil when the section is supposed to be hidden
anyone here with experience replacing compojure (macro driven routing) with bidi/silk (data driven routing)?
@qqq Yes, though I wrote the latter. 😉 Feel free to @mention or DM me with any issues you run into.
I have a huge map and want to find all kv-pairs that match a certain predicate. I think clojure.walk
is what I’m after but I don’t know how to use it. Can anyone provide me a pointer maybe?
@qqq but it doesn’t traverse the map in depth. That said, tree-seq
might be what I’m after 🙂
It’s a deeply nested map with a key like _projects123123
somewhere, I want to find all kv-pairs with this key. I’ll try tree-seq
and if that doesn’t cut it I’ll whip up an example
Ok tree-seq
didn’t yet lead me anywhere
here’s some example data https://gist.github.com/martinklepsch/69da07de5d8b3d6e9502b1df000f163c
What I want to get out of it is all the values of the various _showtimes1iJdI0
keys in the map
@martinklepsch specter? https://github.com/nathanmarz/specter (obviously not std lib though)
Apart from that: http://stackoverflow.com/questions/32853004/iterate-over-all-keys-of-nested-map
@mikethompson flatten-keys gets a bit hairy when you also have seqs etc
@mikethompson I’ll take a look at specter, meant to since ever basically anyways
found some solution, doesn’t feel pretty but well, … it works 🙂
(->> input-data
(tree-seq #(or (map? %) (vector? %))
#(cond (map? %) (vals %) (vector? %) %))
(filter map?)
(map #(get % "_showtimes1iJdI0"))
(keep identity))
@martinklepsch, in case you can use specter
$ boot repl
boot.user=> (set-env! :dependencies '[[com.rpl/specter "0.13.2"]])
boot.user=> (require '[com.rpl.specter :as s])
boot.user=> (def m {:a 34 :b 28 :c {:bingo 40 :d 23 :e {:bingo 41}} :bingo 42})
#'boot.user/m
boot.user=> (s/select [(s/walker #(and (coll? %)
(= :bingo (first %))))
(s/view second)] m)
[40 41 42]
@tolitius interesting, I’ll give that a shot if I run into perf issues
I get how silk works for match/unmatch, but I do not yet see how to create, in silk, routes that I can use with ring
qqq: Ring doesn't care about routes. You'll just have to take the http path header and throw it at silk to match it.
@rb1719 in your example x
is a map with one key-value pair where the key is :a
and the value of that key is :b
. You can create a new map with :a
set to 1
but :b
was the original value of :a
so that will not exist in the new map. {:a 1 :b}
is not a legal map as it's one key-value pair and a key on it's own. All maps must have an even number of forms i.e. key-value together.
@agile_geek if I have (def x {:a 1 😛 4}) is there a way to change the value of 1 to 2 for example?
but it always creates a new map
:b
if not in backticks is an emoji
BTW it might be better to ask this kind of question in the #beginners channel
I didn't know there was a beginners channel. I will ask there in the future. Thanks again
Be aware that assoc
produces a new map, as all data structures in Clojure are, by default, immutable it will not change the value of the var x
How do I disable clojar signing on release? It says add :sign-releases false
to the relevant :deploy-repositories
entry. but I don't have any :deploy-repositories
@tbaldridge: I feel there must be some significant comic effect that can come from the use of 'impudence miss-match' 🙂
is it possible to create a quartzite job without assigning it a toplevel var? (e.g., without using defjob
or defrecord
)
(def api-routes
(silk/routes {:api-data [["api"]
{"limit" (silk/? (silk/int :limit) {:limit 100})
"offset" (silk/? (silk/int :offset) {:offset 0})}
(serve/POST)]}))
(silk/match api-routes {:path ["api"] :request-method :post})
why does this return nil?} according to docs, it should return something like:
;=> {:limit 100, :offset 0, :domkm.silk/name :api-data, ...}Is there a pretty printer focused on printing data in a predictable, diff-friendly way? I tried clj-fmt and clojure.pprint but both don’t really help much it seems
@martinklepsch Can you not use clojure.data/diff
prior to printing and just pprint the result?
Alternately I think you can adjust the line-length on clojure.pprint so that it's so huge that there aren't arbitrary line breaks
I don’t want to print the diff. I want to print the entire data but in a way that does not break tools like git diff
horribly
An important aspect for that is to maintain the order of keys in maps
But maps are unordered....
I can live with weird line breaks every now and then but shuffled keys just wrecking everyting
well hash maps are
@tbaldridge I know but that doesn’t mean they can’t be printed in an ordered way 🙂
I don't know of any pretty printer that does this, but fipp might be a bit more extensible than the built in pprint
I’ll give it a try 🙂
is there a simple way to express arbitrary maps in clojure.spec? say a string->number or a number->::user map?
but it sounds like what you want is a pprint that defaults to one key per line
@lambdacoder yes...is it map-of?
yeah: http://clojure.github.io/clojure/branch-master/clojure.spec-api.html#clojure.spec/map-of
ahh, thanks! I was trying to google for it and the about/spec page doesnt mention it 🙂
http://clojure.org/guides/spec under "Collections"
there it is! that guide could be linked to at the bottom of the about page, seems to be a natural follow up read
oh wait, its linked to a bit before the end, my bad
quick question - is there a better way to figure out whether current date is in the past in clojure? all I got now is (neg? (compare (clj-time.coerce/from-date some-java-util-date-clojure-instant) (clj-time.core/now)))
I must be missing something trivial. How do I use silk (instead of compojure) with ring? I understand that ring gets a map encoing the request, but I don't see how to hook this up to silk/match
@qqq unlike compojure and defroutes, you will use silk to match the incoming url+params and use that dispatch a ring handler yourself. no?
i'd imagine you need a ring handler to respond to all requests, which inspects the url and then uses the silk returned match to call ring handlers which you're presumably storing in your own map which maps results from silk queries to ring handlers
boot.user=> (require '[clj-time.core :as t])
boot.user=> (t/before? (t/date-time 1986 10) (t/now))
true
once you get it working you should throw it up on github so no one else needs to reinvent this particular wheel
@qqq Here's a third-party example I bookmarked a while ago https://gist.github.com/Deraen/426285564376266c675b though it's frontend
@qqq You can use the ring-handler
function https://github.com/domkm/silk/blob/master/src/domkm/silk/serve.cljx if you want to write a little less
@qqq here are some other public resources https://pupeno.com/2015/08/18/no-hashes-bidirectional-routing-in-re-frame-with-silk-and-pushy/ https://pupeno.com/2015/09/21/bidi-vs-silk/
@tolitius, thanks. somehow missed it. also I thank you very much for making wonderful mount library. it is so much simpler to use than system
@leov if you're using java 8, you can write some interop code around java.time. I think there are a few clojure libs which wrap it as well.
@domkm: I saw the bidi vs silk resources; but I couldn't figure out how to get a ring handler out of either of them
@qqq Not a problem. Check out the Ring spec https://github.com/ring-clojure/ring/blob/master/SPEC . It's only 140 lines and very readable.