medley
medley copied to clipboard
Add mapcat-indexed function
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 :)