__get_iter is a bit of a mess. It handles both creating a node iterator AND printing functionality.
filter_ tells us to only print nodes meeting some user-specified property. filter_ is a function. You input a node into filter_ and filter returns true (print the node) or false (don't print the node). Do not get me wrong, that's a perfectly reasonable thing to want to do. I only mention what filter_ is so that we can see how to decouple making node iterators and printing.
key and reverse tell us how to order the nodes for printing purposes. reverse is a Boolean, which says to print the nodes in reverse order. key allows more complicated node orderings than a mere reversal.
dt is a container of three elements:
dt_vline
dt_line_box
dt_line_cor.
Each element is a string of characters used in printing:
dt_vline is something like "|"
dt_line_box is something like "|-- "
dt_line_cor is something like '+-- '
The code would be much cleaner if the back-end function which constructs and returns a node iterator knew nothing about printing, and the printing functionality used node iterators without knowing about filter_key or reverse
The function with generates a node iterator would use filter_key and reverse but not dt, dt_vline, dt_line_box, dt_line_cor.
After generating a node-iterator you pass the node-iterator to the printing function. The printing function does not know if the iterator it just received loops over ALL nodes, SOME of the nodes, nodes in forward order, nodes in backward order, etc... The printer doesn't need to know. It just needs a node iterator.
__get_iter
is a bit of a mess. It handles both creating a node iterator AND printing functionality.filter_
tells us to only print nodes meeting some user-specified property.filter_
is a function. You input a node intofilter_
and filter returnstrue
(print the node) orfalse
(don't print the node). Do not get me wrong, that's a perfectly reasonable thing to want to do. I only mention whatfilter_
is so that we can see how to decouple making node iterators and printing.key
andreverse
tell us how to order the nodes for printing purposes.reverse
is a Boolean, which says to print the nodes in reverse order.key
allows more complicated node orderings than a mere reversal.dt
is a container of three elements:dt_vline
dt_line_box
dt_line_cor
. Each element is a string of characters used in printing:dt_vline
is something like "|"dt_line_box
is something like "|-- "dt_line_cor
is something like '+-- 'The code would be much cleaner if the back-end function which constructs and returns a node iterator knew nothing about printing, and the printing functionality used node iterators without knowing about
filter_
key
orreverse
The function with generates a node iterator would use
filter_
key
andreverse
but notdt
,dt_vline
,dt_line_box
,dt_line_cor
.After generating a node-iterator you pass the node-iterator to the printing function. The printing function does not know if the iterator it just received loops over ALL nodes, SOME of the nodes, nodes in forward order, nodes in backward order, etc... The printer doesn't need to know. It just needs a node iterator.