如何应用的序列功能上的序列的变量在题?

0

的问题

我有一个功能,这需要一个序列的功能和一系列参数。 这应该回一矢量的结果的每个功能应用到的顺序的论点。

((solution + max min) 2 3 5 1 6 4) ;;--> [21 6 1]

我试图要解决它与减少但我不知道如何应用的所有功能,它仅适用于第一个功能:

(defn solution
  [& args]
 (fn [& args2]
 (reduce (first args) [] args2)))
clojure higher-order-functions
2021-11-13 20:27:42
1

最好的答案

4

使用 juxt:

((juxt + max min) 2 3 5 1 6 4)
=> [21 6 1]

或定义功能 solution:

(defn solution
  [& args]
  (fn [& args2]
    (apply (apply juxt args) args2)))

((solution + max min) 2 3 5 1 6 4)
=> [21 6 1]
2021-11-13 20:34:59

好了, (def solution juxt) 会做定义 solution.
jaihindhreddy

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................