Switch tables to list/streams of records

This commit is contained in:
JT
2021-09-07 19:07:11 +12:00
parent 2055b83c34
commit b0ab78a767
11 changed files with 75 additions and 165 deletions

View File

@ -52,7 +52,7 @@ impl Command for Each {
.into_value_stream(),
span: call.head,
}),
Value::List { val, .. } => Ok(Value::ValueStream {
Value::List { vals: val, .. } => Ok(Value::ValueStream {
stream: val
.into_iter()
.map(move |x| {
@ -95,8 +95,6 @@ impl Command for Each {
.into_value_stream(),
span: call.head,
}),
Value::RowStream { .. } => panic!("iterating row streams is not yet supported"),
Value::Table { .. } => panic!("table iteration not yet supported"),
x => {
//TODO: we need to watch to make sure this is okay
let engine_state = context.engine_state.borrow();

View File

@ -68,8 +68,8 @@ impl Command for For {
.into_value_stream(),
span: call.head,
}),
Value::List { val, .. } => Ok(Value::List {
val: val
Value::List { vals: val, .. } => Ok(Value::List {
vals: val
.into_iter()
.map(move |x| {
let engine_state = context.engine_state.borrow();

View File

@ -24,15 +24,7 @@ impl Command for Length {
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
match input {
Value::List { val, .. } => {
let length = val.len();
Ok(Value::Int {
val: length as i64,
span: call.head,
})
}
Value::Table { val, .. } => {
Value::List { vals: val, .. } => {
let length = val.len();
Ok(Value::Int {
@ -48,14 +40,6 @@ impl Command for Length {
span: call.head,
})
}
Value::RowStream { stream, .. } => {
let length = stream.count();
Ok(Value::Int {
val: length as i64,
span: call.head,
})
}
Value::Nothing { .. } => Ok(Value::Int {
val: 0,
span: call.head,