Fork me on GitHub
#meander
<
2020-07-26
>
ikrimael15:07:53

+1 on group by; @jatkin how're you using m/gather? i couldn't get it to work the way i thought it would (i.e. with maps)

JAtkins16:07:04

(m/search [{:a :whatever :b [{:n 1} {:n 2} {:n 1}]}
             {:a :goes :b [{:n 1} {:n 2} {:n 4}]}
             {:a :here :b [{:n 2} {:n 2} {:n 3}]}]
    (m/scan {:a ?a :b (m/gather {:n !n})})
    {:a ?a :n !n})
This did an ordered powerset of n

🤯 1
ikrimael16:07:05

imho, that's a great candidate to go into the cookbook

JAtkins16:07:36

Sure - only thing is I don't fully grok why this did what it did

ikrimael16:07:51

haha, neither do I. i'm playing with it right now

jimmy16:07:28

The gather there wouldn't be necessary. On my phone but you should be able to do [pattern ...]

JAtkins16:07:43

Yup, you are right

jimmy16:07:00

Gather is filter for pattern matching. Given a pattern it will go through a sequence and find all the elements that match ignoring the others.

ikrimael16:07:29

can you elucidate on how this is different than the "normal" way? ex: [ (m/app bla) ...] or [pattern ...] also is it meant to be used with maps?

jimmy16:07:01

It is used on seqables. Gather is often used with pred. So you could use gather with (m/pred even?) To gather up all the even numbers. Where as doing it with ... would require everything to be an even number.

jimmy16:07:41

Gather has a (m/or pattern _) inside it. It does a little bit more than that though to handle more advanced repeat cases.

ikrimael16:07:04

i think i'm missing something bc i'm still seeing it as (gather (pred even?) == syntactic sugar for [(pred even?) ...] ?

ikrimael16:07:48

except with the latter, that form also allows for dealing with maps

jimmy16:07:06

Imagine the sequence were [1 2 3]. The former expression would match. The latter would not because they are not all even numbers.

jimmy16:07:58

Gather has nothing to do with maps. It is just matching on seqables using m/seqable

jimmy16:07:34

Gather is almost syntatic sugar for (seqable (or pattern _) ...)

ikrimael17:07:05

👍 ah right right. i keep blurring when things are exhaustive matches vs. not

ikrimael17:07:10

i think i've hit [(pred even?) ...] => not doing what i just thought it did and then replacing it with scan and changing match to find or search until something works 😛

ikrimael17:07:21

caveat: i just recently discover m/map-of and m/submap-of which (correct me if i'm wrong) are the map equivalents for gather

jimmy17:07:24

Yep. That is why I came up with gather. I found myself doing the same thing and realized most of the time I wanted a simple filter.

ikrimael17:07:59

(btw, i've added all this info to the cookbook so it'll be in a PR in a week or so)

👍 2
JAtkins16:07:19

Oh --- and that's how I got a powerset

JAtkins16:07:42

well, got 2 things to add now

ikrimael18:07:07

------------------ ah, also one more addition: i think it'd be great if there was a m/gather for maps e.g. if m/submap-of can be used with :as to capture the result of the submap filter

👍 1
noprompt20:07:12

At the time map-of/`submap-of` was added, the inverse of this was suggested e.g. a way to capture the part of that map that didn’t match. I think both are useful and supportable. From my point of view this is yet more support for the idea that “folds”, as I have discussed them, are primitive and relevant i.e. these two problems are symptoms of the same underlying condition which is that we do not have a way to bind with reduction. Binding, in theory sense, is a sort of reduction operation that can fail. Logic variables bind values when they are unbound and fail when an attempt is made to bind them to a logically inequivalent value. Memory and mutable variables always bind. It makes sense [to me] that reduction be exposed to allow for binding to be rich and powerful.

👍 1