parsing - Clojure Mapping a function that returns a list into a flat list -
this happens when parse list of strings , want split each 1 in two, afterwards making hashmap.
say have list of strings, each 1 first line id , rest data:
("#id data more data", "#another id more data still")
now suppose use following method returns nested structure:
(map #(clojure.string/split % #"\n" 2) data)
now if want put hashmap, first has flatten
'd , apply hash-map
'd. there way skip flatten
part , having flat-map
return non-nested structure?
you can use into
:
(into {} (map #(clojure.string/split % #"\n") data))
Comments
Post a Comment