Fork me on GitHub
#clojure
<
2015-09-04
>
gtrak00:09:38

that's the only use of clojure.lang.TransformerIterator/createMulti so it seems right

firthh01:09:08

can you use mapcat instead of (comp (map ... ) cat)

gtrak01:09:26

Yea, i believe so.

gtrak01:09:36

it started as a standard lazy mapcat

gtrak01:09:53

that works fine

gtrak01:09:37

`(defn make-record [cols row] (into {} (sequence (mapcat (fn [col col-val] (if (seq col-val) [[col col-val]]))) cols row)))`

gtrak01:09:37

would like to just use into if possible

firthh01:09:30

so are you trying to achieve something like the first example for interleave - https://clojuredocs.org/clojure.core/interleave

gtrak01:09:04

yea, same idea

gtrak01:09:11

or zipmap

gtrak01:09:57

but zipmap itself is pretty slow simple_smile

gtrak01:09:14

i don't know why it doesn't use transients

gtrak01:09:23

for the last 7 years

gtrak01:09:09

(defn make-record
  [cols row]
  (as-> nil ⛷
    (mapcat (fn [col col-val]
              (if (seq col-val)
                [[col col-val]])))
    (sequence ⛷ cols row)
    (into {} ⛷)))

Alex Miller (Clojure team)01:09:36

There is a ticket to update zipmap fyi

gtrak01:09:36

I always opted for just using into, but seems like we should be able to skip that extra lazy-seq

Alex Miller (Clojure team)01:09:59

On a phone so hard to search it but it's also rewritten to use iterators so it avoids the seq

Alex Miller (Clojure team)01:09:27

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

gtrak01:09:04

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.

gtrak02:09:35

https://github.com/cognitect-labs/transducers-js/issues/11 here it says transduce would need to be changed to support multiple collections

ghadi02:09:26

gtrak: your original snippet (-> (comp … whatever) cat) is invalid, because the cat transducer is being evaluated too early

ghadi02:09:15

transducers must be applied by either into, sequence, transduce or eduction, not early as arguments to those customers

gtrak03:09:11

@ghadi I think it's just bad indentation and unnecessary -> in the first place

tel03:09:15

mapcat is “as powerful as” any pure transducer

tel03:09:35

so if you are getting to that point then it might be desirable to break it into pieces

tel03:09:29

one of these days I’m going to get used to precomposed comp

mccraigmccraig08:09:13

firthh: i've been using the producer directly and the consumer via https://github.com/onyx-platform/onyx-kafka ... pretty straightforward

danielgrosse09:09:26

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?

kongeor09:09:16

How can I check that a vector contains exactly one element of type a and all the rest are of type b

kongeor09:09:53

i'm using prismatic schema and a basic example would be a vector of positives and negatives ints

kongeor09:09:41

something like [-1 1 -2] would match while [1 1 -2] would not, the exact positions are irrelevant

ragge09:09:15

@firthh: we're using it extensively at uswitch (and wrote/maintain it) , let me know if you have any qs

jonpither09:09:27

Any buddy guys in here?

phil_r10:09:35

@kongeor both those vectors are 2 of one thing and one of the other thing though... simple_smile

phil_r10:09:44

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.

kongeor10:09:33

@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)])

kongeor10:09:28

this is a child of a more complex schema, so I'm not sure how I would run functions on it

phil_r11:09:45

@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

phil_r11:09:10

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

phil_r11:09:38

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))

zcaudate12:09:04

hey guys. wanted to show off a simple library for directed graphs:

jsyeo12:09:58

j-bob proof assistant in clojure https://github.com/holguinj/clj-bob

bbss12:09:29

that's cool @zcaudate was thinking of doing something similar for the browser (JS or CLJS)

jrychter14:09:02

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 😃

amacdougall14:09:05

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.

luxbock15:09:02

@zcaudate: have you tried exporting GraphStream graphs to SVG?

luxbock15:09:29

I hadn't heard of the project before. Looks very interesting

martinklepsch15:09:48

Why is this?

(get #{1 2 3} 1) ;=> 1
(get [1 2 3] 1) ;=> 2

meow15:09:04

a set isn't ordered

martinklepsch15:09:09

right, but shouldn’t (get #{1} 0) still return 1?

luxbock15:09:09

@martinklepsch: (get #{:a} :a) returns :a

luxbock15:09:27

sets are like maps where the keys and values are identical

martinklepsch15:09:34

Oh that makes sense.

luxbock15:09:10

calling nth on a set throws an exception even, which makes sense

luxbock15:09:43

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

luxbock15:09:42

so from what I understood from the course, a priority-queu is another name for the heap datastructure

luxbock15:09:16

and it serves very much the same purpose as an AVL-tree

luxbock15:09:20

I don't know if that's the case for priority-map btw

luxbock15:09:19

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

luxbock15:09:58

so I'm wondering if there are any reason for why I would use the priority-map library over the avl one

zcaudate16:09:30

@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

zcaudate16:09:12

@luxbock: No I haven’t… just been saving screen shots atm 😃

zcaudate16:09:28

but it’s really easy

luxbock16:09:10

@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

zcaudate16:09:31

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/

zcaudate16:09:51

it will give you a clue of what’s possible

jrotenberg17:09:26

playing around with transducers a bit seems to lead to wanting to transduce all the things

timvisher18:09:51

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?

timvisher18:09:10

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?

timvisher18:09:17

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

timvisher19:09:28

anyone know how to get a hold of weavejester? i have a potential security hole to report to him

akiva19:09:18

He’s pretty active on Twitter.

tcrayford19:09:56

@timvisher: though you way want to report a security hole via pgp and email 😉

tcrayford19:09:30

@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

puzzler20:09:33

@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").

puzzler20:09:17

@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.

darwin20:09:38

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.

Alex Miller (Clojure team)20:09:42

you might find this article on zippers I wrote a zillion years ago useful http://www.ibm.com/developerworks/library/j-treevisit/

Alex Miller (Clojure team)20:09:50

in particular, Listing 14 creates a generic tree zipper

Alex Miller (Clojure team)21:09:37

you can certainly do it in less code but that creates an open system via multimethods

darwin21:09:17

@alexmiller: thanks for the pointer

darwin21:09:01

that’s exactly the reading I needed, using tools.reader to parse general cljs sources and need a way how to walk/edit it