feat: implement comparison skeleton
This commit lays out the general idea of how the ComparisonData struct will work. It is expandable and I'm sure we will add more to it as time goes on.
This commit is contained in:
1 parent
431a8f244a
commit
83e46f4064
17 files changed
+1161
-89
No files matched your search
@@ -0,0 +1,23 @@
|
||||
use crate::common::{ExpandableInfo, ValueType};
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
pub fn get_number_list(student_info: &ExpandableInfo, member: &String) -> Result<Vec<f64>, String> {
|
||||
match student_info.data.get(member) {
|
||||
Some(ValueType::List(Some(list))) => {
|
||||
let temp = list.iter().try_fold(vec![], |mut list_acc, item| {
|
||||
if let ValueType::Number(Some(number)) = item {
|
||||
list_acc.push(number.parse::<f64>().unwrap());
|
||||
ControlFlow::Continue(list_acc)
|
||||
} else {
|
||||
ControlFlow::Break(list_acc)
|
||||
}
|
||||
});
|
||||
|
||||
match temp {
|
||||
ControlFlow::Continue(list) => Ok(list),
|
||||
ControlFlow::Break(_) => return Err("List contains non-number values".to_owned()),
|
||||
}
|
||||
}
|
||||
_ => return Err("Couldn't find the list".to_owned()),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user