From 6a7a23e3fafcee6bd291496647350605867ab28d Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Fri, 28 Jul 2023 22:12:58 +0200 Subject: [PATCH] Fix `math min`/`max` signatures (#9830) # Description Under the hood those are just `Value::partial_cmp` and this is defined for all values and defines a partial order over `any` Should address part of https://github.com/nushell/nushell/issues/9813 # User-Facing Changes Reenable all behavior before `0.83` # Tests + Formatting Added an example to `math min` showing this cursedness --- crates/nu-command/src/math/max.rs | 4 ++-- crates/nu-command/src/math/min.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/math/max.rs b/crates/nu-command/src/math/max.rs index fdfc993946..33c57717f5 100644 --- a/crates/nu-command/src/math/max.rs +++ b/crates/nu-command/src/math/max.rs @@ -15,7 +15,7 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("math max") .input_output_types(vec![ - (Type::List(Box::new(Type::Number)), Type::Number), + (Type::List(Box::new(Type::Any)), Type::Any), (Type::Table(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) @@ -23,7 +23,7 @@ impl Command for SubCommand { } fn usage(&self) -> &str { - "Returns the maximum of a list of numbers, or of columns in a table." + "Returns the maximum of a list of values, or of columns in a table." } fn search_terms(&self) -> Vec<&str> { diff --git a/crates/nu-command/src/math/min.rs b/crates/nu-command/src/math/min.rs index 2cb3458125..e89f792200 100644 --- a/crates/nu-command/src/math/min.rs +++ b/crates/nu-command/src/math/min.rs @@ -15,7 +15,7 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("math min") .input_output_types(vec![ - (Type::List(Box::new(Type::Number)), Type::Number), + (Type::List(Box::new(Type::Any)), Type::Any), (Type::Table(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) @@ -23,7 +23,7 @@ impl Command for SubCommand { } fn usage(&self) -> &str { - "Finds the minimum within a list of numbers or tables." + "Finds the minimum within a list of values or tables." } fn search_terms(&self) -> Vec<&str> { @@ -56,6 +56,11 @@ impl Command for SubCommand { span: Span::test_data(), }), }, + Example { + description: "Find the minimum of a list of arbitrary values (Warning: Weird)", + example: "[-50 'hello' true] | math min", + result: Some(Value::test_bool(true)), + }, ] } }