title: Clojure - Splitting a sequence into multiple sequences
body: <p>I am working on a function that will split a sequence of dates (or anything else) into a number of sequences contained within a vector based on a given number x.</p>
  
  <pre><code>   (date1 date2 date3 date4 date5 date6 date7)
  </code></pre>
  
  <p>So given the list of dates above and passing in the variable 2 it will produce the vector below.</p>
  
  <pre><code>   [(date1 date2) (date3 date4) (date5 date6) (date7)]
  </code></pre>
  
  <p>The code I have so far is below but all it returns is a vector containing nil.</p>
  
  <pre><code>(defn date-splitter [date-count dates x]
    (loop [i date-count, current-split dates, split-dates (vector)]
          (if (&lt;= i x)
              (conj split-dates (get current-split 1))
              (let [s (split-at x current-split)]
                (recur (int (- i x)) (get s 1) (conj split-dates (get s 0)))))))
  </code></pre>
  
  <p>I have also had a look at the split-with function, thinking that I could use it to split the sequence when the modulus of the index divided by x is zero, but I haven't had any luck with this.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>David.</p>