Another advantage it is the support of dynamic key pattern matching. 
If you are supporting function which accept paramete as the keys to filter 
the map, so it can be dynamically filtered out.

Example

def get_data(fields) do
   get_map_from_state_or_db()
   |> Map.take_in(fields) # or take_in (with Access implementation)

end
Le mercredi 2 septembre 2020 à 14:30:36 UTC+2, Samuel Manzanera a écrit :

>
> Hello everybody,
>
> I propose the support of Map.take_in/2 to extract values using nested keys 
> (recursively).
>
> I think it may be useful when you only want a part of the map -- mostly 
> when its deep nested map (i.e KV stores, DB engines, etc..) to reduce 
> memory footprint with copy and message passing.
>
> Example:
>
>
> iex> Map.take_in(%{a: "hello", b: %{c: "hi", d: "hola"}}, [:a, b: [:d]]) 
>
> %{a: "hello", b: %{d: "hola"}}
>
> As discussed in the #1029 
> <https://github.com/elixir-lang/elixir/pull/10296> the feature should be 
> extended to Access  for both Map and Keyword implementation.
>
> To analyse the efficiency regarding pattern matching.
>
> But it's a way to resolve the duplication from pattern matching as in this 
> example.
>
> iex> %{a: a, b: %{d: d}} = %{a: "hello", b: %{c: "hi", d: "hola"}}
> iex> %{a: a, b: %{d: d}} 
> %{a: "hello", b: %{d: "hola"}}
>
>
> Thanks :)
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/6fffe7bc-5b8a-45a3-888d-3fa856a75f61n%40googlegroups.com.

Reply via email to