mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:26:22 +02:00
Introduce metadata into the pipeline (#397)
This commit is contained in:
@ -57,14 +57,14 @@ pub fn eval(
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
if let Some(expr) = spanned_expr {
|
||||
match parse(&expr.item, &expr.span) {
|
||||
Ok(value) => Ok(PipelineData::Value(value)),
|
||||
Ok(value) => Ok(PipelineData::Value(value, None)),
|
||||
Err(err) => Err(ShellError::UnsupportedInput(
|
||||
format!("Math evaluation error: {}", err),
|
||||
expr.span,
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
if let PipelineData::Value(Value::Nothing { .. }) = input {
|
||||
if let PipelineData::Value(Value::Nothing { .. }, ..) = input {
|
||||
return Ok(input);
|
||||
}
|
||||
input.map(
|
||||
|
@ -62,12 +62,12 @@ pub fn calculate(
|
||||
mf: impl Fn(&[Value], &Span) -> Result<Value, ShellError>,
|
||||
) -> Result<Value, ShellError> {
|
||||
match values {
|
||||
PipelineData::Stream(s) => helper_for_tables(&s.collect::<Vec<Value>>(), name, mf),
|
||||
PipelineData::Value(Value::List { ref vals, .. }) => match &vals[..] {
|
||||
PipelineData::Stream(s, ..) => helper_for_tables(&s.collect::<Vec<Value>>(), name, mf),
|
||||
PipelineData::Value(Value::List { ref vals, .. }, ..) => match &vals[..] {
|
||||
[Value::Record { .. }, _end @ ..] => helper_for_tables(vals, name, mf),
|
||||
_ => mf(vals, &name),
|
||||
},
|
||||
PipelineData::Value(Value::Record { vals, cols, span }) => {
|
||||
PipelineData::Value(Value::Record { vals, cols, span }, ..) => {
|
||||
let new_vals: Result<Vec<Value>, ShellError> =
|
||||
vals.into_iter().map(|val| mf(&[val], &name)).collect();
|
||||
match new_vals {
|
||||
@ -79,7 +79,7 @@ pub fn calculate(
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
PipelineData::Value(Value::Range { val, .. }) => {
|
||||
PipelineData::Value(Value::Range { val, .. }, ..) => {
|
||||
let new_vals: Result<Vec<Value>, ShellError> = val
|
||||
.into_range_iter()?
|
||||
.map(|val| mf(&[val], &name))
|
||||
@ -87,6 +87,6 @@ pub fn calculate(
|
||||
|
||||
mf(&new_vals?, &name)
|
||||
}
|
||||
PipelineData::Value(val) => mf(&[val], &name),
|
||||
PipelineData::Value(val, ..) => mf(&[val], &name),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user