On Dec 2, 9:10 am, Konrad Kułakowski (kony) <kulakow...@gmail.com> wrote: > Recently I need something which works as "inverse of interleave" > > I did something like that: > > (defn unravel [expr-list] > (loop [flist () slist () tic-tac 0 olist expr-list] > (let [item (first olist)] > (if (= item nil) > (list flist slist) > (if (= tic-tac 0) > (recur (concat flist (list item)) > slist 1 (rest olist)) > (recur flist (concat slist (list > item)) 0 (rest olist))))))) > > Test: > > (def dl (interleave (iterate inc 1) ["A" "B" "C" "D" "E"])) > (unravel dl) > > And the "classic" question is it possible to do it simple, more in a > "functional manner", without explicit looping?
How about this? (defn skip [coll n] (lazy-seq (when-let [s (seq coll)] (cons (first s) (skip (drop n (next s)) n))))) (defn unravel [coll n] (for [i (range n)] (skip (drop i coll) (dec n)))) -- 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 Note that posts from new members are moderated - please be patient with your first post. 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