Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns scratch.group)
(defn numbered-line? [s]
(Character/isDigit (first s)))
(defn split-group [lines]
(when (seq lines)
(let [[group remaining] (split-with (complement numbered-line?) (next lines))]
[(cons (first lines) group)
remaining])))
(defn groups [lines]
(->> [nil lines]
(iterate (comp split-group second))
next
(map first)
(take-while identity)))
(comment
scratch.group> (groups ["1. foo" "bar" "baz" "2. bing" "bang" "bong" "3. eouaeo" "ueoue"])
(("1. foo" "bar" "baz") ("2. bing" "bang" "bong") ("3. eouaeo" "ueoue")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.