diff --git a/src/unitary-list.lisp b/src/unitary-list.lisp index 8b1b74b..c8c75d8 100644 --- a/src/unitary-list.lisp +++ b/src/unitary-list.lisp @@ -13,7 +13,10 @@ "Return the monad operators for a unitary list. A unitary list is a list with 1 or zero elements" - (make-instance 'monad-operators + (make-instance 'monad-fail-operators :mreturn #'list :flatmap (lambda (f mx) - (and mx (funcall f (car mx)))))) + (and mx (funcall f (car mx)))) + :fail (lambda (str) + (declare (ignore str)) + nil))) diff --git a/test/unitary-list-test.lisp b/test/unitary-list-test.lisp index b493644..e2db395 100644 --- a/test/unitary-list-test.lisp +++ b/test/unitary-list-test.lisp @@ -30,7 +30,8 @@ (is (equal '("X") (ctx-run context (fmap #'symbol-name (pure 'x))))) (is (equal '("X") (ctx-run context (fapply (pure #'symbol-name) (pure 'x))))) (is (equal '((x y)) (ctx-run context (product (pure 'x) (pure 'y))))) - (is (equal '("X") (ctx-run context (flatmap (lambda (x) (mreturn (symbol-name x))) (pure 'x))))))) + (is (equal '("X") (ctx-run context (flatmap (lambda (x) (mreturn (symbol-name x))) (pure 'x))))) + (is (equal '() (ctx-run context (fail "Yikes!")))))) (test binding (let ((context (make-unitary-list-context)))