diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -109,7 +109,7 @@ impl<'a> Simulation<'a> { println!("Year | Mon | Quota ( Amrtzd + Intrst) | Pending"); for st in self.history.iter() { print!("{st}"); - for update in self.updates.get(st.period) { + for update in flatten_amortizations(self.updates.get(st.period)) { print!(" {update}"); } println!(); @@ -279,3 +279,19 @@ impl SimUpdate { updates } } + +fn flatten_amortizations(updates: Vec<&SimUpdate>) -> Vec<SimUpdate> { + let mut amortized = 0.; + let mut result = vec![]; + for update in updates { + match update { + SimUpdate::Amortize(n) => { + amortized += n; + } + } + } + if amortized > 0. { + result.push(SimUpdate::Amortize(amortized)); + } + result +} |