Clojure中是否内置了与Python any和all函数类似的函数?
例如,在Python中,它就是all([True, 1, 'non-empty string']) == True.
小智 42
(every? f data) [ docs ]是一样的all(f(x) for x in data).
(some f data) [ 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
Run Code Online (Sandbox Code Playgroud)