making things more functional

This commit is contained in:
kevin zhao
2025-11-12 14:11:48 -05:00
parent 2f8d3f6b42
commit 8c909a0084
2 changed files with 4 additions and 15 deletions

View File

@@ -92,8 +92,7 @@ fn parse_pattern<'v>(pattern: UnpackList<Value<'v>>) -> Result<Vec<PatternToken>
fn parse_pattern_token<'v>(value: Value<'v>) -> Result<PatternToken> {
if let Some(s) = value.unpack_str() {
Ok(PatternToken::Single(s.to_string()))
}
else if let Some(list) = ListRef::from_value(value) {
} else if let Some(list) = ListRef::from_value(value) {
let tokens: Vec<String> = list
.content()
.iter()

View File

@@ -44,19 +44,9 @@ impl Policy {
None => return Evaluation::NoMatch,
};
let mut matched_rules: Vec<RuleMatch> = Vec::new();
let mut strictest_decision: Option<Decision> = None;
for rule in rules {
if let Some(matched) = rule.matches(cmd) {
let decision = match strictest_decision {
None => matched.decision(),
Some(current) => std::cmp::max(matched.decision(), current),
};
strictest_decision = Some(decision);
matched_rules.push(matched);
}
}
match strictest_decision {
let matched_rules: Vec<RuleMatch> =
rules.iter().filter_map(|rule| rule.matches(cmd)).collect();
match matched_rules.iter().map(RuleMatch::decision).max() {
Some(decision) => Evaluation::Match {
decision,
matched_rules,