FIX don't eval either twice in bind

This commit is contained in:
Nathan Dwarshuis 2022-04-27 23:44:14 -04:00
parent 21449ad792
commit 19077c72c9
1 changed files with 6 additions and 4 deletions

View File

@ -39,10 +39,12 @@ left/right slot."
(defmacro either>>= (either form) (defmacro either>>= (either form)
"Bind EITHER to FORM where the right slot is bound to 'it'." "Bind EITHER to FORM where the right slot is bound to 'it'."
(declare (indent 1)) (declare (indent 1))
`(pcase ,either (let ((e (make-symbol "--either")))
(`(:left ,_) ,either) `(let ((,e ,either))
(pcase ,e
(`(:left ,_) ,e)
(`(:right ,it) ,form) (`(:right ,it) ,form)
(e (error "Learn to use monads, dummy; this isn't one: %s" e)))) (e (error "Learn to use monads, dummy; this isn't one: %s" e))))))
(defun either-foldM (fun init xs) (defun either-foldM (fun init xs)
"Mondically apply FUN to XS (a list). "Mondically apply FUN to XS (a list).