Skip to content

ngryman/tree-mutate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-mutate

n-ary tree mutation library.

travis codecov

tree-mutate lets you mutate n-ary trees at both structural level and node level. You can apply both homomorphisms or isomorphisms. You can mutate node labels (value). In other words, tree-mutate lets you easily create high-order functions such as map or filter that work well with your specific tree structure.

tree-mutate works around mutators. Those mutators define logic to handle tree mutations. Depending on your needs and your tree structure, you can implement mutators to do whatever you want.

Install

npm install --save tree-mutate

Usage

import mutate from 'tree-mutate'

// add a `depth` property to each node
tree = mutate(tree, (node, context) => { node.depth = context.depth })

// only keep `type` property
tree = mutate(tree, node => pick(node, 'type'))

// filter nodes with type=foo
tree = mutate(tree, node => ('foo' === node.type ? node : null), remover)

See more examples.

API

See the api documentation.

Related

  • tree-morph Little brother of tree-mutate, but for immutable trees.
  • tree-crawl n-ary tree traversal library. This module uses it.

License

MIT © Nicolas Gryman

About

🍃 n-ary tree mutation library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published