aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 5eb8b5b..423f607 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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
+}