11 Matching Annotations
  1. Mar 2021
    1. A one-liner alternative for hash-only cases can be implemented using Enumerable#reduce: root = {} [:a, :b, :c].reduce(root){@1[@2]||={}}[:d] = 'E' # root => {:a=>{:b=>{:c=>{:d=>"E"}}}}
    2. I think the issues/problems specified in the comments are not present with a Hash-only implementation. :) I would be supportive of re-considering this feature just for use with a Hash, where I believe 80% of the real-life use cases would (and do) exist. I have encountered this need before in the wild, but not with Arrays.
    3. Would it be desirable to specify the new object in a block? That would make it somewhat symmetrical to how Hash.new takes a block as a default value.
    1. // A general key transform method. Pass it a function that accepts the old key and returns // the new key. // // @example // obj = transformKeys(obj, (key) => ( // key.replace(/\b(big)\b/g, 'little') // )) export function transformKeys(source, f) { return Object.entries(source).reduce((o, [key, value]) => { o[f(key) || key] = value return o }, {}) } // Provide an object that maps from old key to new key export function rekeyObject(source, keyMap) { transformKeys(source, key => keyMap[key]) }
    2. function objectMap(source,keyMap) { return Object.entries(keyMap).reduce((o,[key , newKey]) => { o[newKey]=source[key] return o;},{}) }
    1. There’s no additional logic from Trailblazer happening here. The function returns a well-defined hash which is passed as an argument to step.
  2. Feb 2021
    1. array :translations do hash do string :locale string :name end end array inputs can only have one input nested underneath them. This is because every element of the array must be the same type. And the inputs nested inside arrays cannot have names because they would never be used.