This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-18
Channels
- # beginners (56)
- # boot (1)
- # cider (96)
- # cljs-dev (148)
- # clojure (60)
- # clojure-austin (11)
- # clojure-france (2)
- # clojure-italy (5)
- # clojure-russia (11)
- # clojure-spec (31)
- # clojure-uk (5)
- # clojurescript (52)
- # community-development (37)
- # cursive (3)
- # data-science (8)
- # datomic (14)
- # devcards (2)
- # emacs (1)
- # fulcro (13)
- # hoplon (1)
- # immutant (2)
- # luminus (3)
- # off-topic (2)
- # onyx (16)
- # parinfer (38)
- # re-frame (8)
- # reagent (5)
- # shadow-cljs (332)
- # spacemacs (5)
- # specter (5)
- # sql (6)
- # vim (52)
if you care about performance, you can convert the stacked maps to a singe function via map/comp
(map (comp str/lower-case (partial apply str) (partial apply concat))
also, collection functions will be a lot slower than string functions - though I'm sure the code would be less aesthetically pleasing
This code will be run remarkably seldom. It just feels like there shouldn't be quite so much going on here.
also partition is going to drop the last item on odd numbered inputs
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.
But that's just making 2 collections for no reason
user=> (partition 2 [1 2 3 4 5])
((1 2) (3 4))
it's making two collections, and dropping the last element if the count is odd
also why no transducers?
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?
if performance doesn't matter there's hardly a point, I don't know that they'd improve the code
regarding your partition bug, just use partition-all it does what most people intuitively expect partition to do
@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
@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
Won't get get much simpler than a regex 😉
@sundarj I think that's generally pretty good advice. Normally I would, but this seemed like it should have been so atomic
I think so
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
For what it's worth, this is what I had in some other libraries I have:
(defn camel->kabob [from]
(let [s (string/split (name from) #"(?=[A-Z])" )]
(apply str (interpose "-" (map string/lower-case s)))))
lol, and I just now saw what you posted
yours works with pascal case as well
And btw, if you ever get concerned about performance at all, do this first
(alter-var-root #'camel->kabob memoize)
That'll turn it into a memoized function with the overhead of a hashmap lookup.
Can cause problems if you're doing this on randomly generated strings, but aside from that it just works
I was considering memoizing it actually, I'm cataloging an API so there's a lot of repeats
thanks for the pointers
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"
also you don't need to keywordize (let [{:strs [width height]} (js->clj dims)] ...)
the question seems to have been deleted
oh - it's still there, asked by Zeff
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
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.@U051SA920 It's not used anywhere, by any transducing context?
it's +
that gets called with no args by transduce
which returns 0, an apropriate initial value
The jira ticket for fixing this was declined https://dev.clojure.org/jira/browse/CLJ-1569
My question is then: Why on earth do we have to implement the zero arity if it's not supposed to be used anywhere?
it also works without, until it doesn’t and then you find out why… dynamic typing 🙂
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])
@U054W022G this is the required 0-arity reduce function, but how does this relate to the 0-arity transducer function?
yes @U04V15CAJ sorry, I misread the thread.
somewhere I read that it was idiomatic in Clojure to take a single map as an argument and to return values in maps too.
Can anyone point me at some reading related to these ideas? I know I can build nice pipelines all of sudden.
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
Swagger code gen allows you to create a clojure client from a swagger, why not a server?
How could you generate a server reliably? AFAIK Swagger only specifies how the data is shaped, not show it is computed