MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / min

Function min

cel/src/functions.rs:409–431  ·  view source on GitHub ↗
(Arguments(args): Arguments)

Source from the content-addressed store, hash-verified

407}
408
409pub fn min(Arguments(args): Arguments) -> Result<Value> {
410 // If items is a list of values, then operate on the list
411 let items = if args.len() == 1 {
412 match &args[0] {
413 Value::List(values) => values,
414 _ => return Ok(args[0].clone()),
415 }
416 } else {
417 &args
418 };
419
420 items
421 .iter()
422 .skip(1)
423 .try_fold(items.first().unwrap_or(&Value::Null), |acc, x| {
424 match acc.partial_cmp(x) {
425 Some(Ordering::Less) => Ok(acc),
426 Some(_) => Ok(x),
427 None => Err(ExecutionError::ValuesNotComparable(acc.clone(), x.clone())),
428 }
429 })
430 .cloned()
431}
432
433#[cfg(test)]
434mod tests {

Callers

nothing calls this directly

Calls 3

cloneMethod · 0.80
iterMethod · 0.45
partial_cmpMethod · 0.45

Tested by

no test coverage detected