Hey I’m new to Elixir and trying to work through “Advent of code” in order to get a better understanding of the language. Right now I’m having difficulties sorting out newline characters in a string and converting that string into a list.
defmodule One do
def readme(filename) do
my_text = File.read(filename)
String.split(my_text, ~r{\n})
end
end
I know this might just be terrible elixir but could someone help me understand why it is not correctly splitting the string by newline and moving it into a list ?
I keep getting this error:
Attempted function clauses (showing 3 out of 3):
def split(string, %Regex{} = pattern, options) when is_binary(string) and is_list(options)
def split(string, "", options) when is_binary(string) and is_list(options)
def split(string, pattern, options) when is_binary(string) and is_list(options)
(elixir 1.12.2) lib/string.ex:473: String.split/3
I’m not sure this will do what the Original Poster wants because that is not equivalent. String.split/1 will split on all whitespace characters instead of just newlines.