Fork me on GitHub
#meander
<
2020-08-26
>
yuhan05:08:29

@timothypratley Another idea for #130: extend the familiar & syntax:

{&... [!k !v]}
;; desugars intuitively to 
{& (m/seqable [!k !v] ...)}

;; or

{&!k !v} ;; implicitly includes !v in the repeating pattern

;; or 

{&!k &!v} ;; over-specification? 
There is already precedence in ..?n for splitting a symbol up into components to bind ?n

timothypratley13:08:38

I agree and I like the {&!k !v} notation! That seems very intuitive to me and I like that it doesn’t use metadata. I think this would be really cool and work well!

yuhan05:08:50

This would also apply to sets: #{ &!x } looks better to me than using metadata #{ ^& !x }

timothypratley13:08:46

+1 I think this looks way better than the metadata and I find it clearer about the structure (metadata is always weird because it looks like another element). I think this works still for expression: #{(m/pred int? &!x) &?more} seems possible and very cool 🙂

scarrucciu19:08:29

All, just getting started with meander, and trying to match against a pattern of keys within a map to return in a search. For example

(defn testm [input]
  (m/search input
    (m/scan {(m/re #"LX") ?result})
    {:result ?result}))

(testm {"LX-1" "a" "LX-2" "b"})

scarrucciu19:08:19

where I would want to result to be

({:result "a"} {:result "b"})
is this possible?

chucklehead20:08:15

I think this will do what you want:

(defn testm [input]
  (m/search input
            {(m/re #"LX.*") ?result}
            {:result ?result}))

3
scarrucciu20:08:27

Thank you, if I wanted to nest that part in a broader transformation (say there were other keys that I was applying a transformation to), would you recommend apply different m/search’s and then composing the results?

Jimmy Miller20:08:32

It all depends on what you are wanting to accomplish. You can do other keys as well inside the same search. There is no limitation on that. For example:

(m/search {"LX-1" "a" "LX-2" "b" :x 1 :y 2}
  {(m/re #"LX.*") ?result
   :x ?x
   :y ?y}
  {:result ?result
   :x (even? ?x)
   :y (even? ?y)})

chucklehead20:08:03

I'm fairly new to meander myself, so take anything I say with a grain of salt, but most of what I have been doing is matching/transforming nested maps and I rarely have to use more than one top-level rewrite/search/etc.

scarrucciu23:08:14

thank you, that is really helpful, attempting to translate a bunch of custom transformation base clojure to meander, so very much in the easy stages of understanding what it can do.