On May 4, 9:03 am, Konrad Hinsen <konrad.hin...@laposte.net> wrote:
> On May 4, 2009, at 14:23, Nathan Hawkins wrote:
>
> > This seems a little bit more like what I expected:
>
> > (map-assoc split-kv (split-pairs test-str))
>
> > -> {"baz" "3", "bar" "2", "foo" "1"}
>
> > Am I overlooking some already existing function hidden away someplace
> > that does this?
>
> Here's one way to do what you want:
>
> (ns test (:use clojure.contrib.str-utils))
>
> (def test-str "foo=1;bar=2;baz=3")
>
> (defn split-kv [text]
>   (vec (re-split #"=" text)))
>
> (defn split-pairs [text]
>   (re-split #";" text))
>
> (apply conj {} (map split-kv (split-pairs test-str)))
>
The last can be simplified by using into:
(into {} (map split-kv (split-pairs test-str)))

--
Michel
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to