本文介绍了等同于每个谓词,但对于任何给定谓词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么更可爱的表达方式吗?

Any cuter way to express this?

#(or (:a %) (b: %) (:c %)) ;; would prefer (desired-fn :a :b :c)

clojure.core缺少 any- pred功能,也许是因为已经有一种提供相同功能的方法?还是要自己来实现?

clojure.core lacks a "any-pred" function, maybe because there is already a means of providing the same functionality? Or would have one to implement it himself?

推荐答案

是您要的内容。唯一的区别是 some-fn 将返回 false 而不是 nil

some-fn is what you're looking for. The only difference is that some-fn will return false rather than nil in the case where none of the functions return a logically true value.

只是命名注意:它不被称为 some-pred / any -pred,因为谓词仅返回 true false ,而 some-fn 将返回第一个逻辑上为true的值(本身可能不是 true 本身)。

Just as a note on naming: it's not called "some-pred"/"any-pred" because predicates only return true or false, whereas some-fn will return the first logically true value (which may not be true itself).

这篇关于等同于每个谓词,但对于任何给定谓词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 22:17