This is assuming that all nested values are maps all the way down. What happens in the event of a Keyword list for example? Or a tuple? If the use-case is limiting itself to just maps of maps this works. But if the wider use-case should be supported it may make sense to consider a Kernel.deep_merge that has indifferent access support for the values to be merged.
On Tuesday, September 6, 2016 at 2:41:22 PM UTC-4, OvermindDL1 wrote: > > I had made my own a few times, though rare, it could be useful. Unsure > about it in core but in a library definitely. > > On Tuesday, September 6, 2016 at 9:20:23 AM UTC-6, Tobias Pfeiffer wrote: >> >> Hi everyone, >> >> in Elixir we work a lot with maps (or at least I do :D). And we know and >> love Map.merge. However given a map like %{a: %{b: 1}} and we want to >> merge it with a map like %{a: %{c: 2}} then the :a key will be totally >> overridden with whatever is supplied in the other map. >> >> However, for instance for configuration, what we might want is the >> result to be %{a: %{b: 1, c: 2}} - e.g. if the value is a map on both >> sides recursively merge that as well. >> >> It is rather simple to implement in elixir with Map.merge/3 [1] but I >> think it'd still be helpful to have it in elixir core (otherwise I'll >> make a mini hex package :D). E.g. it is useful and it'll keep people >> from wondering about it or writing their own a little flawed >> implementations. >> >> So, what do you think - Map.deep_merge in elixir-core - yay/nay? I'm >> happy to draft a PR if it gets the sign of approval. >> >> Tobi >> >> >> [1] http://stackoverflow.com/a/38865647/1810896 >> -- >> http://www.pragtob.info/ >> > -- 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 elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/c451058c-6a49-481e-9cb8-1541ce1b77a7%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.