meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
timothypratley 2020-02-29T17:52:32.073300Z

(m/and ?parameters (m/let [?required-parameters (get-required-params ?parameters)
                           ?optional-parameters (get-optional-params ?parameters)]))
^^ is this the “right” way to introduce bindings? seems a bit weird using m/and + I’m never sure exactly where to “put” the let

👀 1
timothypratley 2020-02-29T18:02:32.073700Z

Oh this is pretty sick:

{:parameters [(m/or {:required true :as !required-parameters}
                                   {:as !optional-parameters}) ...
                             :as ?parameters]}

👍 1
timothypratley 2020-02-29T18:04:20.073900Z

Seems like there is often a way to avoid using let bindings altogether.

👍 1
timothypratley 2020-02-29T18:37:21.077600Z

Hmmm something that occurred to me, and I’m sure you’ve already considered about error messages: Currently things like match can take multiple patterns, but I often use them with 1 pattern. In the 1 pattern case; it makes sense when meander encounters “FAIL” to return “FAIL”, what was expected, what was actually there, and where the fail occurred. In the general multiple pattern case that information should be discarded.

jimmy 2020-02-29T19:08:02.077800Z

To answer the first question. That is a pretty common idiom we’ve used for introducing bindings. It does feel a little weird. Many times the let body is just empty. Maybe we should think of a better syntax for that.

jimmy 2020-02-29T19:09:27.079100Z

Yeah, I definitely want there to be better error messages. Sometimes it can get tricky with the optimizations we do to surface good information there. But we can definitely easily do better than what we currently do.

timothypratley 2020-02-29T19:52:44.081100Z

🤯 wow strategies compose great with m/app even for multi-arg scenarios if you pass vectors:

(def extract-resources
  (s/rewrite
    (m/with [%resource {:methods {& (m/seqable [_ !methods] ...)}
                        :resources {& (m/seqable [_ %resource] ...)}}]
            [?baseUrl {& (m/seqable [_ %resource] ...)}])
    ;;=>
    [(m/app extract-method' [?baseUrl !methods]) ...]))

(def build-methods'
  (s/rewrite
    {:baseUrl ?baseUrl
     :resources {& (m/seqable [!resource-names !resources] ...)}
     :name ?name
     :version ?version}
    ;;=>
    [[!resource-names (m/app extract-resources [?baseUrl !resources])] ...]))
^^ no lambdas required o_O 🙂

🦜 1
aisamu 2020-02-29T20:32:01.081900Z

From the cookbook:

(m/match {1 2 3 4 5 6}
  {& (m/seqable [!ks !vs] ...)}
  [!ks !vs])
;; => [[1 3 5] [2 4 6]]

;; But if we remove the map from the pattern, it returns the same: 
(m/match {1 2 3 4 5 6}
  (m/seqable [!ks !vs] ...)
  [!ks !vs])
;; => [[1 3 5] [2 4 6]]
Is that expected?

jimmy 2020-02-29T20:35:53.082700Z

Yeah in that example the map wouldn't make any difference whatsoever. Maps are seqable afterall.

👌 1
jimmy 2020-02-29T20:36:34.083100Z

Well technically not true

jimmy 2020-02-29T20:36:48.083600Z

If you passed the first one something that was not a map it would fail.

jimmy 2020-02-29T20:37:14.084Z

The second one will match on any seqable.

aisamu 2020-02-29T21:06:09.088100Z

I can't seem to explain the behaviour of the third case:

;; "Please match everything" - works as expected
(m/rewrite [1 2 1 3 1 4]
  [!xs ...]
  [!xs ...])
;; => [1 2 1 3 1 4]

;; "Please don't match 1's" - works as expected
(m/rewrite [1 2 1 3 1 4]
  [(m/or 1 !xs) ...]
  [!xs ...])
;; => [2 3 4]

;; "Please don't match 1's nor 3's" - ???
(m/rewrite [1 2 1 3 1 4]
  [(m/or 1 3 !xs) ...]
  [!xs ...])
;; => [1 1 3 1]
m/or is suddenly its inverse! What am I missing?

aisamu 2020-03-01T18:36:18.094700Z

Oh, thanks!

nlessa 2020-02-29T23:18:19.089500Z

Hi! Why !(m/rewrite [::a ::b] [!enums ...] ( !enums ...)) is OK and (m/rewrite [::a ::b] [!enums ...] #{ !enums ...}) is not? # has some special behaviour inside meander?

jimmy 2020-02-29T23:21:45.089600Z

I'm surprised by this. I will look into it tonight if someone else doesn't first.

jimmy 2020-02-29T23:23:11.089800Z

Sets aren't ordered collections so we can't make ... Work consistently. Can't think off the top of my head the right option there. On my phone will get back to you tonight.

nlessa 2020-02-29T23:31:21.090Z

Thanks, Jimmy!

timothypratley 2020-02-29T23:37:15.090400Z

(m/rewrite [1 2 3 4 5 6]
  [!x ...]
  #{^& (!x ...)})
;;=> #{1 4 6 3 2 5}

👍 1
🤘 1
timothypratley 2020-02-29T23:37:26.090600Z

You can use metadata trick

timothypratley 2020-02-29T23:38:33.090800Z

(m/rewrite [::a ::b]
  [!enums ...] #{^& (!enums ...)})
=> #{:happy.beaver/a :happy.beaver/b}

timothypratley 2020-02-29T23:39:17.091Z

Because metadata is on the set item 🙂