reduce - Clojure: finding sequential items from a sequence -


in clojure program, have sequence of numbers:

(2 3 4 6 8 1) 

i want find longest sub-sequence items sequential:

(2 3 4) 

i assuming involve (take-while ...) or (reduce ...).

any ideas?

clarification: need longest initial list of sequential items. easier, i'm sure. solutions more difficult problem posed.

if interested in longest initial sequence, it's 1-liner:

(defn longest-initial-sequence [[x :as s]]   (take-while identity (map #(#{%1} %2) s (iterate inc x)))) 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -