PragTob

PragTob

Deep_merge 0.1.0 - deep merging maps, keyword lists + more

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.Resolver protocol 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 :slight_smile:

Most Liked

PragTob

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:

I believe though there are still too many questions to be answered before moving forward.

and

(…) as long as you pick a sane namespace, like DeepMerge, it should be fine. It is unlikely we would add it to Elixir as DeepMerge.

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 :slight_smile:

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 :clap:

PragTob

PragTob

Resurrection time :stuck_out_tongue_winking_eye:

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 :slight_smile:

josevalim

josevalim

Creator of Elixir

See https://github.com/elixir-lang/elixir/pull/5339 for a discussion on why it is not part of core.

PragTob

PragTob

I think so, yes.

  • override behaviour (aka take the right side), at least for deep_merge as I could have a map with keywords as values but I don’t want them to be merged but rather treat them as values
  • domain logic - not something I’ve actively tried but I think if you think about ecto’s queries and their keywords you could come up with a number of valid ways to “merge” them (intersection, union, append, connect with OR/AND), although I don’t think it’s a good thing to ever do
  • given that duplicated keys are absolutely fine in keyword lists one might just wish to append - this is also true for merging “normal” lists (someone on the mailing list actually wanted this) - but it’s hard to distinguish as “normal” lists back keyword lists

I’m sure other people can and will come up with more ways :slight_smile:

kelvinst

kelvinst

Totally agree. :clap::clap::clap:

Nice work guys, if the choice was mine, this language would not be as wonderful as it is! Awesome community and awesome maintainers!

Where Next?

Popular in Libraries Top

Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
cjen07
parameterized pipe in elixir: |n> edit: negative index in |n> and mixed usage with |> are supported example: use ParamP...
New
woutdp
Hi! I wanted to introduce my latest project LiveSvelte. It allows you to render Svelte inside LiveView with end-to-end reactivity. It’s ...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
Qqwy
While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Eli...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Sub Categories:

We're in Beta

About us Mission Statement