At the moment, a lot of copying and extra memory is consumed by keeping hold of the remaining path in the object*. It's perfectly possible to simple pass the depth, and derive the path from that, the key and the hashPath function (possibly memoized).
Try it out for possible perf boost, and implementation simplificaiton.
ironically, given that i'm not implementing them, this would be a fantastic use of persistent singly linked lists.
At the moment, a lot of copying and extra memory is consumed by keeping hold of the remaining path in the object*. It's perfectly possible to simple pass the depth, and derive the path from that, the key and the hashPath function (possibly memoized).
Try it out for possible perf boost, and implementation simplificaiton.