Fork me on GitHub
#clojure
<
2018-01-11
>
caleb.macdonaldblack02:01:45

Does anyone know why my pedestal interceptors :enter fn are not being short-circuited when one of the returns context with :response like it says in the docs http://pedestal.io/reference/servlet-interceptor

caleb.macdonaldblack02:01:54

I need to use io.pedestal.interceptor.chain/terminate. We believe those docs are out of data

caleb.macdonaldblack03:01:44

@luskwater Thankyou. You are right, headers as a map must be provided to short circuit

luskwater03:01:56

I’ve been diving into Pedestal for the past couple of months, so it’s fresher in my mind than it might be in others. Have a good afternoon (if your local time is what Slack says it is).

caleb.macdonaldblack03:01:07

Thanks I think I got confused with because this: http://pedestal.io/reference/response-map

caleb.macdonaldblack03:01:26

The table shows headers not being “Always Present?“. I assumed this meant that it was not required. I must have misinterpreted what “Always Present?” meant.

josh_tackett03:01:56

Anyone know a good clojure library for stock market sentiment analysis?

qqq04:01:10

using prewritten, open source, off the shelf stock market analysis code is probably equiv to writing a check directly to Renaissance / Two Sigma

qqq04:01:48

there's stanford nlp / open nlp / spacy if you don't mind java, but you'll have to check the licenses for cmmercial use

qqq08:01:03

(def tswap!                   (fn [ta f & args]
                                (swap! ta
                                       (fn [tv]
                                         (as-> tv **
                                             (update-in ** [::t] inc) 
                                             (apply update-in ** [::s] f args))))))
is there a better way to write this? I'm not sure why, but this code just looks unnecessairly complex

bronsa09:01:53

(def tswap!
  (fn [ta f & args]
    (swap! ta
           (fn [tv]
             (-> tv
                 (update-in [::t] inc) 
                 (update-in [::s] (partial apply f) args))))))
maybe

qqq09:01:33

