Is it possible to remove one key from map with meander?
I know I can rewrite all keys except one, but with a large number of keys this doesn't sound like a good solution
(m/rewrite {:a 1 :b 2 :c 3}
{:a _ & ?rest}
?rest)
;; =>
{:b 2, :c 3}
Like this?This almost compiles to (dissoc m :a)
Looks cool, but also doesn't seem to scale well for more operations
In what way? Maybe I can help.
I will give you an example, 1s
I’ve been staring at something else all day and I want an excuse to look at something else. 🙂
Errr, that was redundant but I think you know what I’m saying.
1s?
OH. YOU MEAN ONE SECOND.
😂
(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}
let's say I want to remove the keys from :swap/dissoc
By “scale” you mean in terms what you must write?
yes
Gotcha
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.Note I’m using &
on the left not :as
.
But maybe there is a reason you’re using :as
and not &
?
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 know that concision is important to people.
it's still awesome
I feel a little bad because I’ve been hacking on zeta
. If I don’t do it though, I’ll never release it.
specter never clicked in my head, using meander is much easier and more enjoyable
Ah, thanks. That kind of support keeps me motivated to work on it. 🙂
I am waiting for the zeta impatiently and with flushed face
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.
Hell, I enjoy seeing what people make with it and noticing the same thing!
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.
I think having explanations will be a game changer for the library. 🤞
Haha! Yes!
That happens to me. 😐
what do you mean by having explanations
?
Anyway, I'm keeping my fingers crossed for zeta
, but I have to go
thanks again for the tip
I mean that it will be possible to get an explanation for why a rewrite failed.
This is useful for even small systems but becomes much more valuable as the system grows especially when cata
is involved.
cider debugger is an invaluable help, especially when it comes to cata