Update full example in readme

main
Aaron Jensen 2015-08-05 00:39:56 -07:00
parent 78c30e038a
commit 8d0f389106
1 changed files with 28 additions and 18 deletions

View File

@ -33,11 +33,15 @@ supports [partial application][currying], so the parameter order is:
var u = require('updeep'); var u = require('updeep');
var person = { var person = {
name: { name: { first: 'Bill', last: 'Sagat' },
first: 'Bill', children: [
last: 'Sagat', { name: 'Mary-Kate', age: 7 },
}, { name: 'Ashley', age: 7 }
children: ['Marty', 'Ashley'], ],
todo: [
'Be funny',
'Manage household'
],
email: 'bill@example.com', email: 'bill@example.com',
version: 1 version: 1
}; };
@ -45,23 +49,29 @@ var person = {
var inc = function(i) { return i + 1; } var inc = function(i) { return i + 1; }
var newPerson = u({ var newPerson = u({
name: { // Change first name
first: 'Bob', name: { first: 'Bob' },
}, // Increment all children's ages
children: { 0: 'Mary-Kate' }, children: u.map({ age: inc }),
// Update email
email: 'bob@example.com', email: 'bob@example.com',
// Remove todo
todo: u.reject('Be funny'),
// Increment version
version: inc version: inc
}, person); }, person);
// => { // => {
// name: { // name: { first: 'Bob', last: 'Sagat' },
// first: 'Bob', // children: [
// last: 'Sagat', // { name: 'Mary-Kate', age: 8 },
// }, // { name: 'Ashley', age: 8 }
// children: ['Mary-Kate', 'Ashley'], // ],
// email: 'bob@example.com', // todo: [
// version: 2 // 'Manage household'
// } // ],
// email: 'bob@example.com',
// version: 2
//}
``` ```
**NOTE**: All functions are curried, so if you see `f(x(, y))`, it can be called with either `f(x, y)` or `f(x)(y)`. **NOTE**: All functions are curried, so if you see `f(x(, y))`, it can be called with either `f(x, y)` or `f(x)(y)`.