From 766726d0fa23eab165ec3d960569fb1451aed883 Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 26 Oct 2021 12:35:51 +1300 Subject: [PATCH] Use different helper functions for split column --- crates/nu-command/src/strings/split/column.rs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/nu-command/src/strings/split/column.rs b/crates/nu-command/src/strings/split/column.rs index 6dedde4090..374904907b 100644 --- a/crates/nu-command/src/strings/split/column.rs +++ b/crates/nu-command/src/strings/split/column.rs @@ -54,7 +54,7 @@ fn split_column( let rest: Vec> = call.rest(engine_state, stack, 1)?; let collapse_empty = call.has_flag("collapse-empty"); - input.map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span)) + input.flat_map(move |x| split_column_helper(&x, &separator, &rest, collapse_empty, name_span)) } fn split_column_helper( @@ -63,7 +63,7 @@ fn split_column_helper( rest: &[Spanned], collapse_empty: bool, head: Span, -) -> Value { +) -> Vec { if let Ok(s) = v.as_string() { let splitter = separator.item.replace("\\n", "\n"); @@ -95,24 +95,21 @@ fn split_column_helper( vals.push(Value::string(k, head)); } } - Value::List { - vals: vec![Value::Record { - cols, - vals, - span: head, - }], + vec![Value::Record { + cols, + vals, span: head, - } + }] } else { match v.span() { - Ok(span) => Value::Error { + Ok(span) => vec![Value::Error { error: ShellError::PipelineMismatch { expected: Type::String, expected_span: head, origin: span, }, - }, - Err(error) => Value::Error { error }, + }], + Err(error) => vec![Value::Error { error }], } } }