I am pretty new to Elixir so I am sure I am making a rookie mistake here somewhere but this behavior seems a bit odd to me.
This issue is best demonstrated with an example.
I have a nested list of the following form.
raw_list = [[123, "The Hobbit", 456, "JRR Tolkien"]]
When I perform the following map on this list
items = Enum.map(raw_list, fn [book_id, book_title, author_id, author_title] ->
%{
book_id: book_id,
book_title: book_title,
author_id: author_id,
author_title: author_title
} end)
items now equals the following (which is expected)
[
%{
author_id: 456,
author_title: "JRR Tolkien",
book_id: 123,
book_title: "The Hobbit"
}
]
The issue here is if I run the following map over that items list
Enum.map(items, fn item -> item.book_id end)
which returns
'{'
It seems like elixir thinks it should treat item.author_id
as a string, so it gets the ASCII character for the value of 123 which is '{'
The weird part is that if I run
Enum.map(items, fn item -> item.author_id end)
elixir returns
[456]
Which is what I expect...
Any idea what's going on here?