I am struggling with something embarrassingly basic. I just can’t get my head wrapped around Enum.map. I’m pretty sure it’s the best solution for my problem, but can’t format it correctly.
From my form, I have a list of ID numbers for a many-to-many table. So my params look like this:
%{
“title” => “blah”
“description” => “longer blah”
“resource_types” => [“1”, “2”, “5”]
}
I used get_in( params, “resource_types” ) and that returns my list of IDs:
type_list = [“1”, “2”, “5”]
Now I need to convert that into a list that will be accepted by put_assoc which is either a keyword list or a map list. So I’m trying to use Enum.map but can’t quite get it right. I think I also need to convert those string numbers into integers for put_assoc … but not totally sure about that.
formatted_list_map = Enum.map(type_list, fn x-> {:id => String.to_integer(x)} end)
But that fails. Could an Elixir pro help me with this?