clojure - 如何在集合上映射(组合)函数中的多个非集合?

标签 clojure

我想通过一系列非集合函数传递集合。可以通过多次使用map来实现。如何更简洁地使用 clojure/函数式编程惯用方式做到这一点:

(defn my-processor [coll]
  (let [get-text (fn [element] (:text element))
        sanitize (fn [element] (string/trim element))
        to-int (fn [element] (Integer. element))]
    (map to-int (map sanitize (map get-text coll))))) ; <-- this line

(我的处理器 [{:text "123"} {:text "456"}]) ; =>(123 456))

最佳答案

这应该有效: (map (comp to-int sanitize get-text) coll)

关于clojure - 如何在集合上映射(组合)函数中的多个非集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45659978/

相关文章:

emacs - 为什么 clojure-mode 用一些 curl 的 f 字符替换 fn?

c# 相当于 clojure 中的 base64 + UrlTokenEncode

exception - 不知道如何从 : clojure. lang.PersistentList$1 创建 ISeq

postgresql - 如何使用 clojure.java.jdbc 进行 UPSERT

clojure - 绕过 Compojure 中的链的自定义中间件

clojure - Clojure 1.4 上的棱柱模式?

clojure - 将 Clojure 的数据结构与 MapDB 结合使用

windows - Leiningen 安装 Windows 错误

clojure - 什么是 :<> in reagent hiccup?

clojure - 当一个符号被另一个符号引用时如何访问该符号的值