This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-09-04
Channels
- # admin-announcements (25)
- # beginners (21)
- # boot (161)
- # cider (12)
- # clojure (92)
- # clojure-art (1)
- # clojure-germany (5)
- # clojure-nl (5)
- # clojure-russia (38)
- # clojure-sweden (1)
- # clojurescript (87)
- # clojutre (2)
- # cursive (9)
- # datascript (1)
- # datomic (22)
- # devops (1)
- # editors (33)
- # events (3)
- # hoplon (19)
- # immutant (7)
- # jobs (2)
- # ldnclj (22)
- # off-topic (41)
- # re-frame (34)
- # reagent (39)
`(defn make-record [cols row] (into {} (sequence (mapcat (fn [col col-val] (if (seq col-val) [[col col-val]]))) cols row)))`
so are you trying to achieve something like the first example for interleave - https://clojuredocs.org/clojure.core/interleave
(defn make-record
[cols row]
(as-> nil ⛷
(mapcat (fn [col col-val]
(if (seq col-val)
[[col col-val]])))
(sequence ⛷ cols row)
(into {} ⛷)))
There is a ticket to update zipmap fyi
I always opted for just using into, but seems like we should be able to skip that extra lazy-seq
On a phone so hard to search it but it's also rewritten to use iterators so it avoids the seq
I have some doubts about whether that is actually an ok requirement. The transient part obviously needs to be done. The other key is to avoid mapentry creation
Ah I see that iterators addresses the seq issue with zipmap in particular, and if the end result is a concrete map, then that's good. I'm still wondering if I can express a zip transducer, since using it requires 'sequence'. I tend to chain a lot of operations on maps at once, and I don't need concrete seqs/maps along the way necessarily.
https://github.com/cognitect-labs/transducers-js/issues/11 here it says transduce would need to be changed to support multiple collections
gtrak: your original snippet (-> (comp … whatever) cat)
is invalid, because the cat
transducer is being evaluated too early
transducers must be applied by either into, sequence, transduce or eduction, not early as arguments to those customers
has anyone used clj-kafka? - https://github.com/pingles/clj-kafka
firthh: i've been using the producer directly and the consumer via https://github.com/onyx-platform/onyx-kafka ... pretty straightforward
Hello, I want to generate pngs from a given text, with style applied on the text. Do you now some libraries who are could be helpful?
How can I check that a vector contains exactly one element of type a and all the rest are of type b
i'm using prismatic schema and a basic example would be a vector of positives and negatives ints
something like [-1 1 -2] would match while [1 1 -2] would not, the exact positions are irrelevant
@firthh: we're using it extensively at uswitch (and wrote/maintain it) , let me know if you have any qs
One way is maybe (group-by neg? your-vector) and then checking that the map that comes out of that has exactly 2 vector values and one of them is exactly 1 element long.
@phil_r: yep, I was thinking something like (s/both [s/Num] [(s/optional s/Num) (s/one (s/pred pos?)) (s/optional s/Num)])
this is a child of a more complex schema, so I'm not sure how I would run functions on it
@kongeor: I'm not too familiar with prismatic/schema, but it looks like you can use (s/pred your-fn) to define a checking function for a part of a schema
you could probably also write this as a reducer where you 'accumulate' nil
for no single value found, true
for one single value found and false
for more than one found
maybe something like this (but mind i'm no schema expert):
(defn exactly-one-of? [one others coll]
(reduce (fn [result item]
(cond
(false? result) false
(and (s/validate one item) (nil? result)) true
(and (s/validate one item) (true? result)) false
(and (not (s/validate others item))) false
(true? result) true
:default nil))
nil
coll))
(s/pred (partial exactly-one-of? s/OneThing s/OtherThings))
j-bob proof assistant in clojure https://github.com/holguinj/clj-bob
that's cool @zcaudate was thinking of doing something similar for the browser (JS or CLJS)
Ok, so I fixed at least one problem. lein new
now works for me, after I found an old project.clj
sitting in my $HOME
, four directory levels up from where I was. I should have understood that the message java.io.FileNotFoundException: Could not locate clojure/data/priority_map__init.class or clojure/data/priority_map.clj on classpath
meant I should look for a project.clj
anywhere up the directory tree 😃
I've been thinking more about my YeSQL/clj-time quandary, and I think that instead of trying to convert everything to/from clj-time at the instant of database access, maybe I should keep everything as SQL timestamps (or to be more exact, whatever YeSQL chooses to convert timestamps to), and convert to clj-time only within functions that manipulate datetimes. If nothing else, this is probably an easy approach to rework later.
Why is this?
(get #{1 2 3} 1) ;=> 1
(get [1 2 3] 1) ;=> 2
right, but shouldn’t (get #{1} 0)
still return 1
?
@martinklepsch: (get #{:a} :a)
returns :a
Oh that makes sense.
@luxbock: thanks!
speaking of data structures... I've been watching the MIT OpenCourseWare lectures on Introduction to Algorithms, and that got me wondering about the practical difference between clojure.data.priority-map
and clojure.data.avl
so from what I understood from the course, a priority-queu is another name for the heap datastructure
my impression from the videos was that there aren't really situations where a priority queu would be better than an AVL-trees efficiency wise
so I'm wondering if there are any reason for why I would use the priority-map library over the avl one
@bbss: yeah I thought about doing a js version before wrapping graphstream. the problem ultimately is that it needs to be run in a browser and so there is one more layer of complexity to deal with
@zcaudate: cool I'll have to give it a try, been using Rhizome so far for my project but I'd like to have better control over styling stuff
sweet… 😃 the css styling is not very well documented at the moment but if you have a look at http://graphstream-project.org/doc/Tutorials/GraphStream-CSS-Reference_1.2/
playing around with transducers a bit seems to lead to wanting to transduce all the things
i have a circleci build that runs lein uberjar
to create an artifact. That artifact includes a log4j.properties file. During the build, it appears that that log4j.properties file attempts to log to the file that the jar is configured to log to. I’d like to avoid that. Any thoughts?
i don’t think i can specify a different resources directory because then the prod log4j.properties file wouldn’t be included in the jar?
i suppose i should say that the uberjar process attempts to log to the file that the prod jar will eventually be logging to based on the included log4j.properties file
anyone know how to get a hold of weavejester? i have a potential security hole to report to him
@timvisher: though you way want to report a security hole via pgp and email 😉
@timvisher: re log4j: one dumb option: remove the log4j properties file from your production config, then just treat the jar file like a zip file and shove it back in it after the build
@luxbock data.avl is a drop-in replacement for Clojure's sorted maps. data.priority-map sorts by the map's values, not the map's keys, and is therefore better suited for use as a priority queue (because if you're sorting by keys, the keys must be unique so you can't have two things with the same "priority").
@luxbock Also since data.priority-map has the object as the key and the priority as the value, it makes it easy to query whether a specific object is in the priority map. If you try to use a sorted map (or data.avl) as a priority queue, then the priorities are the keys and the objects are the values, and there's no efficient way to query or delete a given object from the queue.
I’m looking for some example of make-zipper call which turns general edn into a zipper, seq-zip branches only on lists, I need to branch on lists, vectors, sets, maps, etc.
you might find this article on zippers I wrote a zillion years ago useful http://www.ibm.com/developerworks/library/j-treevisit/
in particular, Listing 14 creates a generic tree zipper
you can certainly do it in less code but that creates an open system via multimethods
@alexmiller: thanks for the pointer