Skip to content

Want a way to iterate through a tree from right to left #107

Closed
@xinxinw1

Description

@xinxinw1

Hi @aureooms, I've been using your Finger tree javascript implementation in an online calculator that I'm building and so far it has been really good and easy to use. However today I found that I needed to iterate through the items of a tree from right to left and realized this was gonna be really difficult to do efficiently without changing your fingertree code.

Would it be possible to add something like an Tree#reverseIter() method or something like it to the tree API that'll efficiently iterate through the tree from right to left like Tree[Symbol.iterator]() does from left to right?

I'm guessing part of the implementation will probably look something like

Deep.prototype.reverseIter = function* () {
	yield* this.left.reverseIter();
	for (const node of reversed(this.middle)) yield* node.reverseIter();
	yield* this.right.reverseIter();
};

but I'm not familiar enough with the code to be sure of the details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apifeatureThis issue is about adding methods to the API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions