Fork me on GitHub

Is my understanding right? transduce is basically reduce, except instead of (reduce fn (xform coll)) you call it as (transduce xform fn coll), provided xform is a composition of map, filter, take, drop, replace, etc. As a bonus, then, such an xform can be used with into and channels and etc. Is this perspective incorrect?


sounds about right. the definition of transduce is almost literally (reduce (xform f) init coll) -- note the xform wraps the function


coltnz: DSL-like arguments are generally frowned upon in clojure. It is more idiomatic to use generic collection fns to transform sequences, wrt filtering. (file-seq f :dir) is implemented:

(let [dir? (memfn ^File isDirectory)]
  (filter dir? (file-seq f)))


thanks for the reply @ghadi on reflection you are right about the 'dsl' aspect, i don't get your point on implementation, isnt the point that we all have to do it cos we seldom want the collection as is (if it didnt have '.' it would be more useful)


perhaps i should be less ambitious and suggest


(defn file-seq [dir children-only?] 


though going to


(defn file-seq [dir children-only? files-only?] 
would be good too


i note File/listFiles doesnt include "."


That's also a small DSL, but the issues go beyond syntax. While it looks like a convenience, it raises more questions than it answers: what are all the possible filter options? what order are they listed in? what if there are conflicting combinations of options? The implementor of file-seq need not be in the business of providing conveniences... Just let the user do what they want with the abstraction (the seq).


If we gonna reduce that to a dsl, then theres precedent... I posit that file-seq is almost always used with a filter (often after being erroneously used without one) and that doc string to explain the option(s) needn't be burdensome even in the prevailing terse style but <shrug>


question about transducers:

(let [xform (comp (map :data) (filter even?))
        ch (chan 1 xform)]
    (clojure.core.async/>!! ch {:data (range 10)})
    (clojure.core.async/<!! ch))
The above returns nil because the (filter even?) receives a single arg, which is a collection, rather than the elements of the coll itself, ie the numbers 1-10


How do I split these items out so they can be processed individually


google keeps pointing me at an fn called eduction but I con’t figure out how to use it


@clumsyjedi: something like this: ` (let [xform (comp (mapcat :data) (filter even?)) ch (clojure.core.async/chan 1 xform)] (clojure.core.async/>!! ch {:data (range 10)}) (clojure.core.async/close! ch) (clojure.core.async/<!! (clojure.core.async/into [] ch))) `


@clumsyjedi: mapcat instead of the map


hello peeps, not really relevant to this channel but I dont know where to post this message


where could I get a list of companies using clojure in London?


@mariogintili: there is a London Clojurians email list, and a London Clojurians Job list


You could also talk to @jonpither at Juxt, he’s pretty friendly and might be able to help


Anyone have tips around handling user facing data validation errors in compojure-api/schema? I’ve looked at bouncer but using that would mean a lot of duplication between that and schema.


Does clojure join preserve the order of the list?


jtackett: clojure.string/join yes


Hello everyone. I need some feedback regarding Exceptions, I've read somewhere that Exceptions in clojure aren't frequently used. I'm writing a lib and want to know how do you think it would fit better:


The lib processes images using the command line. I'm doing a validation over the allowed options, to help whoever uses it. My current implementation whenever that option doesn't exist, I raise a java (Exception.), what would be a good contrasting approach to that? Or should I create my own specific Exception? What do you recommend/would like a library like this one to behave?


@thiagofm: we like slingshot.


@thiagofm: do you mean when someone passes an invalid option from the command line? an exception is a bit weird then imho


@thiagofm: there is a whole school of people who think that exceptions suck, but the alternatives ain't better in my opinion and i'd rather see a program fall on the face than paper over an error because some error code is not checked.


@borkdude: we like to have one exception handler in our -main function and translate exceptions into user-consumable message exactly there.


do you use ? seems like a handy lib


@borkdude: yes. we don't love it but we use it simple_smile


@hans: that's a way to do it, but afaik an exception is not needed if you have something like {:errors [...]}, but yeah, it's possible of course


the benefit of working with {:errors [....]} is that you can display multiple errors (unless you use the exception to wrap a collection)


@thiagofm: take a look at ex-info, instead of raw Java exceptions. They’re more idiomatic, and let you bundle arbitrary data in an exception and easily get it out again with ex-data


@hans: slingshot is what I had in mind


@danielcompton: the shell library I use, uses this approach. Will take a look


@borkdude: I mean that somebody has written a program passing a wrong argument. For this case I would like the programmer to see that this command doesn't exist or that a typo has been made


@jm: plumatic schema & human readable errors seems to be unsolved. I would suggest writing / commenting issue to Schema itself.


Hi folks - anyone know of a way to get pretty exception stack traces, like those in in a log output by log4j?


I’ve got a feeling this might be fiddly, as the stack traces are formatted by some internal log4j appender, not by clojure code. But I’m hoping someone can prove me wrong...


(I’m actually using tools.logging but have log4j as the underlying logger)


@korny: not sure about enhancing stack traces, but I ended up implementing my own log4j “layouter" when printing logs to console, I prefer to have logger name and then actual content indented at specific column (multi-line text aware) here is the implementation: you could implement a formatter to process LoggingEvent in a different way, maybe using parse-exception from clj-stacktrace


neat stuff - thanks


Hi, anyone familiar with pulsar actors?


@mping: I only did the tutorial, they look awesome


but my impl is borked 😄


@ikitommi: thanks for the reply


is there a place to update my information given on the Clojure Contributing Agreement?


Hey, if I have a Java Object with a number of public attributes, what is the easiest way to turn that into a Map.


Say I have the following properties on the object.

name: someName
state: OK
agentVersion: 60.0.59410.0
stage: UNKNOWN
opswLifecycle: MANAGED
hypervisor: false
firstDetectDate: null
lastScanDate: null


I want to turn that list of props into a map


@dimiter do you want all of the properties to be in the map, or a subset of them?


All of them, I can dissoc any ones I dont need later.


have you tried bean?


or seen wallhack?


wallhack gives you an object that implements ILookup, which is not entirely a map, but you can call get and use destructuring on it


Question about macros. Do they expand at static compile time, as in, do they expand when I'm creating my jar, or are they going to expand at run-time compile time, that is, when Clojure loads the classes and dynamically compiles them?