This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-15
Channels
- # beginners (34)
- # boot (45)
- # cider (16)
- # cljs-dev (20)
- # cljsjs (1)
- # cljsrn (8)
- # clojure (207)
- # clojure-berlin (3)
- # clojure-dev (18)
- # clojure-greece (1)
- # clojure-ireland (1)
- # clojure-italy (9)
- # clojure-russia (20)
- # clojure-spec (27)
- # clojure-uk (19)
- # clojurescript (110)
- # code-reviews (2)
- # cursive (7)
- # data-science (2)
- # datomic (7)
- # devcards (1)
- # emacs (4)
- # graphql (1)
- # hoplon (2)
- # immutant (15)
- # jobs (5)
- # jobs-rus (1)
- # juxt (1)
- # luminus (7)
- # lumo (26)
- # microservices (3)
- # off-topic (27)
- # om (13)
- # onyx (11)
- # pedestal (7)
- # proton (4)
- # re-frame (24)
- # remote-jobs (1)
- # spacemacs (2)
- # specter (2)
- # unrepl (31)
- # untangled (7)
- # vim (14)
given a nested map structure like {1111 {:s 0 :r 1}} {1111 {:s 1 :r 2}} I'm trying to use merge-with to give me the output {1111 {:s 1 :r 3}}
check-stock.core=> (apply merge-with (fn [l r] (merge-with + l r)) '({1111 {:s 0 :r 1}} {1111 {:s 1 :r 2}})) {1111 {:s 1, :r 3}}
some might prefer (apply merge-with (partial merge-with +) ...)
I did some heavy manipulation of data structures last week, and I think my main sticking points, or rather ugly pieces left in my code, have been that I often expected a single map entry from a map, or wanted to create one.
In the first case, I would first
the result of a filter
, but I wonder if there's a cleaner way (before implementing a macro myself).
In the second, I am not aware of a neat way of creating a map entry, other than enclosing a tuple in a vector, then stuffing it into a map at some later point in the logic. Other than saying map entries reflect residues of OO thinking, any comments to that?
What do you think?
@matan nothing wrong with stuffing tuples into maps IMO
but I don't really understand this first-filter approach, could you give an example ?
@matan http://weavejester.github.io/medley/medley.core.html#var-find-first I find medley to be the sweet point of "stuff I find myself doing a lot" vs "this stuff is confusing"
@matan 2-entry vectors are capable map entries. at some future point we may have actual tuples (there has been some work done, but retracted, on this in the past).
I have a case where I have many different records which extend a protocol the same exact way. Is there any concise way to do that? stating multiple classes under the extend-protocol
doesn’t seem to work:
(extend-protocol AProtocol
Class1 Class2 Class3
(foo [_] true)
(bar [_] false))
although (extenders AProtocol)
returns (Class1 Class2 Class3)
the extension of the protocol happens only to the last i.e. Class3
. Calling foo
with arguments other than an instance of Class3
results in IllegalArgumentException
@gerry you could write a custom macro and call it repeatedly :)
@alexmiller @dominicm thanks guys, I appreciate it! I just try to retrospect and this has been really helpful. I was otherwise a bit surprised to see some functions not preserving the collection type provided to them, but didn't have time to make a concrete description while at it as I was working towards a specific date.
@dominicm maybe medley will replace my own private evolutionary util lib then 🙂 although with leiningen's support for symlinks it's easy curating a util lib as I go
otherwise as stated here you want a map literal to have the value of a var that has not been introduced. which would be your error i'd imagine
all of this assuming that card looks sufficiently like [rank suit]
to destructure here
Is it possible to give a value multiple tags in edn
? i.e. is {:port #num #env SERVER_PORT}
valid, assuming that I’ve implemented reader functions for both num
and env
?
@mhuerster yes according to the spec https://github.com/edn-format/edn/blob/master/README.md#tagged-elements
I would not call this “multiple tags” - this is a tagged value that contains a tagged value
so “nested tags” perhaps, but not two tags applied to the same value