(Arguments(args): Arguments)
| 407 | } |
| 408 | |
| 409 | pub 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)] |
| 434 | mod tests { |
nothing calls this directly
no test coverage detected