Fork me on GitHub
#meander
<
2021-04-07
>
ribelo22:04:23

Is it possible to remove one key from map with meander?

ribelo22:04:04

I know I can rewrite all keys except one, but with a large number of keys this doesn't sound like a good solution

noprompt22:04:22

(m/rewrite {:a 1 :b 2 :c 3}
  {:a _ & ?rest}
  ?rest)
;; => 
{:b 2, :c 3}
Like this?

noprompt22:04:16

This almost compiles to (dissoc m :a)

ribelo22:04:43

Looks cool, but also doesn't seem to scale well for more operations

noprompt22:04:11

In what way? Maybe I can help.

ribelo22:04:36

I will give you an example, 1s

noprompt22:04:45

I’ve been staring at something else all day and I want an excuse to look at something else. 🙂

noprompt22:04:12

Errr, that was redundant but I think you know what I’m saying.

noprompt23:04:19

OH. YOU MEAN ONE SECOND.

ribelo23:04:23

(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}

ribelo23:04:02

let's say I want to remove the keys from :swap/dissoc

noprompt23:04:21

By “scale” you mean in terms what you must write?

ribelo23:04:21

there is a NONE in the specter that can be used to remove keys or other items and overall it useful

noprompt23:04:49

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.

noprompt23:04:05

Note I’m using & on the left not :as.

noprompt23:04:37

But maybe there is a reason you’re using :as and not & ?

ribelo23:04:51

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

noprompt23:04:32

Cleaning up all the nested lets 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))

noprompt23:04:50

The into bit there is slightly annoying because the epsilon compiler isn’t smart enough to know ?m is a map.

ribelo23:04:37

Thanks for the advice, your way is indeed much faster, which after a bit of thought is pretty much obvious.

noprompt23:04:38

I’ve been thinking that what might satisfy people is to allow map keys to be extensible.

noprompt23:04:45

I know that concision is important to people.

ribelo23:04:33

it's still awesome

noprompt23:04:37

I feel a little bad because I’ve been hacking on zeta . If I don’t do it though, I’ll never release it.

ribelo23:04:37

specter never clicked in my head, using meander is much easier and more enjoyable

noprompt23:04:10

Ah, thanks. That kind of support keeps me motivated to work on it. 🙂

ribelo23:04:10

I am waiting for the zeta impatiently and with flushed face

noprompt23:04:13

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.

noprompt23:04:53

The past month has been mostly on writing a lot of tests and organizing the project.

ribelo23:04:33

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

noprompt23:04:06

100% the intended result and it makes me happy that I’ve heard this from many people.

noprompt23:04:30

Hell, I enjoy seeing what people make with it and noticing the same thing!

ribelo23:04:08

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.

noprompt23:04:20

I think having explanations will be a game changer for the library. 🤞

noprompt23:04:45

That happens to me. 😐

ribelo23:04:12

what do you mean by having explanations?

ribelo23:04:57

Anyway, I'm keeping my fingers crossed for zeta, but I have to go

ribelo23:04:13

thanks again for the tip

noprompt23:04:28

I mean that it will be possible to get an explanation for why a rewrite failed.

noprompt23:04:03

This is useful for even small systems but becomes much more valuable as the system grows especially when cata is involved.

ribelo23:04:58

cider debugger is an invaluable help, especially when it comes to cata