Skip to content

refactor: ♻️ more functional Programming#183

Merged
solidiquis merged 3 commits intosolidiquis:masterfrom
KP64:master
May 28, 2023
Merged

refactor: ♻️ more functional Programming#183
solidiquis merged 3 commits intosolidiquis:masterfrom
KP64:master

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