(def fma                  (fn [m] #(reduce (fn [o [k f]] (u-in o [k] f)) % m)))
(def d-swap!                  (fn [da f & args] (swap! da (fma {::age inc ::s #(apply f % args)}))))
^-- job security ftw

qqq09:01:53

=== related question I have a structure of the form {:: age INT ::data ... } where I'm building a distributed object, and I need to keep track of how 'recent/old' an object is -- what is a good name for such an object ?

romni10:01:27

is there any way in clojure to do typehints for multiply bounded types?

bronsa11:01:45

@rimooz_clojurians what do you mean by multiply bounded types?

bronsa11:01:22

generics? no

romni11:01:20

let's say i have a class which implements interfaces A and B, and another class which also implements A and B

romni11:01:34

then i would like to typehint on A & B

romni11:01:47

instead of making an interface which extends both and typehint on that

romni11:01:53

because that would require me to rewrite both classes

romni11:01:45

i know in java you create those with type witnesses (eg. <G extends A & B> where G is generic and A, B interface types) but i was wondering if there's some syntax in clojure which supports this in another way

qqq11:01:17

@bronsa: I don't doubt your expertise; but what do you read to give you the confidence that no such thing exists? (i.e. for me, for negative responses, the best I can reach is "I don't know how to do that; but Clojure has enough black magic that I'm not sure") -- is there some official clojure spec?

bronsa11:01:38

I’ve read and written clojure compilers

bronsa11:01:00

no comprehensive docs that i’m aware of

bronsa11:01:23

there’s no clojure specification

qqq11:01:14

oh wow, was unaware you were a clojure.core contributor

qqq11:01:20

it'd be nice of someone wrote a "The C Programming Language" type ref for Clojure. My entire learning process has been bits / pieces here & there, and at some point, a comprehensive ref would be nice.

qqq11:01:42

I guess it's unrealistic as Clojure is still evolving as a language.

bronsa11:01:24

@qqq @reborg is working on exactly that

bronsa11:01:54

FWIW reading through clojure/core.clj is quite easy and very instructive

qqq11:01:58

@reborg: what's planned for Part 5, "Type Oriented Programming" ?

reborg12:01:17

Here's a complete TOC

qqq12:01:38

based on the TOC alone, this looks beautiful

qqq12:01:58

it's perfect train/subway reading, when there's 10-15 minutes of downtime, and I want to pick up a few more clojure functions in a "cluster"

reborg12:01:08

Funny you mention that, the book started exactly after me spending commutes learning one function at a time 🙂

qqq11:01:21

It's not "is there a function for that" that concerns me -- most of those are resolved via google clojuredocs + keywords It's "does Clojure have some weird syntactical construct for BLAH" that I have no idea how to reason about.

reborg11:01:20

@qqq yeah it's a shame the book homepage it's not showing the content of the TOC.

reborg11:01:44

about to post a link to the full toc, but essentially, that's my arbitrary classification of the 700+ functions in the stdlib

qqq11:01:10

@bronsa: that's clever, if one can mentally simulate the clojure parser, it's a good "spec" for "what features does clojure support"

qqq11:01:15

TIL #: and #::

bronsa11:01:45

those are new in 1.9

crankyadmin12:01:31

Hi, I have a lump of code that looks like this: https://gist.github.com/crankyadmin/a3db5b5429dde419aff87a0875f259e1 but I have a feeling there is a better way of doing it, Take the first example, its parse-*second* then time/*second*. Is it macros I’m looking for?

genmeblog12:01:06

macro is ok, you can also utilize partial or multimethod

qqq12:01:20

(let [f (fn [g] #(str (g (time-coerce/from-string %))))]
  (def parse-second (f time/econd))
  (def parse-minute (f time/minute))
  (def parse-hour (f time/hour))
  ...

  ) 
@crankyadmin

bronsa12:01:33

no need for macros

crankyadmin12:01:08

Ah! Thats perfect. Thanks 🙂

genmeblog12:01:57

(defn- parse-anything [f time-string] (str (f (time-coerce/from-string time-string))))
(def parse-second (partial parse-anything time/second))

crankyadmin12:01:30

Thats concise! Thank you!

Ryan Radomski12:01:45

Is there a core library function for (drop n (drop-last n coll))?

qqq12:01:58

if coll is a vector, maybe (subvec coll n (- (count coll) n)) ;; not tested, probably off by 1

spacepluk13:01:42

is anybody using vim-fireplace with figwheel? I used to be able to use it with :Piggieback (figwheel-sidecar.repl-api/repl-env) but it doesn't seem to work anymore.

mbjarland13:01:02

general open source question: if a project is stale (4+ years since last commit) and the maintainer of the project does not seem to be active anymore (no activity for the last few years), I created a pr a number of months ago and things seem to be dormant. Assuming I want to be a good member of the community and not step on anybodys toes etc, what's the correct way to proceed from here? Project is under epl. I can of course rewrite the entire thing myself from scratch (it's a one pager), but would have preferred to contribute. I need the result in another downstream project I'm working on. Tried contacting the maintaner but the email bounced. Opinions and ramblings welcomed...

mpenet13:01:16

fork, change maven coords and you're good to go

chris13:01:18

you tried

mbjarland13:01:27

ok, so just forking and renaming is not considered bad mojo?

mbjarland13:01:54

@chris right, that's kind of where I'm at right now

cvic13:01:04

If the project is dead, nah. It's totally ok. But just preserve the copyright / license

nulligor13:01:45

well, if its that simple you could just rewrite it into a different project and give props to where u got the inspiration from

nulligor13:01:55

or maybe I'm just an asshole

mbjarland13:01:13

@igor.larcs : ) yeah I was going down that route and felt a slight twinge of asshole-ness...why I asked the question here

mbjarland13:01:20

@chris @mpenet @cvic @igor.larcs ok, thanks for the input - I consider the question answered

grav14:01:13

From a performance view-point, what would be the most optimal? (->> my-coll (pmap expensive-fn1) (pmap expensive-fn2)) versus (->> my-coll (pmap (comp expensive-fn2 expensive-fn1)))?

schmee14:01:56

The second one avoids allocating an intermediate sequence so it’s preferable

schmee14:01:38

you might want to check out reducers as well, they have better performance than pmap IIRC https://clojure.org/reference/reducers

grav14:01:37

Cool! Regarding allocating an intermediate sequence, isn’t this what transducers are supposed to avoid? What do they solve that isn’t solved with comp?

schmee14:01:12

you actually use comp to compose transducers, just like functions

schmee14:01:41

transducers have some additional conventions around early termination and stuff, but other than that they are indeed ordinary functions 🙂

schmee14:01:14

have you seen Hickey’s transducer talk?

Alex Miller (Clojure team)14:01:57

As a wise man named Rich once told me, “why guess when you can measure?”

grav14:01:58

No haven’t seen it yet. It’s on my todo 🙂

grav14:01:04

@alexmiller Good point. I guess my problem is that expensive-fn1 is much slower that expensive-fn2 so I’m not sure I’d see a difference at all with a low n.

grav14:01:25

Anyway, thanks for the pointer. I guess I’ll get back to measuring the performance 😉

itaied17:01:11

I'm trying to use shrubbery mocking library, which is using reify, but I'm getting IllegalArgumentException. I think I'm missing something, but I can't find what. Would someone may take a look please? https://github.com/bguthrie/shrubbery/issues/14

ag22:01:16

so, can someone explain why 1.9 has seqable? now, how is it different from seq?

ag22:01:29

which should be used when?

seancorfield22:01:11

Have you looked at the docstrings? They seem self-explanatory...

seancorfield22:01:18

seq? just checks if its argument implements ISeq, i.e., it is specifically a "seq"; seqable? checks if it's argument can be coerced to a "seq" (via the seq function)...

andy.fingerhut23:01:27

e.g. seqable? is true for vectors and maps, because calling seq on them does something useful and expected, whereas seq? is false for those types of objects

andy.fingerhut23:01:03

I am not imaginative enough to come up with use cases where I would want seq?, but I have used seqable?

Alex Miller (Clojure team)23:01:09

seq? Is for things that are seqs. seqable? Is for things that can provide seqs

erhardtmundt23:01:45

I have a web app written in clojure behind a reverse proxy and I was just wondering if the app should be aware of its root url or if I can configure the proxy so it will rewrite them for me

jgh23:01:22

if you’re using nginx you can pretty much rewrite the url however you need it

erhardtmundt23:01:45

I’m using Apache at the moment but I’ll migrate soon

hiredman23:01:03

it has been my experience that rewriting will break badly eventually

erhardtmundt23:01:35

so basically I have /foo that should actually be /app/foo

noisesmith23:01:14

would rewriting the url in the ring request map be an option? or providing the prefix as a config

erhardtmundt23:01:40

it would certainly be, but if having it in the proxy is possible and not a bad practice, I’d rather have it there

erhardtmundt23:01:56

just not to spread this all over and have it contained in the proxy config files