Skip to content

Instantly share code, notes, and snippets.

@johnmn3
Created April 1, 2011 04:50
Show Gist options
  • Save johnmn3/897755 to your computer and use it in GitHub Desktop.
Save johnmn3/897755 to your computer and use it in GitHub Desktop.
Like partition, but adds padding at the end of the last sequence so that last sequence's size is equal to "si
(defn end-padded-partition [size acoll]
(loop [new-coll [], coll acoll)]
(if (empty? coll)
new-coll
(recur
(let [next-stuff (vec (take size coll))
padding-size (- size (count next-stuff))
padding (rand-bytes padding-size)]
(if (zero? padding-size)
(conj new-coll next-stuff)
(conj new-coll (into next-stuff padding))))
(drop size coll)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment