Hello, Elixir gang. I’m starting to get the hang of Elixir, which has been challenging since I’m not coming from Ruby. I have been struggling to find a solution for a particular problem. I need to generate a list of strings which increments over the alphabet. So["A", "B", "C"]
is a very basic example.
When the end of the alphabet is reached, I want the result to look like this: [..."X", "Y", "Z", "AA", "BB"...]
. The goal is to create a function like this: generate_list(first_letter, count)
.
I tried using the Alphabetify package, but it was pretty slow, and didn’t quite give me the results I needed. String.duplicate got me almost there, but I still wasn’t getting the right output.
Does anyone have an idea or package suggestion for this problem? I’ve hit a wall on this one.
Where I’m at
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |> String.split("", trim: true)
def generate_list(first_letter, count)
when is_binary(first_letter)
when is_integer(count) do
# letters
# |> Stream.cycle
# |> Stream.take(count)
starting_index = letters |> Enum.find_index(fn x -> x == first_letter end)
# 0..count
# |> Enum.map(fn x -> end)
end