问题描述
我写了一个小的匿名函数,用于 map
调用。该函数返回一个包含来自SQL结果集查询的列名和列值的向量。
I wrote a small anonymous function to be used with a map
call. The function returns a vector containing a column name and column value from a SQL result set query.
这里是函数(输入是列名):
Here is the function (input is the column name):
(fn [name] [(keyword name) (.getObject resultset name)])
这工作正常,但是当我试图使用一个简化版本的匿名函数,我有一个错误:
This works fine, however when I tried to use a "simplified" version of the anonymous function, I got an error:
#([(keyword %) (.getObject resultset %)])
java.lang.IllegalArgumentException: Wrong number of args (0) passed to: PersistentVector
这是映射
call:
(into {} (map (fn [name] [(keyword name) (.getObject resultset name)]) column-names))
是否可以使用此函数的简化语法?如果是,如何?
Is it possible to use the simplified syntax for this function? If so, how?
感谢。
推荐答案
你可以插入一个identity函数来使它工作,因为这只是一个简单的函数
You can insert an "identity" function to make it work, as this is just a simple function that will return the vector unchanged:
#(identity [(keyword %) (.getObject resultset %)])
这篇关于Clojure:从一个匿名函数返回一个向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!