传递参数的翻转顺序 [英] flip order of passed arguments

查看:50
本文介绍了传递参数的翻转顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有惯用的/内置的方式来翻转传递给Clojure中的函数的参数顺序?

Is there a idiomatic / built-in way to flip the argument order that is passed to a function in Clojure?

就像我在这里对a的定义那样辅助函数:

As I do here with the definition of a helper function:

(defn flip [f & xs]
   (apply f (reverse xs)))


(vector 1 2)       ; [1 2]
(flip vector 1 2)  ; [2 1]


推荐答案

我认为大多数时候都有意义创建稍后使用的翻转函数,因此函数的变化形式如下:

I think it makes sense most times to create a flipped function that you use later, so the variation on your function would be this:

(defn flip [f]
  (fn [& xs]
    (apply f (reverse xs))))

这篇关于传递参数的翻转顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