This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-08
Channels
- # admin-announcements (2)
- # beginners (35)
- # boot (353)
- # capetown (1)
- # cider (1)
- # cljs-dev (41)
- # cljsjs (3)
- # cljsrn (3)
- # clojure (118)
- # clojure-austin (12)
- # clojure-russia (17)
- # clojure-spec (21)
- # clojure-taiwan (1)
- # clojure-uk (91)
- # clojurescript (80)
- # clojurex (1)
- # cloverage (3)
- # datomic (66)
- # devcards (2)
- # events (2)
- # garden (6)
- # hoplon (54)
- # jobs-rus (1)
- # keechma (1)
- # lein-figwheel (4)
- # leiningen (3)
- # luminus (3)
- # off-topic (7)
- # om (4)
- # onyx (53)
- # other-languages (17)
- # proton (7)
- # protorepl (4)
- # re-frame (123)
- # reagent (1)
- # ring (6)
- # rum (2)
- # spacemacs (1)
- # specter (21)
- # testing (1)
- # untangled (1)
- # yada (42)
There are cases where it is important to load one piece of code before another (for example installing multi method or protocol impls before use) but generally most code is not that sensitive
system 0.3.1 is out and here is the official announcement. https://groups.google.com/forum/#!topic/clojure/Td4-b8gDL58
Why is this failing with Map literal must contain an even number of forms
? http://sprunge.us/jWCT
How can I transform
{:a [1 2 3] :b [3 4]}
to
[{:k :a :v 1} {:k :a :v 2} {:k :a :v 3} {:k :b :v 3} {:k :b :v 4}]
simply?(->> {:a [1 2 3] :b [3 4]}
(mapv
(fn [[key vals]]
(mapv #(hash-map :k key :v %) vals)))
(flatten)
(vec))
Something like this:
(reduce (fn [acc [k v]]
(reduce (fn [acc' v]
(conj acc' {:k k :v v}))
acc
v))
[]
{:a [1 2 3] :b [3 4]})
I prefer @levitanong 's version.
@niwinz ās version is likely more efficient though.
A little benchmark:
user=> (time (dotimes [i 1000] (levitanong)))
"Elapsed time: 7.857729 msecs"
nil
user=> (time (dotimes [i 1000] (niwinz)))
"Elapsed time: 0.712184 msecs"
^ this
@doglooksgood: flatten is an inherently slow operation. My code goes through the vector at least thrice. @niwinz ās builds a new vector as he proceeds through the reduce
.
so he only goes through the input data once
@syk0saje ās code is the most elegant though, imho. I completely forgot about for
.
I like it too. It's pretty readable. Only part that can give the reader pause is v (% k)
Someone should make a slack bot that can evaluate the efficiency of pasted code like what @niwinz is doing. š
btw, if you really care about benchmarks you should use https://github.com/hugoduncan/criterium
Is it possible to require multiple namespaces into the same alias? e.g both com.rpl.specter and com.rpl.specter.macros as specter
also asked this in #C0A5GSC6T, but maybe someone here knows: in a StreamableResponseBody (ring 1.6.0-beta4), can I somehow detect that the client has closed the http connection, and then stop writing a response?
https://docs.oracle.com/javase/7/docs/api/java/io/OutputStream.html#write(byte[],%20int,%20int) dunno, but the docs say output streams throw an exception if closed
thanks, that might be it. I didn't notice an exception when continuing to write a response for an already closed connection, so maybe the outputstream isn't properly closed by ring yet
it's a good question for @weavejester
also what happens (and how to detect) if a client "disconnects" before the response is sent in async response
there's a error handler actually, maybe you can use this detect it and stop writing to the responsebody
now that I'm doing better async handling in my StreamableResponseBody, I do get an IOException when trying to write. is there a way to trigger it without actually writing something?
Someone can help me in off-topic channel? its about postgres triggers
Havenāt played with clojure.spec as much as Iād like yetā¦ but Iāve got a feeling that it could be used to solve this: https://medium.com/@jamis/weekly-programming-challenge-2-33ef134b39cd#.2sx7h4cme ā would you agree?
another problem with ring 1.6.0-beta4: it seems that my handler with a StreamableResponseBody gets called over and over again with the same request (with maybe 20 seconds in between), even though the original client has already quit
i'm at a crossroads in my architecture of a solution to a problem, would it be off topic to ask for guidance about how to proceed here?
not off topic IMO
I'm making a game in clojure. I'm trying at all costs to avoid having "types" because I think they create complexity, but I'd like to test that by making a game without types to see
Right now I have every entity as just a "bag" (a map), and these are stored in arbitrary order in an array
for instance, (comp (map gravitated) (map scaled) (map located) (map positioned) and so forth
but now I'm thinking about how to handle collision handling with a map and I feel like i've hit a roadblock
take for instance a rubber ball bouncing on the ground-- the map would have to "handle" the collision for both the ball and the ground. The ground would just be mapped to the ground again. The ball would be mapped to a new ball that is relocated as it would need to be given the fact that it is bouncing
@bcbradley: if the ball has properties that, in your model, determine that the ball is bouncy, e.g. {:mygame.physics/bounding-box [ ...coordinates... ]}
, you could write a predicate (defn bouncy? [entity] (entity :mygame.physics/bounding-box))
i feel like that would end up creating scenarios in which adding a property might cause unintended side effects
I tried dispatching to entity specific 'handler' code, but that isn't working out all that well
because the collision handling itself seems to be a problem who's semantics depends on atleast two entities, not just one
you could prevent unintended side effects from handling by using namespaced properties and having a clear policy per namespace
for curiosity sake, lets suppose I rephrase the question: if you had to develop a function that would serve a map over the entities in an array and who's purpose was to take an entity as input, and return either the same entity or slightly different one as output so as to "handle" collisions for that entity (collisions being a key associated with a set of other entities), how would you write such a function?
I'm asking for your opinion here-- you could do it the most straightforward way possible
but these approaches each have strengths and weaknesses-- i'm asking what you FEEL would be the best approach
wouldn't map over the entities one-by-one, since one collision probably impacts two entities
I'd probably call (swap! state (assoc :entities #(-> % handle-collisions handle-health handle-points)))
15 times per second
with (defn handle-collisions [entities] (let [all (filter collides? entities)] ...handle collisions...))
etc
how would you determine what the functionality should be for the "handle collisions"?
do you just have one enormous "handle collisions" function that knows how to interpret entities?
do you defer to the entities themselves to provide "pieces" of the functionality, and then compose them?
you can't compose functionality from each entity separately because the semantics of collision handling is such that it depends on at least two entities in the general case, and thats not the same as the composition of a function on one entity with another function on another entity
Hi everyone -- I'm the Open Source Evangelist at Zalando(.com), and we've got a few open-source projects to offer the community: Friboo (https://github.com/zalando/friboo), a utility library to write microservices in Clojure, with support for Swagger and OAuth; and cats.match (https://github.com/zalando/cats.match), pattern matching for the monads in the cats Clojure library. Let me know if you have any feedback/suggestions for the projects, and I'll pass it along to the devs who created them ...
Is it possible/desirable to modify atoms new value in its watcher function?
not possible
unless you want to just swap!
it again, which feels silly
I was just thinking this morning about the idea of wrapping reference types so you can tweak the writes/reads
I'm curious how easy that is
a question for juxt
(sort-by (juxt second first) [[4 2] [3 2] [2 3]]) ;;; ([3 2] [4 2] [2 3]) but I want ([4 2] [3 2] [2 3])
if I want second func keep in increment order, but the first func in descrement order. how can i do that?Sorting descending on numbers is sorting ascending on negā¦ yeah, what @tap said
so the "official" way to do this is to reverse the comparator:
(sort-by key-function (fn [a b] (compare b a)) collection)
shouldāa had flip
https://www.haskell.org/hoogle/?hoogle=flip
The negative trick also fails in the very rare scenario of Long/MIN_VALUE, whose negation is itself if the result is also a Long
reversing order of args in the comparator is far preferable to avoid subtle bugs
@slipset: We have a flip
in our "util" namespace at work for exactly that reason šø
flip
is one of those functions that you write once for a specific thing and then realize you can use it all over the place
Using clojure-1.9.0-alpha10, is is possible to print without the reader macro? For example:
;; what currently prints
(println {'myns/foo 1})
#:myns{foo 1}
;; what i want to print
(println {'myns/foo 1})
{myns/foo 1}
The use-case is I am spit
ing a map that has a fully qualified symbol to a .edn
file which will be read later. When reading the .edn
file, the symbols are no longer symbols due to the conversion into a reader macro.
I don't understand that last sentence
what are the symbols if they aren't symbols?
my guess is, he is reading it in will something that doesn't support the new namespaced map syntax
I saw a jira issue to provide some way to turn namespaced maps off, but I am not sure what the status of that is
@gfredericks: Sorry for the confusion. @hiredman's explanation is much better š
@ghadi but Iām still confused how I can differentiate the order rules of functions in juxt if using āofficialā way.
@gfredericks: yep it went in the collection of "broken stuff", as I can't make make it work for some reason. It could be my fault too. I'll probably fork it and try to get to a well polished tool :)
@nilrecurring I'd try upgrading tools.analyzer first
I would love to see it more polished
I get mad at it myself for not working :)
I have a fairly large project at the moment and I would love to see graphically if I should refactor better