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
This commit is contained in:
Stefan Holderbach 2023-07-28 22:12:58 +02:00 committed by GitHub
parent 9448225690
commit 6a7a23e3fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -15,7 +15,7 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("math max") Signature::build("math max")
.input_output_types(vec![ .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![])), (Type::Table(vec![]), Type::Record(vec![])),
]) ])
.allow_variants_without_examples(true) .allow_variants_without_examples(true)
@ -23,7 +23,7 @@ impl Command for SubCommand {
} }
fn usage(&self) -> &str { 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> { fn search_terms(&self) -> Vec<&str> {

View file

@ -15,7 +15,7 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("math min") Signature::build("math min")
.input_output_types(vec![ .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![])), (Type::Table(vec![]), Type::Record(vec![])),
]) ])
.allow_variants_without_examples(true) .allow_variants_without_examples(true)
@ -23,7 +23,7 @@ impl Command for SubCommand {
} }
fn usage(&self) -> &str { 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> { fn search_terms(&self) -> Vec<&str> {
@ -56,6 +56,11 @@ impl Command for SubCommand {
span: Span::test_data(), 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)),
},
] ]
} }
} }