feat: add keep_lowest method to Outcome

This commit is contained in:
2025-11-19 10:19:47 +01:00
parent d29fa81fbb
commit 3a3c1487bb
2 changed files with 22 additions and 0 deletions

View File

@@ -5,3 +5,4 @@ pub mod outcome_keep_highest;
pub mod outcome_max;
pub mod outcome_min;
pub mod outcome_sum;
pub mod outcome_keep_lowest;

View File

@@ -0,0 +1,21 @@
use crate::*;
impl Outcome {
pub fn keep_lowest(self, dice_num: u16) -> Result<Outcome, FailedTo> {
if dice_num == 0 {
return Err(FailedTo::ProcessInput);
}
match self {
Outcome::Scalar(value) => Ok(Outcome::List(vec![value])),
Outcome::List(mut values) => {
values.sort();
Ok(Outcome::List(
values.into_iter().take(dice_num as usize).collect(),
))
}
}
}
}
// #[cfg(test)]
// mod unit_tests { use super::*; }