I want to take a list and generate subsequences, in this manner:
(subs '(1 2 3))
; should evaluate to ((1) (1 2) (1 2 3) (2) (2 3) (3))
and yes, order matters. I might be missing something obvious, but I'm stuck. Bonus points for pretty solutions!
Another take, a little shorter.
(defn subs4 [coll]
(mapcat #(reverse (take (count %) (iterate butlast %)))
(take (count coll) (iterate rest coll))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With