小编yur*_*riq的帖子

在Clojure中,是否有类似Haskell的函数?

在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)

但是,是否有任何内置函数可以实现相同的目标?我好像找不到一个.

haskell functional-programming clojure combinators

11
推荐指数
1
解决办法
608
查看次数