2022-03-12 10:10:08 +00:00
|
|
|
:PROPERTIES:
|
|
|
|
:ID: c1dbe471-a470-4d44-a91c-0bfda0d47d21
|
|
|
|
:END:
|
|
|
|
#+TITLE: Deep Merge exploration
|
|
|
|
#+Author: Yann Esposito
|
|
|
|
#+Date: [2022-03-12]
|
|
|
|
- tags :: [[id:debfbdb6-03a6-478e-8316-bce0119c0dd7][clojure]]
|
|
|
|
- source ::
|
2022-03-12 10:11:10 +00:00
|
|
|
|
2022-03-12 10:12:44 +00:00
|
|
|
One common task in software coding is to manipulate deeply nested structures.
|
2022-03-12 10:15:39 +00:00
|
|
|
Depending on the programming language you use, you have a different set of
|
|
|
|
root structures.
|
|
|
|
|
|
|
|
But in most languages you have roughly the same concepts.
|
2022-03-12 10:19:58 +00:00
|
|
|
Base types, like chars, numbers, often strings
|
|
|
|
Storage types, typically, arrays, list, associative array (map, hash-map).
|
|
|
|
|
|
|
|
So let's restrict ourselves to this common denominator of data structure.
|
|
|
|
Say, base types could be: char, number, string
|
|
|
|
Construction types could be map (associative array) or arrays.
|
|
|
|
Sounds simple enough.
|
|
|
|
|
|
|
|
So a common task is to "merge" such structure.
|
2022-03-12 10:21:42 +00:00
|
|
|
A typical common example, is to have an application that read from a
|
|
|
|
configuration file.
|
2022-03-12 10:19:58 +00:00
|
|
|
|
2022-03-12 10:21:42 +00:00
|
|
|
As the application becomes more and more complex, the configuration file
|
|
|
|
also grow in complexity.
|
|
|
|
At first, this is just a list of properties, but it is frequent to use
|
|
|
|
json, yaml (dhall if you are in this kind of thing).
|
2022-03-12 10:23:18 +00:00
|
|
|
|
|
|
|
And a common usage would be to provide default values for the
|
|
|
|
configuration.
|
|
|
|
Instead of putting the default value manually in your code a nice
|
|
|
|
alternative is to "merge" the user config with a default config.
|