【问题标题】:Clojure cats append nil behaviourClojure 猫追加 nil 行为
【发布时间】:2016-03-03 11:07:53
【问题描述】:

我正在使用funcool/cats,在幺半群后面加上以下代码:

(m/mappend (maybe/just [1 2 3])
             nil
             (maybe/just [4 5 6])
             (maybe/nothing)) ;;=> #<Just [1 2 3 4 5 6]>

nil 视为可能/无的理由是什么?

注意:版本为[funcool/cats "1.2.1"]

【问题讨论】:

    标签: clojure category-theory monoids


    【解决方案1】:

    来自commit log,好像是

    只是为了(sic)避免意外的空指针异常

    这也记录在这里:http://funcool.github.io/cats/latest/#nil

    鉴于 nil 既是值又是类型,我们扩展了 nil 类型等同于 Maybe monad 的 Nothing。

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 2016-09-13
      • 2023-02-26
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      • 2013-11-16
      • 2016-07-21
      • 1970-01-01
      相关资源
      最近更新 更多