mirror of
https://github.com/openai/codex.git
synced 2026-05-04 21:32:21 +03:00
making things more functional
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user