An open API service indexing awesome lists of open source software.

https://github.com/peterhoeg/deep-merge.cr

Deep merge support for Hash
https://github.com/peterhoeg/deep-merge.cr

Last synced: about 1 year ago
JSON representation

Deep merge support for Hash

Awesome Lists containing this project

README

          

* deep-merge
[[https://github.com/peterhoeg/deep-merge.cr/workflows/Crystal%20CI/badge.svg]]

Adds support for deep merges to =Hash=

#+BEGIN_SRC crystal
# normal merge
{ "a" => { "b" => 4 } }.merge({ "a" => { "c" => true } })
=> { "a" => { "c" => true } }

# deep merge
{ "a" => { "b" => 4 } }.deep_merge({ "a" => { "c" => true } })
=> { "a" => { "b" => 4, "c" => true } }
#+END_SRC

* Installation

Add it to =shards.yml= in your project:

#+BEGIN_SRC yaml
dependencies:
deep-merge:
gitlab: peterhoeg/deep-merge.cr
#+END_SRC

* Usage

#+BEGIN_SRC crystal
require "deep-merge"
#+END_SRC

=Hash= is now monkey-patched to support =.deep_merge= and =.deep_merge!= instance methods.

** TODO Add support for:

- [ ] arrays (probably configurable)
#+BEGIN_SRC crystal
{ "a" => [ "b" ] }.deep_merge({ "a" => [ "c" ] })
=> { "a" => [ "b", "c" ] }
#+END_SRC
- [ ] arrays of Hashes

* Development / Contributing

1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Merge Request

* Contributors

- [[https://github.com/peterhoeg][peterhoeg]] Peter Hoeg - creator, maintainer