0.0.3 ⢠Published 6 years ago
@bhurlow/tree.walk v0.0.3
š²
tree.walk
An implementation of clojure's walk functions for javascript. Use this for generic tree traversal operations over nested objects and arrays.
example
postwalk
performs a depth-first post-order traversal of the provided (possibly nested) data structure. Uses provided function's return value in place of the original
const { postwalk } = require('./index')
const input = [[1, 2], [3, [4, 5]]]
const res = postwalk(
val => {
if (typeof val == 'number') {
return val * 5
}
return val
},
input
)
=> [ [ 5, 10 ], [ 15, [ 20, 25 ] ] ]
API
walk(inner, outer, form)
applies inner
to the innermost items in the collection, and outer
to the wrapping whole
postwalk(f, form)
depth-first post-order
prewalk(f, form)
depth-first pre-order
0.0.3
6 years ago