Created
January 11, 2021 01:27
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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