mirror of
https://github.com/correl/calrissian.git
synced 2024-11-23 19:19:57 +00:00
Identity monad
This commit is contained in:
parent
7367dc2d05
commit
7a6a23e92c
2 changed files with 31 additions and 0 deletions
11
src/identity-monad.lfe
Normal file
11
src/identity-monad.lfe
Normal file
|
@ -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)))
|
20
test/unit/unit-identity-monad-tests.lfe
Normal file
20
test/unit/unit-identity-monad-tests.lfe
Normal file
|
@ -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)))
|
Loading…
Reference in a new issue