medley icon indicating copy to clipboard operation
medley copied to clipboard

Add mapcat-indexed function

Open tomdl89 opened this issue 6 months ago • 2 comments

I feel this fits with medley pretty well. It exists in Kotlin as flatMapIndexed which I've used a few times recently, and realised is missing from clojure.core. It also exists in JS as the dyadic form of flatMap. It's useful for conditionally inserting extra items based on index, among other things. e.g.

(mapcat-indexed (fn [i x] (if (even? i) [x :break] [x]))
                '[a b c d e f g h i j h])
;; => (a :break b c :break d e :break f g :break h i :break j h :break)

lmk what you think :)

tomdl89 avatar Jun 24 '25 12:06 tomdl89