2009/5/4 Nathan Hawkins <uts...@gmail.com>: > > Possibly I'm going about this wrong. I'm trying to understand how best > to construct maps from sequences, by applying a function which returns a > key / value pair. > > Something like this: > > (ns test (:use clojure.contrib.str-utils)) > > (def test-str "foo=1;bar=2;baz=3") > > (defn split-kv [text] > (let [[k v] (re-split #"=" text )] > {k v})) > > (defn split-pairs [text] > (re-split #";" text)) > > (map split-kv (split-pairs test-str)) > > -> ({"foo" "1"} {"bar" "2"} {"baz" "3"}) > > > Doesn't really do what I had in mind. And yeah, I figured out that I can > convert that to a hash-map in various ways, but I had expected map to be > able to do this.
Hi, no, maybe you make a confusion with the word "map" as in "hash-map" and as in "mapping". The latter is the meaning for the map function: mapping a sequence to another sequence (and the result will always be a sequence). --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---