algo.monadsの Maybeモナド変換子 (maybe-t) はnothing値を任意に指定できる。
でもnothingの判定は identical? で行われるので実行時情報を持たせたオブジェクトをnothingにしてeitherのように使うことは出来ない。 予め決められた選択肢から選択することはできる。
Last active
December 17, 2015 17:49
-
-
Save mnzk/5648536 to your computer and use it in GitHub Desktop.
clojure.algo.monads/maybe-t sample
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
(use 'clojure.algo.monads) | |
(def maybes-t (partial reduce maybe-t)) | |
(with-monad (maybes-t maybe-m [0 :err1 :err2 :err3]) | |
(defn div [x y z] | |
(domonad [a x b y c z] (/ a b c)))) | |
(div 10 0 20) ;=> 0 | |
(div nil 0 20) ;=> nil | |
(div :err2 0 20) ;=> :err2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment