This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-07
Channels
- # announcements (7)
- # asami (3)
- # aws-lambda (2)
- # babashka (10)
- # beginners (30)
- # bristol-clojurians (3)
- # calva (13)
- # cider (26)
- # clj-kondo (6)
- # clojure (172)
- # clojure-europe (30)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-serbia (9)
- # clojure-uk (64)
- # clojurescript (76)
- # conjure (9)
- # cursive (46)
- # data-science (1)
- # datomic (6)
- # emacs (13)
- # etaoin (1)
- # fulcro (27)
- # girouette (4)
- # jobs (1)
- # joker (2)
- # lsp (7)
- # malli (19)
- # meander (47)
- # off-topic (123)
- # pathom (6)
- # reitit (3)
- # remote-jobs (7)
- # reveal (37)
- # ring-swagger (2)
- # shadow-cljs (60)
- # specter (5)
- # startup-in-a-month (3)
- # tools-deps (21)
- # vim (4)
I know I can rewrite all keys except one, but with a large number of keys this doesn't sound like a good solution
I’ve been staring at something else all day and I want an excuse to look at something else. 🙂
(m/rewrite {:a 1 :b 2 :c 3 :d 4 :e 5}
{:a ?a :b ?b :c ?c :d ?d :as ?m}
{& ?m
:a ~(+ ?a ?b)
:b :swap/dissoc
:c ~(+ ?c ?d)
:d :swap/dissoc
:e :swap/dissoc})
;; => {:a 3, :c 7}
there is a NONE
in the specter that can be used to remove keys or other items and overall it useful
I guess I would have written it as
(m/rewrite {:a 1 :b 2 :c 3 :d 4 :e 5}
{:a ?a :b ?b :c ?c :d ?d :e _ & ?m}
{:a ~(+ ?a ?b)
:c ~(+ ?c ?d)
& ?m})
;; => {:a 3, :c 7}
(grabbing the :e
) but I see what you mean.actually there's no reason, that's the way I used to write, but I'm about to check what's faster and to what code it expands
Cleaning up all the nested let
s its roughly
(let [R__37813 (let [TARGET__37806 {:a 1, :b 2, :c 3, :d 4, :e 5}
T__37811 (.valAt TARGET__37806 :e)
T__37810 (.valAt TARGET__37806 :d)
T__37809 (.valAt TARGET__37806 :c)
T__37808 (.valAt TARGET__37806 :b)
T__37807 (.valAt TARGET__37806 :a)
?a T__37807
?b T__37808
?c T__37809
?d T__37810
T__37812 (dissoc TARGET__37806 :a :b :c :d :e)
?m T__37812
form__28292__auto__ {:a (+ ?a ?b), :c (+ ?c ?d)}]
(merge (into {} ?m) form__28292__auto__))]
(if (meander.match.runtime.epsilon/fail? R__37813) nil R__37813))
The into
bit there is slightly annoying because the epsilon compiler isn’t smart enough to know ?m
is a map.
Thanks for the advice, your way is indeed much faster, which after a bit of thought is pretty much obvious.
I’ve been thinking that what might satisfy people is to allow map keys to be extensible.
I feel a little bad because I’ve been hacking on zeta
. If I don’t do it though, I’ll never release it.
Well hopefully it doesn’t take much longer. I spent a lot of time experimenting working to come up with something that could address all of the things people have asked for in terms of programmability and explainability.
The past month has been mostly on writing a lot of tests and organizing the project.
the nice thing about meander is that it doesn't so much describe individual actions, in which we can get lost, but it describes exactly the structure you have and the one we want, this allows you to figure out what the code is doing in a blink of an eye even after a long time
100% the intended result and it makes me happy that I’ve heard this from many people.
This is basically the opposite of all the automatic ways, which after some time become completely incomprehensible and we don't know what they really do and what the author had in mind.