Skip to content

Instantly share code, notes, and snippets.

@milinda milinda/gist:10173848
Last active Aug 29, 2015

Embed
What would you like to do?
(defmacro filter [name params type & body]
(let [prepare-fn-name (symbol (str name "__prep"))
[input-spec _arrow_ output-spec] type
[init work] body
[i init-defs] init
[w conf & impl-body] work
fn-body (if (empty? input-spec)
(if (empty? init-defs)
`(fn [] (spout (~'nextTuple [] ~@impl-body)))
`(fn [] (let [~@init-defs] (spout (~'nextTuple [] ~@impl-body)))))
(if (empty? init-defs)
`(fn [] (bolt (~'execute [] ~@impl-body)))
`(fn [] (let [~@init-defs] (bolt (~'execute [] ~@impl-body))))))
definer (if (empty? input-spec)
(if (empty? params)
`(def ~name
(streamit-spout ~prepare-fn-name ~output-spec ~(:push conf) []))
`(defn ~name [& args#]
(streamit-spout ~prepare-fn-name ~output-spec ~(:push conf) args#)))
(if (empty? params)
`(def ~name
(streamit-bolt ~prepare-fn-name ~output-spec ~input-spec ~(:peek conf) ~(:pop conf) ~(:push conf) []))
`(defn ~name [& args#]
(streamit-bolt ~prepare-fn-name ~output-spec ~input-spec ~(:peek conf) ~(:pop conf) ~(:push conf) args#))))]
`(do
(defn ~prepare-fn-name ~(if (empty? params) [] params)
~fn-body)
~definer)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.