Clojure 对数据应用一系列函数
我希望对数据应用一系列函数,如管道: 我知道它有Clojure 对数据应用一系列函数,clojure,Clojure,我希望对数据应用一系列函数,如管道: 我知道它有->和->,而且我很难定义内部函数 (defn create ([code error] {:statusCode code :error error}) ([code error & [message data]] (create code error) - I want pipe it result to a function that check if
->
和->
,而且我很难定义内部函数
(defn create
([code error] {:statusCode code :error error})
([code error & [message data]]
(create code error) - I want pipe it result
to a function that check if
message if defined then merge with
{:message message}, then
apply to a function that checks if data
is defined an merge with it
))
您可以使用仅合并定义的变量:
(defn创建
([代码错误]
{:状态代码:错误})
([代码错误和[消息数据]]
(条件->(创建代码错误)
消息(关联:消息消息消息)
数据(关联:数据)
或者,如果定义了助手,您可以定义小型关联,并使用普通->
线程宏:
(如果定义,则定义为defn-assoc
[m k v]
(如果(无)m(关联m k v)))
(defn创建
([代码错误]
{:状态代码:错误})
([代码错误和[消息数据]]
(>(创建代码错误)
(如果定义了关联:消息)
(如果定义了关联:数据)))