Repository: astral-sh/uv
File: crates/uv/src/commands/pip/tree.rs (Rust)

Code before:
            // This observation is true recursively even when looking at the subtree rooted
            // at `level_1_0`.
            let (prefix_top, prefix_rest) = if dependencies.len() - 1 == index {
                ("└── ", "    ")
            } else {
                ("├── ", "│   ")
            };

            for (visited_index, visited_line) in self.visit(dep, visited, path).iter().enumerate() {
                let prefix = if visited_index == 0 {
                    prefix_top
                } else {
                    prefix_rest
                };

                lines.push(format!("{prefix}{visited_line}"));
            }
        }
        path.pop();

        lines
    }

    /// Aggregate the requirements associated with the incoming edges for a node.
    fn aggregate_requirement(&self, cursor: &Cursor) -> Option<String> {
        let (url, specifiers) = cursor.edge_ids().iter().fold(
            (None::<String>, Vec::new()),
            |(url, mut specs), edge_id| {
                let requirement = &self.graph[*edge_id];

                let url = match requirement.version_or_url.as_ref() {
                    None => url,
                    Some(VersionOrUrl::VersionSpecifier(values)) => {
                        specs.extend(values.iter().cloned());
                        url
                    }
                    Some(VersionOrUrl::Url(value)) => url.or_else(|| Some(value.to_string())),
                };

                (url, specs)
            },
        );

        if let Some(url) = url {
            return Some(url);
        }

        if specifiers.is_empty() {
            return None;
        }


Review comment (suggestion):
`fold` usually harder to read than the imperative versions, I'd use a `for` loop here and early `return` if it encounters a `Url`.

Code after:
            // This observation is true recursively even when looking at the subtree rooted
            // at `level_1_0`.
            let (prefix_top, prefix_rest) = if dependencies.len() - 1 == index {
                ("└── ", "    ")
            } else {
                ("├── ", "│   ")
            };

            for (visited_index, visited_line) in self.visit(dep, visited, path).iter().enumerate() {
                let prefix = if visited_index == 0 {
                    prefix_top
                } else {
                    prefix_rest
                };

                lines.push(format!("{prefix}{visited_line}"));
            }
        }
        path.pop();

        lines
    }

    /// Aggregate the requirements associated with the incoming edges for a node.
    fn aggregate_requirement(&self, cursor: &Cursor) -> Option<String> {
        let mut specifiers = Vec::new();

        for edge_id in cursor.edge_ids() {
            let requirement = &self.graph[*edge_id];

            let Some(version_or_url) = requirement.version_or_url.as_ref() else {
                continue;
            };

            match version_or_url {
                VersionOrUrl::VersionSpecifier(values) => {
                    specifiers.extend(values.iter().cloned());
                }
                VersionOrUrl::Url(value) => return Some(value.to_string()),
            }
        }

        if specifiers.is_empty() {
            return None;
        }

        let display = Self::simplify_specifiers(specifiers).to_string();

        if display.is_empty() {
            None
        } else {