2

我正在尝试根据“col_nm”字段对下面的地图(Clojure)进行排序,但无法这样做。

{:Mawb {:user_val "3", :col_nm "1"}, 
 :HawbDate {:user_val "", :col_nm "3"}, 
 :EtlBatchID {:user_val "1", :col_nm "2"}}

输出应该是:

{:Mawb {:user_val "3", :col_nm "1"}, 
 :EtlBatchID {:user_val "1", :col_nm "2"}, 
 :HawbDate {:user_val "", :col_nm "3"} }

任何人都可以帮助我,提前谢谢。

4

1 回答 1

5

试试这个:

(def m {:Mawb {:user_val "3", :col_nm "1"},
        :HawbDate {:user_val "", :col_nm "3"},
        :EtlBatchID {:user_val "1", :col_nm "2"}})

(sort-by (comp :col_nm second) m)
=> ([:Mawb {:user_val "3", :col_nm "1"}]
    [:EtlBatchID {:user_val "1", :col_nm "2"}]
    [:HawbDate {:user_val "", :col_nm "3"}])
于 2012-04-12T10:57:28.493 回答