Created
March 21, 2017 14:16
-
-
Save luxbock/a6a1323497a02e36b09dec624c57b3ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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