在Haskell,我们有Data.Function.on:
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
(.*.) `on` f = \x y -> f x .*. f y
Run Code Online (Sandbox Code Playgroud)
在Clojure中,我希望能够定义一个例如anagram谓词,如下所示:
(defn anagram? [word other-word]
(and (not= word other-word)
((on = sort) word other-word)))
Run Code Online (Sandbox Code Playgroud)
实施起来很简单:
(defn on [g f] (fn [x y] (g (f x) (f y))))
Run Code Online (Sandbox Code Playgroud)
但是,是否有任何内置函数可以实现相同的目标?我好像找不到一个.