如何检查 Clojure 哈希映射中的值是否存在且等于 nil?

问题描述 投票:0回答:1

在 Clojure 中编程时,我对这两个问题都得到了相同的公平答案:

(nil? (:potato {}))
=> true
(nil? (:potato {:potato nil}))
=> true

这有时会导致混乱。有没有一个功能可以帮助我发现差异?

类似:

(property-nil? {} :potato)
=> false
(property-nil? {:potato nil} :potato)
=> true
clojure
1个回答
0
投票

使用

contains?

user=> (contains? {} :potato)
false
user=> (contains? {:potato nil} :potato)
true
© www.soinside.com 2019 - 2024. All rights reserved.