-
-
Save practicalli-johnny/4fb8eaef73f4cbd70cb69ca43c492ad4 to your computer and use it in GitHub Desktop.
Produces Excel like column names
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
(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