yzx9 / swcgeom

Neuron geometry library for swc format.
Apache License 2.0
6 stars 3 forks source link

Onion-ring `traverse` API #18

Open yzx9 opened 1 month ago

yzx9 commented 1 month ago
def traverse(next):
  enter = do_something() # same as the enter callback
  children = next(enter)
  leave = do_something_else(children) # same as leave the callback
  return leave

Tree.from_swc(...).traverse(traverse)

The advantage of this onion-ring API design is that users can hold a closure to easily retain some information. However, I am not quite sure if such a call would lead to a too deep call stack (in some extreme cases, a neuron may have hundreds of thousands of points).