Skip to content

Refactor map_account_summary_aggregate to use idiomatic iterator methods#1012

Merged
gemcoder21 merged 2 commits intocodex/hip-3-perpsfrom
copilot/sub-pr-1009
Mar 16, 2026
Merged

Refactor map_account_summary_aggregate to use idiomatic iterator methods#1012
gemcoder21 merged 2 commits intocodex/hip-3-perpsfrom
copilot/sub-pr-1009

Conversation

Copy link
Contributor

Copilot AI commented Mar 15, 2026

map_account_summary_aggregate used manual loops with mutable accumulators. Replaced with map/flat_map/sum iterator chains.

// Before
let mut account_value = 0.0;
for positions in positions {
    account_value += positions.margin_summary.account_value.parse::<f64>().unwrap_or(0.0);
    for position in &positions.asset_positions {
        unrealized_pnl += position.position.unrealized_pnl.parse::<f64>().unwrap_or(0.0);
    }
}

// After
let account_value: f64 = positions.iter().map(|p| p.margin_summary.account_value.parse().unwrap_or(0.0)).sum();
let unrealized_pnl: f64 = positions.iter().flat_map(|p| &p.asset_positions).map(|p| p.position.unrealized_pnl.parse().unwrap_or(0.0)).sum();

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback from review on reopening HIP3 support PR Refactor map_account_summary_aggregate to use idiomatic iterator methods Mar 15, 2026
Copilot AI requested a review from gemcoder21 March 15, 2026 23:11
@gemcoder21 gemcoder21 marked this pull request as ready for review March 16, 2026 02:15
@gemcoder21 gemcoder21 merged commit 7da2811 into codex/hip-3-perps Mar 16, 2026
@gemcoder21 gemcoder21 deleted the copilot/sub-pr-1009 branch March 16, 2026 02:15
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