Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ♻️ more functional Programming #183

Merged
merged 3 commits into from
May 28, 2023
Merged

refactor: ♻️ more functional Programming #183

merged 3 commits into from
May 28, 2023

Conversation

KP64
Copy link
Contributor

@KP64 KP64 commented May 26, 2023

This PR only serves the purpose of cleaning up the Code a bit, be it in form of formatting more functional approaches or compressing functions (map().filter() → filter_map()).

I implemented Add & AddAssign traits for FileCount. This allows for a more functional approach, when calculating the file count, for example.

This:

pub fn compute_file_count(node_id: NodeId, tree: &Arena<Node>) -> FileCount {
    let mut count = FileCount::default();
    for child_id in node_id.children(tree) {
        count.update(tree[child_id].get());
    }
    count
}

became this:

pub fn compute_file_count(node_id: NodeId, tree: &Arena<Node>) -> FileCount {
    node_id
        .children(tree)
        .map(|child_id| tree[child_id].get())
        .fold(FileCount::default(), |acc, node| acc + node)
}

The changes were Tested on WSL (Ubuntu) and it was only checked whether it compiles on Windows (refer to #180 as to why it was not tested on Windows).

Copy link
Owner

@solidiquis solidiquis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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.

2 participants