File tree 2 files changed +15
-0
lines changed
2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -359,3 +359,13 @@ ineligible for garbage collection."
359
359
(let [x (first coll)]
360
360
(cons x (when-not (pred x)
361
361
(take-until pred (rest coll))))))))
362
+
363
+ (defn map-nth
364
+ " Calls f on every nth element of coll. If start is passed, starts
365
+ at that element (counting from zero), otherwise starts with zero."
366
+ ([f nth coll] (map-nth f 0 nth coll))
367
+ ([f start nth coll]
368
+ (map #(% %2 )
369
+ (concat (repeat start identity)
370
+ (cycle (cons f (repeat (dec nth) identity))))
371
+ coll)))
Original file line number Diff line number Diff line change 178
178
s (sequeue 2 coll)]
179
179
(is (= 1 (first s)))
180
180
(is (thrown? Throwable (dorun s))))))
181
+
182
+ (deftest test-map-nth
183
+ (is (= [2 2 4 4 6 6 8 8 10 10 ]
184
+ (map-nth inc 2 [1 2 3 4 5 6 7 8 9 10 ])))
185
+ (is (= [" " " x" " " " x" ] (map-nth #(str % " x" ) 1 2 [" " " " " " " " ]))))
You can’t perform that action at this time.
0 commit comments