Skip to content

Commit

Permalink
Merge pull request #3 from phillip-wenig-frequenz/remove-unwrap
Browse files Browse the repository at this point in the history
Remove `unwrap` from partial equation evaluation
  • Loading branch information
phillip-wenig-frequenz authored Nov 26, 2024
2 parents 607f075 + 3998a64 commit d99f9e2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,15 @@ impl Function {
(None, Some(x)) => Some(x),
(None, None) => None,
}),
Function::Max => values
.iter()
.copied()
.max_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap_or_default(),
Function::Max => values.iter().copied().fold(None, |acc, x| match (acc, x) {
(Some(acc), Some(x)) => match acc.partial_cmp(&x) {
Some(std::cmp::Ordering::Greater) => Some(acc),
_ => Some(x),
},
(Some(acc), None) => Some(acc),
(None, Some(x)) => Some(x),
(None, None) => None,
}),
}
}
}

0 comments on commit d99f9e2

Please sign in to comment.