title: Clojure: Transform string into key-value pairs in hash-map
body: <p>I'll start with my test using the <a href="http://speclj.com" rel="nofollow">speclj</a> framework.</p>
  
  <pre><code>(it "turns the string into a hash-map"
    (should= {1 "1" 2 "2" 3 "3"}
      (format-string "1=1 2=2 3=3")))
  </code></pre>
  
  <p>Then my code:</p>
  
  <pre><code>(:use [clojure.string :only (split)])
  
  (defn format-string [string]
    (split string #"\s+"))
  </code></pre>
  
  <p>Right now, the <code>format-string</code> function returns <code>["1=1" "2=2" "3=3"]</code> and the test fails.  As you can see in my test, I want it to return a hash-map with key-value pairs indicated by the <code>=</code> sign.</p>
  
  <p>I've tried a few things and I've gotten close, but can't quite understand how to make this transformation.</p>
  
  <p><em><strong>EDIT</em></strong></p>
  
  <p>Figured out one solution, although the keys are strings instead of integers.</p>
  
  <p>My code:</p>
  
  <pre><code>(defn format-board [route]
    (let [[first second third] (split route #"\s+")]
      (merge 
        (apply hash-map (split-at-equals first))
        (apply hash-map (split-at-equals second))
        (apply hash-map (split-at-equals third))
  </code></pre>
  
  <p>This returns <code>{"1" "1" "2" "2" "3" "3"}</code>.</p>