mirror of
https://github.com/nushell/nushell
synced 2025-01-26 11:55:20 +00: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
1 changed files with 12 additions and 7 deletions
|
@ -17,14 +17,15 @@ impl Command for SubCommand {
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("into decimal")
|
Signature::build("into decimal")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(Type::Int, Type::Number),
|
(Type::Int, Type::Float),
|
||||||
(Type::String, Type::Number),
|
(Type::String, Type::Float),
|
||||||
(Type::Bool, Type::Number),
|
(Type::Bool, Type::Float),
|
||||||
|
(Type::Float, Type::Float),
|
||||||
(Type::Table(vec![]), Type::Table(vec![])),
|
(Type::Table(vec![]), Type::Table(vec![])),
|
||||||
(Type::Record(vec![]), Type::Record(vec![])),
|
(Type::Record(vec![]), Type::Record(vec![])),
|
||||||
(
|
(
|
||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Number)),
|
Type::List(Box::new(Type::Float)),
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.rest(
|
.rest(
|
||||||
|
@ -76,9 +77,12 @@ impl Command for SubCommand {
|
||||||
result: Some(Value::test_float(1.345)),
|
result: Some(Value::test_float(1.345)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert decimal to decimal",
|
description: "Coerce list of ints and floats to float",
|
||||||
example: "'-5.9' | into decimal",
|
example: "[4 -5.9] | into decimal",
|
||||||
result: Some(Value::test_float(-5.9)),
|
result: Some(Value::test_list(vec![
|
||||||
|
Value::test_float(4.0),
|
||||||
|
Value::test_float(-5.9),
|
||||||
|
])),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Convert boolean to decimal",
|
description: "Convert boolean to decimal",
|
||||||
|
@ -91,6 +95,7 @@ impl Command for SubCommand {
|
||||||
|
|
||||||
fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value {
|
||||||
match input {
|
match input {
|
||||||
|
Value::Float { .. } => input.clone(),
|
||||||
Value::String { val: s, span } => {
|
Value::String { val: s, span } => {
|
||||||
let other = s.trim();
|
let other = s.trim();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue