Hi, what about that :
(require 'clojure.contrib.seq-utils) (defn mystery-function "f : predicate function ; s : sequence to work on ; o : object to insert after each group of items fullfilling predicate f" [f s o] (let [partitioned (clojure.contrib.seq-utils/partition-by f s)] (mapcat #(if (f (first %)) (concat % [o]) %) partitioned))) HTH, -- Laurent 2009/4/22 samppi <rbysam...@gmail.com>: > > Let's say I have a sequence of integers: > (def a (3 9 1 5 102 -322 ...)) > > Is there a function for inserting an object—let's say :foo—after > elements that fulfill a certain predicate? > Furthermore, I mean inserting :foo after any block of elements that > fulfill it: > > (mystery-function (partial > 6) a) ; -> (3 :foo 9 1 5 :foo 102 > -322 :foo ...) > > Is it possible to do this without a loop? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---