-
Notifications
You must be signed in to change notification settings - Fork 127
Open
Description
Ratio and Angle cannot be multiplied, because of mismatching Kinds.
Why would I want this to work? Imagine a weighted-mean function, here hard-wired for Length:
pub fn mean_weighted_length(data: &[Length], weights: &[Ratio]) -> Option<Length> {
let total_weight: Ratio = weights.iter().cloned().sum();
data.iter()
.cloned()
.zip(weights.iter().cloned())
.map( |(d, w)| d * w)
.reduce(| a, b | a + b)
.map(|x| x / total_weight)
}I should be able to write such a function for any Quantity, not just Length. And it fails to compile if Length is replaced with Angle:
pub fn mean_weighted_angle(data: &[Angle], weights: &[Ratio]) -> Option<Angle> {
let total_weight: Ratio = weights.iter().cloned().sum();
data.iter()
.cloned()
.zip(weights.iter().cloned())
.map( |(d, w)| d * w)
.reduce(| a, b | a + b)
.map(|x| x / total_weight)
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels