PragTob
Hey everyone, I created and published a new library to deep merge maps and keyword lists. You can find it on github, hex and hexdocs. I also wrote a small release blog post detailing how the library came to be after trying to get deep_merge into elixir.
Library usage is easy as expected:
DeepMerge.deep_merge(%{a: 1, b: [x: 10, y: 9]}, %{b: [y: 20, z: 30], c: 4})
# => %{a: 1, b: [x: 10, y: 20, z: 30], c: 4}
More features include:
- It handles both maps and keyword lists
- It does not merge structs or maps with structs…
- …but you can implement the simple
DeepMerge.Resolverprotocol for types/structs of your choice to also make them be deep mergable - a deep_merge/3 variant that gets a function similar to Map.merge/3 to modify the merging behavior, for instance in case you don’t want keyword lists to be merged or you want all lists to be appended
Feedback, comments and others all welcome ![]()
Trending in Announcing
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
New
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub.
Docs are at OpenaiEx User Gu...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly.
One of i...
New
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto.
pagination
cursor pagination
sorta...
New
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New
Other Trending Topics
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog
It says that Fly is going all-in on sprites, which is a worry ...
New
Hey folks,
I just published a post about Hologram’s funding and where the project goes next - the short version:
Curiosum as Main Spons...
New
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using.
We’re particularly inte...
New
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 9- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
kelvinst
This is a very common need on many projects. @josevalim do you think this feature could be part of the Elixir
MapandListAPI?josevalim
See [Proposal] Implement Map.deep_merge/2 and Map.deep_merge/3 by PragTob · Pull Request #5339 · elixir-lang/elixir · GitHub for a discussion on why it is not part of core.
Eiji
How about merge when one of
Keywordhave two elements with same key?I expected results like:
How about to generate diff and apply only insert and update changes?
PragTob
As José said you’ll find the reasons there, I described the story in the release blog post - it started with a proposal on elixir-core.
Mainly concerns were about how often it’d be useful, that the right implementation would probably be protocols and that it’d be a bit overkill to add a protocol to the language for a feature with questioned general utilization.
It might be my interpretation, but there seems to be a chance that something like deep_merge will be added to Elixir at some time in the future if it turns out to be more useful/popular/something:
and
All that said, I think a library is a perfectly fine place for this to live, thanks to hex it’s easy to add and use and I hope the library lives up to all your quality standards and if not please tell me
Plus, I have to commend the elixir team for rejecting features. Imo it’s a hard but very necessary thing to do to keep a project lean and maintainable
PragTob
Hi there! Thanks for the feedback
To be honest I was a bit surprised by the keyword list merging behavior as well, but basically this follows what
Keyword.merge/2does in Elixir (it usesKeyword.merge/3underneath) and I want it to be the same and be consistent with whatever Elixir does because otherwise it’d just be weird and confusing.That said, the mailing list discussion showed me that people have different ways they want deep_merge to work especially for lists/keyword lists so that might be a great use case for you for
DeepMerge.deep_merge/3and the reason why I didn’t publish until I had that worked outkelvinst
Totally agree.


Nice work guys, if the choice was mine, this language would not be as wonderful as it is! Awesome community and awesome maintainers!
Eiji
To be honest I’m also a bit surprised!
I agree with your arguments, but I’m not satisfied.
I think I can add
mergeandreverse_merge(for sorting order) methods to my differ package that I’m currently working on it.My merge methods will be based on diff so it will follow the second way that I asked about.
I see only this two ways to merge (elixir based and diff based). Is there other ways that developers need?
PragTob
I think so, yes.
I’m sure other people can and will come up with more ways
PragTob
Resurrection time
I just released 1.0.0 as the API has been proven stable, added some small goodies to go with it.
I consider it feature completely, so save good feature ideas, bugs, performance improvements, compiler warnings it shouldn’t see any more updates.
Enjoy deep merging