Skip to content

Instantly share code, notes, and snippets.

@frankitox
Created January 11, 2021 01:27
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 frankitox/b777d4aa78c6ebb59d44a6f36c46e18f to your computer and use it in GitHub Desktop.
Save frankitox/b777d4aa78c6ebb59d44a6f36c46e18f to your computer and use it in GitHub Desktop.
Monad-like helpers to run spire's shell commands emulating `-e` (exit on error)
(require '[spire.module.shell :refer [shell]])
;; >>= :: m a -> (a -> m b) -> m b
(defn >>= [{:keys [result out-lines] :as prev} f]
(if (= result :ok)
(f out-lines)
prev))
;; return :: a -> m a
(defn return [cmd]
(shell {:cmd cmd}))
;; liftm :: (a -> b) -> m a -> m b
(defn liftm [f ma]
(>>= ma (comp return f)))
(defmacro dom [bindings & body]
(if (= (count bindings) 0)
`(do ~@body)
`(>>= ~(bindings 1)
(fn [~(bindings 0)]
(dom ~(subvec bindings 2) ~@body)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment