deft/notes/deep_merge_exploration.org

36 lines
1.4 KiB
Org Mode
Raw Permalink Normal View History

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]
2024-08-14 09:35:42 +00:00
- tags :: [[id:debfbdb6-03a6-478e-8316-bce0119c0dd7][clojure]] [[id:a5be1daf-1010-428f-a30f-8faf95c1a42f][blog]]
2022-03-12 10:10:08 +00:00
- 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.