Get list from a map

I have a map which contain a record and then its associated records.

         data= %User{
                __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
                id: 4606,
                name: "Test",
                occupation: "Artist",
         paintings: [
          %Painting{
          __meta__: #Ecto.Schema.Metadata<:loaded, "paintings">,
           user_id: 4606,
           id: 1515,
           name: "philip"
       },
       %Painting{
         __meta__: #Ecto.Schema.Metadata<:loaded, "paintings">,
         user_id: 4606,
         id: 1516,
         name: "john"
       }
    ]
 }

We can get the paintings list with data.paintings. Is there any other method beside . operator to get the paintings list?
Thanks

Of course. You can use Map.get as well.

2 Likes

And I totally forgot, as usual, pattern matching is an option as well.

1 Like

And of course get_in/2. :slight_smile:

Only if Access is implemented for the struct.

1 Like