Skip to content

Instantly share code, notes, and snippets.

@luxbock luxbock/take-nth.clj
Created Mar 21, 2017

Embed
What would you like to do?
(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
You can’t perform that action at this time.