Skip to content

Instantly share code, notes, and snippets.

@luxbock
Created March 21, 2017 14:16
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 luxbock/a6a1323497a02e36b09dec624c57b3ab to your computer and use it in GitHub Desktop.
Save luxbock/a6a1323497a02e36b09dec624c57b3ab to your computer and use it in GitHub Desktop.
(defnav take-nth [n]
(select* [this structure next-fn]
(next-fn (take-nth n structure)))
(transform* [this structure next-fn]
(if (vector? structure)
(let [c (count structure)
is (into []
(take-while #(< % c))
(iterate #(+ % n) 0))]
(reduce #(update %1 %2 next-fn) structure is))
(sequence
(map-indexed
(fn [i x]
(if (zero? (mod i n))
(next-fn x)
x)))
structure))))
;; (sp/select (take-nth 2) [1 2 3 4 5])
ArityException Wrong number of args (2) passed to: misc/fn--28811 clojure.lang.AFn.throwArity (AFn.java:429)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment