python - Clojure 相当于 Python 的 "any"和 "all"函数?

标签 python clojure

Clojure 中是否有类似于 Python 的 anyall 函数的内置函数?

例如,在 Python 中,它是 all([True, 1, 'non-empty string']) == True

最佳答案

(每?f 个数据) [ docs ]all(f(x) for x in data) 相同。

(一些 f 数据) [ docs ]any(f(x) for x in data) 类似,只是它返回 f(x) 的值(必须为真),而不仅仅是 true

如果您想要与 Python 中完全相同的行为,您可以使用 identity 函数,该函数将只返回其参数(相当于 (fn [x] x))。

user=> (every? identity [1, true, "non-empty string"])
true
user=> (some identity [1, true "non-empty string"])
1
user=> (some true? [1, true "non-empty string"])
true

关于python - Clojure 相当于 Python 的 "any"和 "all"函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7871295/

相关文章:

python - 使用 TwitterAPI Python 库,当您进行搜索时可以按语言进行过滤吗?

Python TypeError : argument 1 must be pygame. Surface,而不是 pygame.Rect

python - 可以从base64字符串中删除等号吗?

Python 检测网格中对齐的线段

clojure - 根据 clojure 中的映射值拆分映射集合

clojure - 捕获序列的头部

python - ZIP 格式重复字符

Clojure(脚本): macros to reason about async operations synchronously

java - 在 clojure 中同时支持 xml 和 json REST 响应

clojure - 如何获取数据数据库中最后一笔交易的日期时间?