Fork me on GitHub
#clojure
<
2018-02-18
>
noisesmith04:02:20

if you care about performance, you can convert the stacked maps to a singe function via map/comp

noisesmith04:02:54

(map (comp str/lower-case (partial apply str) (partial apply concat))

noisesmith04:02:20

also, collection functions will be a lot slower than string functions - though I'm sure the code would be less aesthetically pleasing

Ryan Radomski04:02:25

This code will be run remarkably seldom. It just feels like there shouldn't be quite so much going on here.

noisesmith04:02:19

also partition is going to drop the last item on odd numbered inputs

Ryan Radomski04:02:19

It is silly that I don't compose the map functions. For some reason in my head I was thinking no transducers means I have to use threading macros instead.

Ryan Radomski04:02:35

But that's just making 2 collections for no reason

noisesmith04:02:41

user=> (partition 2 [1 2 3 4 5])
((1 2) (3 4))

noisesmith04:02:53

it's making two collections, and dropping the last element if the count is odd

noisesmith04:02:32

also why no transducers?

Ryan Radomski04:02:20

I usually only use them if I want to decompose and recompose the transformations in many contexts or for efficiency. Would they be better here?

noisesmith04:02:50

if performance doesn't matter there's hardly a point, I don't know that they'd improve the code

noisesmith04:02:35

regarding your partition bug, just use partition-all it does what most people intuitively expect partition to do

sundarj04:02:00

@radomski i am dangerously tired so take this advice with caution: what about decomposing the function so you can better ascertain whether the work you are doing is intrinsic to the problem or just an artifact of the way you've written it. it's hard (for me at least right now) to tell what a function is doing vs. what it should be doing when all the work is happening in one place

noisesmith04:02:21

@radomski reading it still - if I'm look at this correctly, the partition followed by concat does nothing that the concat wouldn't do alone, except for the odd behavior of dropping the last item if the input count is odd

tbaldridge04:02:31

Won't get get much simpler than a regex 😉

Ryan Radomski04:02:54

@sundarj I think that's generally pretty good advice. Normally I would, but this seemed like it should have been so atomic

noisesmith04:02:27

I'll admit I've had a lot of marijuana within the last 6 hours, but I'd say the fact that the partition/concat behavior sat that long without anyone jumping on it indicates the code does too many things in one function

tbaldridge04:02:19

For what it's worth, this is what I had in some other libraries I have:

tbaldridge04:02:47

(defn camel->kabob [from]
  (let [s (string/split (name from) #"(?=[A-Z])" )]
    (apply str (interpose "-" (map string/lower-case s)))))

tbaldridge04:02:29

lol, and I just now saw what you posted

Ryan Radomski04:02:39

yours works with pascal case as well

tbaldridge04:02:59

And btw, if you ever get concerned about performance at all, do this first

tbaldridge04:02:18

(alter-var-root #'camel->kabob memoize)

tbaldridge04:02:42

That'll turn it into a memoized function with the overhead of a hashmap lookup.

tbaldridge04:02:59

Can cause problems if you're doing this on randomly generated strings, but aside from that it just works

Ryan Radomski04:02:05

I was considering memoizing it actually, I'm cataloging an API so there's a lot of repeats

Ryan Radomski04:02:16

thanks for the pointers

qqq10:02:00

I'm still trying to find the right size for *.cljc module files; it's currently set at "things that don't annoy me when I do a string search on the buffer"

noisesmith16:02:05

also you don't need to keywordize (let [{:strs [width height]} (js->clj dims)] ...)

madstap17:02:13

That's good advice, but you seem to have posted in the wrong channel

noisesmith17:02:09

the question seems to have been deleted

noisesmith17:02:36

oh - it's still there, asked by Zeff

borkdude17:02:14

curious about the answer to this one: https://stackoverflow.com/questions/48848876/transducers-init-not-called played around with it and the init arity seems not to be called, even when you omit the init value

madstap17:02:08

Yeah, that surprised me as well, but looking at the source for transduce it makes sense.

;; The no init arity of transduce
([xform f coll] (transduce xform f (f) coll))
It doesn't do anything with xform, it just calls the reducing function with no arguments.

rauh17:02:13

IIRC it was for "future use" but it's currently not used.

madstap17:02:16

@U051SA920 It's not used anywhere, by any transducing context?

rauh17:02:45

reading...

noisesmith17:02:47

it's + that gets called with no args by transduce

noisesmith17:02:56

which returns 0, an apropriate initial value

madstap18:02:37

The jira ticket for fixing this was declined https://dev.clojure.org/jira/browse/CLJ-1569

madstap18:02:47

My question is then: Why on earth do we have to implement the zero arity if it's not supposed to be used anywhere?

borkdude18:02:50

it also works without, until it doesn’t and then you find out why… dynamic typing 🙂

reborg20:02:33

As a side effect, it prevents reducef without a zero-arity to work with no init on stdlib xducers: (transduce (map inc) - [1 2 3])

borkdude21:02:08

@U054W022G this is the required 0-arity reduce function, but how does this relate to the 0-arity transducer function?

reborg21:02:02

yes @U04V15CAJ sorry, I misread the thread.

dpsutton17:02:12

can clj upgrade itself?

ghadi18:02:41

no, package manager does that

dpsutton18:02:01

i'm on fedora. had to run the installer script again

triss20:02:43

Hey all. I’m not sure if I imagined this or not…

triss20:02:31

somewhere I read that it was idiomatic in Clojure to take a single map as an argument and to return values in maps too.

triss20:02:13

Can anyone point me at some reading related to these ideas? I know I can build nice pipelines all of sudden.

triss20:02:21

Are there other benifits?

noisesmith20:02:02

one reason that we often take and return hash maps in clojure is that it's common to pass things that would be globals or mutable properties in another language, and instead provide them as arguments, and beyond a certain number of items, a map is a lot more usable

mmer21:02:42

Swagger code gen allows you to create a clojure client from a swagger, why not a server?

val_waeselynck10:02:24

How could you generate a server reliably? AFAIK Swagger only specifies how the data is shaped, not show it is computed

gklijs23:02:48

@mmer probably because it's a bit harder to do then a client. You could use the Java one and use interop.