anru / sprout

A set of functions to work with nested data
BSD 3-Clause "New" or "Revised" License
56 stars 10 forks source link

Please add Array support #7

Closed neekey closed 7 years ago

neekey commented 8 years ago

Hi, really thanks for your great work for creating this module!

I found everything is pretty good but there is no API to support array related manipulation. For the moment i can use assoc and dissoc to manipulate array like:

const arr = [1, 2, 3];
sprout.assoc(arr, 3, 4); // => [1, 2, 3, 4] works good, but you need to specify the index manually
sprout.dissoc(arr, 2); // => [1, 2, undefined], bad result, and the length is still 3

I found https://github.com/mariocasciaro/object-path-immutable 's API is easier to use:

//delete a deep array item (splice)
var newObj = immutable.del(obj, 'a.c.0')
//var obj = {
//  a: {
//    b: 'f',
//    c: ['f']
//  }
//}

//push into a deep array (it will create intermediate objects/arrays if necessary)
var newObj = immutable.push(obj, 'a.d', 'f')
//returns
//var obj = {
//  a: {
//    b: 'f',
//    c: ['d', 'f'],
//    d: ['f']
//  }
//}
jstcki commented 8 years ago

Thanks for the request. I agree that this would be a good addition. Unfortunately, I don't really have time to maintain this module at the moment, and I don't use it myself anymore. So if you'd be interested to maintain it further, I'd be happy to hand it over 😄