Skip to content

Instantly share code, notes, and snippets.

@victorb
Created March 1, 2019 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorb/e7622a90db51abc19fe7f602ac6d4d4a to your computer and use it in GitHub Desktop.
Save victorb/e7622a90db51abc19fe7f602ac6d4d4a to your computer and use it in GitHub Desktop.
(def first-func (fn [log] (log "Hello")))
(def second-func (fn [log] (log "World")))
;; current implementation
(defn format-steps [forms]
(loop [items forms
result []]
(if (empty? items)
result
(let [[n f] items
item {:name n :func f}]
(recur (drop 2 items) (conj result item))))))
(defmacro defpipeline [n & forms]
`(def ~n {:name (name '~n)
:steps (format-steps '~forms)}))
;;;;; Tests
;; creating a pipeline
(pipeline/defpipeline simple-pipeline
"log1" first-func
"log2" second-func)
;; expected output
(def simple-pipeline-output
{:name "simple-pipeline"
:steps [{:name "log1"
:func first-func}
{:name "log2"
:func second-func}]})
(deftest creating-pipelines
(testing "Simple Pipeline"
(is (= simple-pipeline-output simple-pipeline))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment