mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
Improve I/O types of into decimal
(/float) (#9998)
# Description - Add identity cast to `into decimal` (float->float) - Correct `into decimal` output to concrete float # User-Facing Changes `1.23 | into decimal` will now work. By fixing the output type it can now be used in conjunction with commands that expect `float`/`list<float>` # Tests + Formatting Adapts example to do identity cast and heterogeneous cast
This commit is contained in:
parent
3bd46fe27a
commit
5d94b16d71
@ -17,14 +17,15 @@ impl Command for SubCommand {
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("into decimal")
|
||||
.input_output_types(vec![
|
||||
(Type::Int, Type::Number),
|
||||
(Type::String, Type::Number),
|
||||
(Type::Bool, Type::Number),
|
||||
(Type::Int, Type::Float),
|
||||
(Type::String, Type::Float),
|
||||
(Type::Bool, Type::Float),
|
||||
(Type::Float, Type::Float),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(
|
||||
Type::List(Box::new(Type::Any)),
|
||||
Type::List(Box::new(Type::Number)),
|
||||
Type::List(Box::new(Type::Float)),
|
||||
),
|
||||
])
|
||||
.rest(
|
||||
@ -76,9 +77,12 @@ impl Command for SubCommand {
|
||||
result: Some(Value::test_float(1.345)),
|
||||
},
|
||||
Example {
|
||||
description: "Convert decimal to decimal",
|
||||
example: "'-5.9' | into decimal",
|
||||
result: Some(Value::test_float(-5.9)),
|
||||
description: "Coerce list of ints and floats to float",
|
||||
example: "[4 -5.9] | into decimal",
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_float(4.0),
|
||||
Value::test_float(-5.9),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Convert boolean to decimal",
|
||||
@ -91,6 +95,7 @@ impl Command for SubCommand {
|
||||
|
||||
fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
||||
match input {
|
||||
Value::Float { .. } => input.clone(),
|
||||
Value::String { val: s, span } => {
|
||||
let other = s.trim();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user