Skip to content

Commit

Permalink
updated readme for hash traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Aug 27, 2010
1 parent 0f11600 commit a56b629
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,25 @@ use.
, '55': { id: 55, f: [Function], path: [ 'foo', '3' ] }
}
*/

Hash Transforms
===============

There's also a hash lib in this distribution for writing maps, filters, and
folds over hashes.

> var Hash = require('traverse/hash')
> Hash({ a : 1, b : 2 }).map(function (v) { return v + 1 }).end
{ a: 2, b: 3 }

To do the same thing without chaining:

> Hash.map({ a : 1, b : 2 }, function (v) { return v + 1 })
{ a: 2, b: 3 }

Hash supports map(), filter(), and reduce(). In the first style, you can chain
together operations before the ".end". Each callback is executed like this:
f.call(hash, value, key)

See also "creationix's pattern/hash":http://github.com/creationix/pattern, which
does a similar thing except with hash inputs and array outputs.

0 comments on commit a56b629

Please sign in to comment.