leonoel / missionary

A functional effect and streaming system for Clojure/Script
Eclipse Public License 2.0
651 stars 26 forks source link

Add type metadata to flow and task functions like `ap`, `sp`, `via` etc? #110

Open den1k opened 5 months ago

den1k commented 5 months ago

I have a spreadsheet app (build on electric 😉) with a sandboxed runtime that can evaluate Clojure. In order to support use cases with intermittent return values such as streaming users should be able to write code that returns a flow. The runtime should the be able to identify that the evaluated code (e.g. (m/ap ...) is in fact a flow and run it appropriately.

to illustrate:

(defn yield-intermittent-values-middleware [x]
  (case (some-> x meta :missionary.type)
    :flow (run-flow-and-yield-intermittent-values x)
    x))

(let [user-code                                  `(m/ap '...)
      user-code-if-missionary-added-type-as-meta `(with-meta
                                                    ~user-code
                                                    {:missionary.type :flow})
      user-code-with-middleware                  (list 'yield-intermittent-values-middleware
                                                       user-code-if-missionary-added-type-as-meta)]
  ;; runtime
  (runtime-eval user-code-with-middleware))

Generally this could be useful for missionary middleware and other cases dynamic evaluation in user land.