Skip to content

Tree structures#3

Merged
ArachnidAbby merged 8 commits intomainfrom
tree_structures
Apr 15, 2026
Merged

Tree structures#3
ArachnidAbby merged 8 commits intomainfrom
tree_structures

Conversation

@ArachnidAbby
Copy link
Copy Markdown
Member

Description

Add in new NTree datastructure that makes working with tree datastructures extremely easy.

class ModuleName:
  ...

class Module:
  ...

class ModuleView:
  ...

class Package(NTree[ModuleView, str]):
    """An example of an extension of NTree"""
  ... #impl in full file


imports = Package(
    identifier="base",
    leaves=[
        Module("main", private=True),
        Module("other_mod"),
        Package(
            identifier="lib",
            leaves=[
                Module("math"),
                Module("system"),
                Module("err"),
                Package(
                    identifier="ui",
                    leaves=[
                        Module("application"),
                        Module("widgets"),
                        Module("internal_stuff", private=True),
                        Package(
                            identifier="bindings",
                            leaves=[
                                Module("application", private=True),
                                Module("widgets", private=True),
                            ],
                        ),
                    ],
                ),
            ],
        ),
    ],
)

# NTree supports:
#  - intersection via `&` operator
#  - combining via `|` op
#  - custom leaf initialization (useful for those ModuleView classes)
#  - Two kinds of indexing (NTree indexing and Leaf node indexing) via the index operator
#  - Comparison via `==`
#  - arbitrary tree/leaf matching (via common interface/protocol)
#  - Fully supported type annotation that work fantastically (avoiding bare type unions and instead using overloads to provide more accurate typing when calling a function or using an operator)

@ArachnidAbby ArachnidAbby merged commit 091c040 into main Apr 15, 2026
1 check passed
@ArachnidAbby ArachnidAbby deleted the tree_structures branch April 15, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant