This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-04
Channels
- # admin-announcements (9)
- # beginners (40)
- # boot (61)
- # cider (6)
- # cljsrn (5)
- # clojure (65)
- # clojure-gamedev (6)
- # clojure-greece (8)
- # clojure-ireland (1)
- # clojure-portugal (5)
- # clojure-russia (46)
- # clojure-uk (38)
- # clojurescript (177)
- # core-async (9)
- # cursive (17)
- # datomic (6)
- # dirac (8)
- # emacs (5)
- # error-message-catalog (8)
- # hoplon (248)
- # ldnclj (11)
- # ldnproclodo (1)
- # lein-figwheel (36)
- # leiningen (12)
- # mount (2)
- # off-topic (3)
- # om (26)
- # onyx (12)
- # perun (2)
- # planck (26)
- # re-frame (62)
- # reagent (55)
- # remote-jobs (2)
- # rethinkdb (1)
- # ring-swagger (14)
- # spacemacs (47)
- # untangled (69)
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)
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-10How 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
@stask yes, perfect
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
@danielcompton: perfect thanks
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.
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: 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 https://github.com/clojure/tools.cli ? seems like a handy lib
@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
@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 https://github.com/mmcgrana/clj-stacktrace 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...
@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: https://github.com/binaryage/dirac/blob/master/src/logging/dirac/logging/utils.clj#L59
you could implement a formatter to process LoggingEvent in a different way, maybe using parse-exception
from clj-stacktrace
here is an example of produced logs: https://travis-ci.org/binaryage/dirac#L637
I'm trying to convert this to pulsar: http://blog.paralleluniverse.co/2016/05/03/skynet-go-quasar/
@korny sounds like http://ioavisopretty.readthedocs.io/en/latest/exceptions.html#io-aviso-logging is what you’re after
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
defaultGw: 10.11.22.1
hypervisor: false
firstDetectDate: null
lastScanDate: null
@dimiter do you want all of the properties to be in the map, or a subset of them?