leafParentIter
Iterable
leafParentIter(node, getParentNode)
iterates child->parent
todo: hmm, should or should not the initial node be part of the iteration?
- Parameters:
-
node <object> -
getParentNode <function>
- Returns:
Iterable
pairIter
Iterable
pairIter(iterable)
Pairwise view of an iterable (overlapping)
[a, b, c, d, ..] -> [[a,b],[b,c],[c,d], ..]
todo: generalize to full n-tuples (fifo queue) and configurable start and end logic (offset, clamp, wraparound etc) (windowIter?)
- Parameters:
-
iterable <Iterable>
- Returns:
Iterable
treeLevelOrderIter
Iterable
treeLevelOrderIter(rootNode, getChildNodes)
top-down, breadth-first, level-order traversal (parent->siblings order)
ref tree traversal
(could be seen as an iterator version of MochiKit.Base.nodeWalk())
useful for searching and culling
todo: create version taking a descend-predicate if used for culling
todo: hmm, would be nice to have some version that would indicate each level (useful when doing searches for example)
- Parameters:
-
rootNode <object> -
getChildNodes <function(node)>should return an empty array if no children
- Returns:
Iterable
treeLevelOrderIterIf
void
treeLevelOrderIterIf(rootNode, getChildNodes, predicate)
predicate decides if the branch will be descended into
todo: this could be done using any depth-first iter (preOrderIter) also.
todo: create tri-state version. i.e a path where it descends into subtree but stops checking if parent was flagged (completely) visible.
rename cullingIter?
- Parameters:
-
rootNode <object> -
getChildNodes <function> -
predicate <function>(unary)
- Returns:
void
treePostOrderIter
Iterable
treePostOrderIter(rootNode, getChildNodes)
bottom-up iteration
ref tree traversal
useful for pruning for example.
- Parameters:
-
rootNode <object> -
getChildNodes <function(node)>should return an empty array if no children
- Returns:
Iterable
treePreOrderIter
Iterable
treePreOrderIter(rootNode, getChildNodes)
parent->child order (depth-first, preorder)
ref tree traversal
- Parameters:
-
rootNode <object> -
getChildNodes <function>(ex: for dom traversal usetreePreOrderIter(dom, methodcaller('childNodes'));)
- Returns:
Iterable