Skip to content

Instantly share code, notes, and snippets.

@tomjack
Created March 27, 2011 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomjack/8c7bdf1c62f5280470e7 to your computer and use it in GitHub Desktop.
Save tomjack/8c7bdf1c62f5280470e7 to your computer and use it in GitHub Desktop.
(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