Fork me on GitHub
#meander
<
2020-09-28
>
Lucy Wang14:09:02

the beauty of extracting JIRA api response with meander, really ❤️ it

(defn format-issues [issues]
  (me/search issues
    (me/scan {:fields {:summary ?summary
                       :assignee {:displayName ?assignee}
                       :status {:name ?status}}})
    {:summary ?summary
     :assignee ?assignee
     :status ?status}))

❤️ 3
🚀 3
Lucy Wang14:09:58

and now I have too handle some nils ...

(defn format-issues [issues]
  (me/search issues
    (me/scan {:fields {:summary ?summary
                       :assignee (me/or (me/let [?assignee nil]
                                          nil)
                                        {:displayName ?assignee})
                       :status {:name ?status}}})
    {:summary ?summary
     :assignee ?assignee
     :status ?status}))

Jimmy Miller15:09:00

I know you got a nice little defsyntax for this. Just wanted to point out this little and idiom.

(defn format-issues [issues]
  (m/search issues
    (m/scan {:fields {:summary ?summary
                      :assignee (m/or (m/and nil ?assignee)
                                      {:displayName ?assignee})
                      :status {:name ?status}}})
             {:summary ?summary
              :assignee ?assignee
              :status ?status}))

Lucy Wang01:09:27

TIL +1! Thanks Jimmy!

Lucy Wang15:09:19

time for some defsyntax!

(defn logic-variable? [x]
  (and (symbol? x)
       (str/starts-with? (name x) "?")))

;; (logic-variable? '?x)
;; => true

(defn extract-logic-variables [m]
  (sp/select (sp/walker logic-variable?) m))

;; (extract-logic-variables '{:a ?a :b ?b :c "?c" :d :?d})
;; => [?a ?b]

(me/defsyntax maybe-map
  [m]
  (if (me/match-syntax? &env)
    `(me/or
       (me/let ~(->
                 (extract-logic-variables m)
                 (interleave (repeat nil))
                 vec)
         nil)
       ~m)
    &form))

(defn format-issues [issues]
  (me/search issues
    (me/scan {:fields {:summary ?summary
                       :assignee (maybe-map {:displayName ?assignee})
                       :status {:name ?status}}})
    {:summary ?summary
     :assignee ?assignee
     :status ?status}))

Lone Ranger15:09:03

I'm curious, has anyone put any thought into a symbolic syntax for Meanderlang?

Lone Ranger15:09:31

The two closest cousins I can find are Dyalog APL and the mathematical field of topology

Lone Ranger15:09:41

Or maybe those things like me/scan macroexpand into a more verbose data literal syntax?

noprompt21:09:38

@U3BALC2HH Yes. me/scan essentially expands to

(m/seqable _ … p1 ,,, pN . _ ...)
which expands to
(m/pred seqable? (m/app seq (_ ... p1 ,,, pN . _ ...))

noprompt21:09:04

Originally, me/scan expanded to

(m/or (_ ... p1 ,,, pN . _ ...)
      [_ ... p1 ,,, pN . _ ...))
but this expansion could result in large code explosions which is a problem which still needs to be addressed.