Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save practicalli-johnny/4fb8eaef73f4cbd70cb69ca43c492ad4 to your computer and use it in GitHub Desktop.
Save practicalli-johnny/4fb8eaef73f4cbd70cb69ca43c492ad4 to your computer and use it in GitHub Desktop.
Produces Excel like column names
(defn column-names-seq
"Given an alphabet string generate a lazy sequences of column names
e.g.
`(column-names-seq \"abcdefghijklmnopqrstuvwxyz\") ;; => (\"a\" \"b\" \"c\" ... \"aa\" \"ab\")`"
[alphabet]
(->> (map str alphabet)
(iterate (fn [chars]
(for [x chars
y alphabet]
(str x y))))
(apply concat)))
(defn alphabetical-column-names
"Returns an infinite sequence of alphabetized column names. If more
than 26 are required the sequence will count AA AB AC ... BA BB BC
... ZZZA ... etc"
[]
(column-names-seq "abcdefghijklmnopqrstuvwxyz"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment