簡體   English   中英

如何在集合上映射(組成)函數中的多個非集合?

[英]How to map (compose) multiple non-collection in functions over collection?

我想通過一系列非集合函數傳遞一個集合。 可以通過多次使用地圖來實現。 如何更簡潔地做到這一點和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

(my-processor [{:text "123"} {:text "456"}]) ; => (123 456))

那應該工作: (map (comp to-int sanitize get-text) coll)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM