3 ms·
This is really cool. Did you ever consider an API to do the reverse - to insert a value at a particular point in the data? My interest stems from this issue[0]
by faitswulff 8y ago
This is really cool. Did you ever consider an API to do the reverse - to insert a value at a particular point in the data?
My interest stems from this issue[0] on the Ruby issue tracker to make a symmetrical method to Hash#dig (which does something similar to, but more limited than glom) called Hash#bury. The problem in the issue was that inserting a value at a given index in an array proved difficult and unnatural in Ruby, so I was wondering if there were other solutions out there.
Another question occurs to me - does glom only support string keys?
[0]: https://bugs.ruby-lang.org/issues/11747 https://bugs.ruby-lang.org/issues/11747
- mhashemi 8y agoglom not only supports more than string keys, it also supports assigning to non-dictionary objects. That's a part of the API we're working on right now, actually. As for the data insertion, mutation may be in the future, but for now glom only transforms and returns new objects. Definitely something to think about though, bookmarked! :)
- hiccuphippo 8y agoCheck the updateIn, mergeIn, mergeDeepIn methods in immutable.js. Maybe even asMutable, asImmutable for mutation.
- doublereedkurt 8y ago'string-key', T['string-key'], T[not-string-key] :-)
- smittywerben 8y agoPerhaps assoc_in or update_in from the Toolz library fits this? https://toolz.readthedocs.io/en/latest/api.html#toolz.dicttoolz.assoc_in https://toolz.readthedocs.io/en/latest/api.html#toolz.dictto... https://toolz.readthedocs.io/en/latest/api.html#toolz.dicttoolz.update_in https://toolz.readthedocs.io/en/latest/api.html#toolz.dictto...