Emi*_*son 29 error-handling exception clojure either maybe
当我戴上我的C帽时,我认为也许惯用的Clojure只做简单的事情并检查返回值.
当我戴上我的Java帽子时(不情愿地,我必须添加),我想我自己,因为Clojure在JVM上运行,自然的方式必须是使用JVM异常.
当我戴上我的功能帽时,我认为必须有某种monadic构造或线程宏可以以可组合的方式处理错误.
那么在Clojure程序中处理错误的惯用方法是什么?
对于非常实用的方法,请查看cats,它对应于“某种一元结构”:
Clojure 和 ClojureScript 的范畴论和代数抽象。http://funcool.github.io/cats/latest/
从他们的文档中获取的示例:
(require '[cats.core :as m])
(require '[cats.monad.maybe :as maybe])
(m/mappend (maybe/just [1 2 3])
(maybe/nothing)
(maybe/just [4 5 6])
(maybe/nothing))
Run Code Online (Sandbox Code Playgroud)
您可以看到这nothing在某种程度上等同于nil,但您不必手动检查任何内容。
| 归档时间: |
|
| 查看次数: |
6044 次 |
| 最近记录: |