This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-20
Channels
- # beginners (106)
- # boot (25)
- # cider (2)
- # cljs-dev (100)
- # cljsjs (1)
- # cljsrn (8)
- # clojure (90)
- # clojure-brasil (1)
- # clojure-dev (7)
- # clojure-greece (2)
- # clojure-italy (4)
- # clojure-madison (1)
- # clojure-russia (15)
- # clojure-serbia (15)
- # clojure-spec (13)
- # clojure-uk (32)
- # clojurescript (88)
- # cursive (19)
- # datascript (13)
- # datomic (32)
- # defnpodcast (1)
- # dirac (43)
- # euroclojure (1)
- # graphql (5)
- # hoplon (11)
- # immutant (1)
- # jobs (6)
- # lein-figwheel (2)
- # liberator (2)
- # luminus (14)
- # lumo (22)
- # off-topic (12)
- # om (9)
- # onyx (49)
- # parinfer (45)
- # precept (4)
- # protorepl (2)
- # reagent (14)
- # ring-swagger (3)
- # sql (1)
- # test-check (58)
- # timbre (3)
- # untangled (86)
interpose
puts an argument between elements in a given collection or string, but is there a way to put this argument also after the last element? For example:
(some-function "a" [:x :y :z])
--> (:x "a" :y "a" :z "a")
+user=> (interleave [:x :y :z] (repeat "a"))
(:x "a" :y "a" :z "a")
How can I merge two sorted-set-by so that they continue to be one? If both use the same comparator
have you tried into?
Works perfectly, thanks @noisesmith !
+user=> (into (sorted-set-by #(compare (:a %) (:a %2)) {:a 0} {:a 1 :b 2}) [{:a 3} {:a -1}])
#{{:a -1} {:a 0} {:a 1, :b 2} {:a 3}}
yeah - np
they don't need to both be the same - it will use the type of the first one
into is extremely powerful - it can also use transducing functions
exactly
or filter it out
or duplicate, or...
user=> (into (sorted-set-by #(compare (:a %) (:a %2)) {:a 0} {:a 1 :b 2}) (filter (complement :b)) [{:a 3} {:a -1} {:a 2 :b 12}])
#{{:a -1} {:a 0} {:a 1, :b 2} {:a 3}}
only adds items that with falsey or missing :b key
where?
that's a literal paste from my repl
filter is not meant to be wrapping the vector at the end
no, it is the second of three args to into
right
victora: https://juxt.pro/blog/posts/vim-1.html A bit of an overview of the tools I use & know of
I use vim-clojure-sexp and with the =-
indents the current top level form
that's the correct indentation
Any plugins/stuff you recommend? I couldn't get the REPL to work inside vim. Is it worth it?
fireplace is OK but I don't use it much
for indenting, there's a lein plugin called cljfmt that will fix stuff most editors don't (including whitespace stuff)
@noisesmith you told me some days ago that if I need to carry variables during a reduce
then I should use a map. Is there any canonical name for this map?
accumulator or acc for short
or you can just destructure it inline to get the keys out of the function arg (reduce (fn [{:keys [count found blacklist]} el] ...) {:count 0 :found [] :blacklist #{}} coll)
count - bad name since that's a function in clojure.core
what is the best way to take an element out of a sequence for assertion purposes. Like if I want (= (my-last [1 2 3]) 3)
to return just 3
instead of (3)
. I'm currently just using first
in front of everything but I'm not sure if that's the best way.
I'm trying to write a macro that generates a deftest
with metadata .... but not sure how to add the metadata ... any help?
@abarylko use vary-meta
?
@lilactown yes the original function already implements something like what I'm trying to do. But notice that I'm doing my own "last" function and would like to get a similar result
here's a very simple recursive implementation:
(defn my-last [[x & xs]] (if (> (count xs) 0) (my-last xs) x))
(defn my-last
[a-seq]
(loop [x a-seq]
(if (empty? (rest x))
(first x)
(recur (rest x)))))
Hi, what do you think could I find somewhere a “html -> image rendering” library/ repository?
Hi guys, I'm brand new to cljs, any recommended tutorials? This looks good https://github.com/magomimmo/modern-cljs/, I am a pretty decent programmer with small amounts of functional programming experience (mostly Haskell though), and am looking at cljs for webdev. Any advice would be greatly appreciated 🙂 (I'm looking forward to diving in deep)
jasoons: Luminus has good docs, wouldn't really call it a tutorial, but you might be able to follow along and pick up a thing or two
Luminus is a template, or micro framework. I like to recommend it to beginners, even though there's quite a lot to it.. but you get started quickly with a solid base to build on 🙂
@mathew.vijay I’ll try that, thanks ….
@jasoons would you like to try https://github.com/minimal-xyz?utf8=%E2%9C%93&q=shadow-&type=&language= ?
or more specifically https://github.com/minimal-xyz/minimal-shadow-cljs-browser
@U0CKCLN00 Great thanks 🙂 I'll take a dig at it!
this is how you compile ClojureScript. to try an app, you will need http://reagent-project.github.io , also #reagent
Hi guys, any really good and easy to understand material on core.async out there, I would appreciate some some links or so...
how about this? http://ku1ik.com/2015/10/12/sweet-core-async.html
I found this helpful when I was first learning about core.async: http://www.braveclojure.com/core-async/
I am having real problems getting a post body payload with compojure. Can somebody give me a quick hand?
guy: How can i quickly transform a HttpInput which is a json payload to clojure's data structures?
Potentially you might want to use something like this https://github.com/ring-clojure/ring-json
https://github.com/weavejester/compojure-example/blob/master/src/compojure/example/routes.clj
I've been trying to use ring-json and ultimately failing. Let me try again with this example, brb
I'm using ring-json and it helps, but I couldn't make it give me the json parsed. Since this project is time-sensitive, I ended doing the workaround since it wasn't so ugly and dedicated myself to another part
Has anybody ever received this error?
No implementation of method: :kv-reduce of protocol: #'clojure.core.protocols/IKVReduce found for class: clojure.lang.ArraySeq
what were you trying to do when you got it?
it means that something was trying to update a hash-map and got an array
noisesmith: this is one of the function arities, it’s a bit of a mess but I’m trying to persist two arrays that need to be updated so I’m sending them in a map:
([graph] (let [distances (adjacency-matrix graph)
vertices (get-vertices graph)
parents (parent-matrix distances)]
(reduce-kv (fn [acc intermediate-idx _]
(reduce-kv (fn [_ start-idx row]
(reduce-kv #(floyd-warshall acc intermediate-idx start-idx %2) {} row))
{} distances))
{:distances distances :parents parents} vertices))))
right, reduce-kv needs a hash-map as its last arg
and you seem to be giving it an array, that’s simply not valid
why not use reduce? it looks like what you really want is reduce with two accumulators, which is easy to do with destructuring and a vector literal
yeah, good point. I’m just using the indices, so I should really just reduce over a range
. Thanks !
:thumbsup:
yourkit is better, but also not free (though they have a policy of donating it to significant open source projects)
and laziness makes some of the results counterintuitive (things show up under the code that realized the collection, not the code that created it - so eg. “rest” will show up as something taking a lot of time)
thanks. i looked at taoensso/tufte
, and thought it didn't suit my needs, because it doesn't look like it can walk the tree of expressions and show hotspots. i'll try visualvm to start with, and keep in mind your tip. thanks again!
last I checked there was a free preview of yourkit too
@mfm also, once you have narrowed down your hotspots with your profiling tool, criterium is the best library for measuring your improvements to the hotspot function