Skip to content

Instantly share code, notes, and snippets.

@RickMoynihan
Created May 29, 2019 13:36
Show Gist options
  • Save RickMoynihan/c78e33a781910a789a5875b7bb42cbfc to your computer and use it in GitHub Desktop.
Save RickMoynihan/c78e33a781910a789a5875b7bb42cbfc 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