Skip to content

Instantly share code, notes, and snippets.

@jarpiain
Created December 7, 2010 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarpiain/732529 to your computer and use it in GitHub Desktop.
Save jarpiain/732529 to your computer and use it in GitHub Desktop.
Subsampled vector
(deftype Subvec [v n]
clojure.lang.IPersistentVector
(length [_] (quot (count v) n))
(nth [_ i] (v (* i n)))
(assocN [_ i val] (Subvec. (assoc v (* i n) val) n))
(seq [_] (take-nth n (seq v))))
(Subvec. [1 2 3 4 5] 2)
; --> [1 3 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment