diff --git a/src/identity-monad.lfe b/src/identity-monad.lfe new file mode 100644 index 0000000..62d190b --- /dev/null +++ b/src/identity-monad.lfe @@ -0,0 +1,11 @@ +(defmodule identity-monad + (behaviour monad) + (export (>>= 2) + (return 1) + (fail 1))) + +(defun >>= (x f) + (funcall f x)) + +(defun return (x) x) +(defun fail (x) (throw (tuple 'error x))) diff --git a/test/unit/unit-identity-monad-tests.lfe b/test/unit/unit-identity-monad-tests.lfe new file mode 100644 index 0000000..d1b7bc6 --- /dev/null +++ b/test/unit/unit-identity-monad-tests.lfe @@ -0,0 +1,20 @@ +(defmodule unit-identity-monad-tests + (export all) + (import + (from lfeunit-util + (check-failed-assert 2) + (check-wrong-assert-exception 2)))) + +(include-lib "deps/lfeunit/include/lfeunit-macros.lfe") +(include-lib "include/monads.lfe") +(include-lib "include/monad-tests.lfe") + +(test-monad identity-monad) + +(deftest identity + (is-equal 'ok + (return identity-monad 'ok))) + +(deftest fail-with-error + (is-throw #(error value) + (fail identity-monad 'value))) \ No newline at end of file