This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-21
Channels
- # aatree (5)
- # admin-announcements (3)
- # beginners (13)
- # boot (25)
- # cider (4)
- # cljs-dev (2)
- # clojure (107)
- # clojure-austria (2)
- # clojure-japan (12)
- # clojure-russia (128)
- # clojurebridge (2)
- # clojurecup (32)
- # clojurescript (68)
- # css (4)
- # cursive (3)
- # datascript (4)
- # datomic (8)
- # devcards (25)
- # hoplon (19)
- # immutant (2)
- # ldnclj (4)
- # liberator (2)
- # luminus (5)
- # off-topic (184)
- # om (78)
- # onyx (2)
- # portland-or (11)
- # re-frame (27)
- # reagent (11)
- # yada (3)
don't worry, I forgot I was going to do that so I haven't done it yet
Let's say I have two protocols, A and B, and a bunch of types that each implement either A or B but not both.
Let's also say that I have a function f
that, given an instance of one of those types, needs to behave with one of two possible behaviors, depending on whether its input satisfies A or B.
What's the most idiomatic way to do this?
• `f` could use (cond (satisfies? A input) ..., (satisfies? B input) ..., :else (throw (ex-info "Needs to satisfy A or B" {})))
(though apparently satisfies?
is currently quite slow (http://dev.clojure.org/jira/browse/CLJ-1814))?
• A third protocol C could be defined, which each of the types must implement in addition to A or B, and which has a single method ab-type
that returns either :a
or :b
whenever A or B is respectively also implemented. f
could then use (case (ab-type input) :a ... :b ...)
?
• Maybe multimethods (though I can't yet think of a way how one would)?
• Something else?
Wouldn't it be more natural that A and B protocols include a method that f needs, or include f as a method?
Otherwise, I would say that your first point (using satisfies?) is the most idiomatic.
Enjoyed this read: http://mishadoff.com/blog/clojure-design-patterns/
I'm doing Advent of Code in Clojure as a relative newbie. Placed 90th today! @borkdude
I'm lagging behind, only doing it on the weekends and elaborate on details, just to learn a new language
Is there a core.async
function that is the opposite of onto-chan
? Basically, one that does (async/<!! (async/reduce conj [] ch))
to get a collection out of a channel?
@jrychter: I am not aware of such a function in the library itself, its easy to write a naive version if you can guarantee your channel will close - however it cannot work with all channels which I guess is why such a fn isn't in the core.
(defn into
"Returns a channel containing the single (collection) result of the
items taken from the channel conjoined to the supplied
collection. ch must close before into produces a result."
[coll ch]
(reduce conj coll ch))
@d-t-w Yeah, I just thought there would be a single function for this operation. Clojure naming isn't always easy to guess.
is there something in emacs/cider that can format a file that contains edn like pprint does?
anyone using jars and know how to use -classpath and also pass args to the -main defined in -classpath?
Hmm. I'm writing a stateful transducer and it behaves differently when attached to a core.async
channel than when run through sequence
or into
. In particular, my arity-1 flushing function gets called twice (?).
Is it expected for (async/to-chan (line-seq rdr))
to hold on to the head and exhaust memory?
@jrychter: if you can add it as a comment to that ticket, it might help getting it prioritized
@bronsa: I'm just curious how is that not a showstopper for anyone who puts any significant amount of data through core.async
? Am I missing something?
I'm processing log data through a core.async
pipeline with transducers. My 8GB heap is gone within 30 seconds of starting.
@jrychter: if you could try that with a patched core.async
applying that ticket's patch and see if it does indeed fix the leak, (and if so, report that in the ticket), that would be helpful in getting the patch forward
Ok, I see why it doesn't affect more people: it's not all go blocks that leak memory, just ones that use lazy sequences created elsewhere.
Who here has used yesql
I just want to confirm something
@bronsa: Ok, I panicked too early. I can work around that by writing a non-leaking-onto-chan
that uses future
, loop
and blocking puts instead of a go block.
Are a series of rows returned via a SELECT
query in the form of a lazy sequence or as a vector
reason is that I would like to add an extra element to the sequence of rows returned by the query
I'd guess it was lazyseq?
Yeah, that sounds about right. I just needed confirmation
also, hugsql
? What an adorable name
@bronsa Thanks for letting me know about this bug — I could have wasted even more time on this if it wasn't for your help.
@trancehime: You should check it out. Hugsql fixed every problem I had with Yesql. I’ve even written a postgres-async adapter for it that uses core.async. Cool stuff.
@jonpither: just Om, Reagent or Quiescent
A colleague of mine (@jjconti) is experiencing a weird error when using cljs-time. What makes it weird is that the same code works on my machine. Same version of ClojureScript and cljs-time: http://stackoverflow.com/questions/34401358/error-formating-date-in-clojurescript Any clues whit might be going on?
No, different project.
Yeah, but we haven’t been able to figure it out.
@jrychter: Hey man, I think you might have just solved a production bug for us by bringing this up at the right time Nicely done.
What is the best way to coerce incoming data in JSON format to a desired shape/schema?, Which libraries are used for that purpose?, I am trying to apply the coerce function from prismatic schema to transform a JSON but it fails trying to convert a string date to a java.util.Date.
I read about clj-time and about transit?, could this problem be solved using one of those libraries?
@rcanepa: Transit can send any arbitrary values, preserving their type, but you have to be using Transit on both sides of the communication. It doesn't transform JSON from arbitrary sources.
@rcanepa: I had no problem with such coercion. Granted, I used clj-time, but had no problem with stock schema coercion.
@stuartsierra: Good to know that, because I don’t have much control over the client side.
@pupeno: Maybe it’s related to this? https://github.com/bhauman/lein-figwheel/issues/210
@jaen: Maybe I am not understanding correctly how to use the coerce feature. Right now, I am doing a very simple test and it is failing. Could I be doing it wrong?
I am getting this error: #schema.utils.ErrorContainer{:error (not (instance? java.util.Date a-java.lang.String))}
(merge coerce/json-coercion-matcher {java.util.Date your-function-that-takes-string-and-returns-java-util-Date})
As you have it no coercion happens for Dates
so it gets a string and that doesn't match the schema.
I guess that’s reasonable behavior given that there are so many different Date types.
Some people wouldn't want to have to depend on JodaTime, some wouldn't like stock dates.
Were it all Java8 then it probably could standardise on the new API, but alas, that's all too new.
is there a way to make core.test print the string facts in testing declarations (ie. (testing “print me” … )
) when running the tests? similar to how midje allows for (change-defaults :print-level :print-facts)
in your .midje
@solicode: we are also suing the same version of figwheel
@pupeno: Hmm, interesting. I'm not sure if Figwheel is causing the problem or not, but maybe it's worth a shot to try and take Figwheel out of the equation and see what happens. Other than that, I'm not sure if I have any other ideas.
@potetm: hey, glad to take one for the team! May I suggest that you also upvote the core.async bug in JIRA and possibly add a comment describing how it affects you?
I hope to have a few min to look at some of those async things this week
Anyone have any recommendations for a microservices/rpc library like Finagle but in Clojure? I'm aware of the Clojure/Finagle wrapper, but wondering what else might be out there...
@blissdev: I try to make functions small enough that the docstring is the only comment needed.
Other than that, just the old Lisp conventions: end-of-line comment begins with one semicolon, block comments in a function begin with 2 semicolons.
If I have a superclass A
and a subclass B
that overrides all of the methods in A
, does (.x ^A a)
call the implementation from A
, or B
?
@lvh It calls the implementation of whatever concrete type a
is, just like Java.
I don't think it's possible in the JVM to call a super-class method implementation from a sub-class which overrides it.