-
-
Save tomjack/8c7bdf1c62f5280470e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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