noprompt / meander

Tools for transparent data transformation
MIT License
921 stars 54 forks source link

Pure-data API #63

Closed daslu closed 5 years ago

daslu commented 5 years ago

In the last few days I have been using Meander for some declarative data processing project. In order to communicate data processing "as data", I wrapped a subset of Meander in a Pure-EDN API.

For example, instead of

(meander.match.delta/search
    {:a [{:x 1 :y 2}
         {:x 3 :y 4}]}
  {:a (scan {:x ?x :y ?y})}
  {:z (+ ?x ?y)})

One may write something like:

(->> {:a [{:x 1 :y 2} {:x 3 :y 4}]}
     (meander {:operator :search
               :pattern  {:a [:scan {:x :?x :y :?y}]}
               :action   {:z [:fn/+ :?x :?y]}
               :functions-catalog {:+ +}}))

Behind the scenes, there is a memoized compilation of

{:operator :search
 :pattern  {:a [:scan {:x :?x :y :?y}]}
 :action   {:z [:fn/+ :?x :?y]}
 :functions-catalog {:+ +}}

to a function that expects data such as

{:a [{:x 1 :y 2} {:x 3 :y 4}]}

.

Would it be interesting to develop such a layer as part of Meander? Or would it rather live in a separate library?

noprompt commented 5 years ago

My preference would be towards having a separate library though I very much like what you are doing. I've done a similar thing myself working on an application for doing syntactic search and replace. What you're doing looks interesting!

One thing I would be willing to support is an interpreter and I've done some work on this (see the example at the very bottom). Apart from the need to have a way to resolve function symbols to functions (the app pattern is missing), I would consider this a pure data interface. Would this be helpful to you?

daslu commented 5 years ago

Thanks. I will try to share something as a separate repo.

The interpreted idea looks really neat and useful! (In my use case, the goal is to make Meander processing accessible to a team of analysts who do not know Clojure, so we might prefer something which is not only pure-data, but also more JSON-like. Anyway, I'll think a little more.)