映射到输入到输出的哈希映射?这个功能存在吗?

时间:2017-02-02 17:40:15

标签: clojure

我有一个类似高阶searchInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (!s.toString().isEmpty()) { CenterRepository.getInstance().getSearchResultCollection().getListOfSearchResult().clear(); //Iterate over reference models for (ReferenceModel model : CenterRepository.getInstance().getXRefModelCollection().getListOfReferenceModels()) { //if serach key is present in model name or model number if (model.getModelName().toLowerCase().contains(s.toString()) || model.getModelNumber().toLowerCase().contains(s.toString())) { //add to search collection CenterRepository.getInstance().getSearchResultCollection().addToSearchResultsCollection(model); } } //display search results renderListData(true); } else { //display all models renderListData(false); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); 的函数,它返回一个表示函数应用程序(输出到输出)的散列图。

map

这样使用:

(defn map-application [f coll] (into {} (map #(vector % (f %)) coll)))

此功能是否已存在,或此模式是否具有可识别的名称?

我知道它只是一个单行,但是在(map-application str [1 2 3 4 5]) {1 "1", 2 "2", 3 "3", 4 "4", 5 "5"} (map-application (partial * 10) [1 2 3 4 5]) {1 10, 2 20, 3 30, 4 40, 5 50} 中查看相关函数的星座,这看起来就像已经存在的那种。

2 个答案:

答案 0 :(得分:2)

我想你要找的术语是AWS::EC2::SecurityGrouphttps://clojure.org/reference/transducers

事实上,转换变体看起来几乎和你的一样(关键的区别在于transducer参数传递给coll函数而不是into),但它确实没有任何中间作用集合:

map

这也可以通过简单的减少来完成,但它需要更多的手工工作:

user> (defn into-map [f coll]
        (into {} (map (juxt identity f)) coll))
#'user/into-map
user> (into-map inc [1 2 3])
;;=> {1 2, 2 3, 3 4}

答案 1 :(得分:2)

内置的$sql_getinfo = "SELECT * FROM transaction_user WHERE id= ".$stock_id; $sql_stockinfo = "SELECT Shares_for_sale FROM company_listed WHERE id= ".$company_id; $updatebalance = "UPDATE balance SET current_balance = ".$updatedbalance." where username = '".$login_session."'"; $updateshare = "UPDATE company_listed SET Shares_for_sale = ".$updatedshares." where id= ".$stock_id; $sqldelete = "DELETE FROM transaction_user WHERE id= ".$stock_id; 函数可以轻松处理您所描述的内容:

zipmap