This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-06
Channels
- # alda (3)
- # beginners (109)
- # boot (24)
- # cljsrn (17)
- # clojure (41)
- # clojure-brasil (2)
- # clojure-china (1)
- # clojure-russia (19)
- # clojure-spec (9)
- # clojure-uk (5)
- # clojurescript (44)
- # cloverage (5)
- # core-async (3)
- # css (2)
- # datascript (6)
- # datomic (26)
- # emacs (2)
- # events (10)
- # hoplon (24)
- # lambdaisland (1)
- # om (2)
- # onyx (16)
- # other-languages (10)
- # proto-repl (2)
- # re-frame (14)
- # spacemacs (2)
- # untangled (4)
- # videos (1)
@ag, a pattern I use is (filter #(-> % :id (= needle)) coll)
works nicely, especially if you build up an expr from the repl
@ag: with the specter library (which is really great for working with nested data like that), (select-any [:customers ALL #(= (:id %) id-arg)] cs)
oh yes, I have to get into specter
So I’m playing around and trying to implement my own Jupyter Kernel. I see the Clojupyter implementation sets up a repl server to handle all code execution (https://github.com/roryk/clojupyter/blob/master/src/ipython_clojure/core.clj#L260-L270).
I’m trying to understand what the the advantage of this is vs just using clojure.core/read-string
and clojure.core/eval
. I would assume it’s for security reasons, but does an nrepl server actually deliver a sandbox experience?
I'm trying to make a custom sorter key for max-key
and I am getting a confusing error.
(def foo [{:a 5, :b [1 2 3 4]} {:a 5, :b [1 2 3]} {:a 2, :b [1 2 3 4 5 6 7]}])
(apply max-key (juxt :a (comp count :b)) foo)
I'm trying to make a custom sorter key for max-key
and I am getting a confusing error.
(def foo [{:a 5, :b [1 2 3 4]} {:a 5, :b [1 2 3]} {:a 2, :b [1 2 3 4 5 6 7]}])
(apply max-key (juxt :a (comp count :b)) foo)
ClassCastException clojure.lang.PersistentVector cannot be cast to java.lang.Number (Numbers.java:229)
ohh. it's not because of the (comp count :b)
like I thought, max-key
won't sort vectors.
I've been hard at work on this Guerrilla Guide to using Clojure at your job: https://purelyfunctional.tv/courses/introducing-clojure-to-the-enterprise/
Is there a better way to initialize a clojure vector of k items all with the same value than
(let [k 10
initialization-val 0]
(->> (range k)
(mapv (constantly initialization-val))))
@mjhamrick: e.g.: (vec (repeat 10 0))
?
@anmonteiro: That works too. I'm wondering in particular if there's anything better than calling vec on a seq. Thinking about it more, I don't know how there could be a better way to do it.
Sorry, that’s a bad comment. The result is actually (true true true true)
as expected.
mjhamrick: (vec (repeat 10 0))
is the fastest way I can find (and most concise).
@weavejester: @anmonteiro Thanks.
I’d like to interleave to collection that might differ in length (one might be 1 element bigger than the other). Is there a recommended way to do that? interleave
drops the last element in the largest collection. I’d like (interleave-all [1 2 3] [4 5 6 7]) ;;=> [1 4 2 5 3 6 7]
.
thanks @gfredericks - I’ll need to look at that for a while to understand what’s happening 🙂
oops I used the wrong thing on the last line
it still works that way it's just dumber
I was thinking about a solution where the cols are padded to max length and the using (mapcat concat col1 col2)
or something similar 😛 Maybe it’s actually more readable to use if
and append the remaining element after using regular interleave
😛
if you pad them then how do you remove the padding elements later?
you don't want to drop nil
s because there might be nil
s in the original collections