mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 03:34:58 +02:00
ListStream
touchup (#12524)
# Description Does some misc changes to `ListStream`: - Moves it into its own module/file separate from `RawStream`. - `ListStream`s now have an associated `Span`. - This required changes to `ListStreamInfo` in `nu-plugin`. Note sure if this is a breaking change for the plugin protocol. - Hides the internals of `ListStream` but also adds a few more methods. - This includes two functions to more easily alter a stream (these take a `ListStream` and return a `ListStream` instead of having to go through the whole `into_pipeline_data(..)` route). - `map`: takes a `FnMut(Value) -> Value` - `modify`: takes a function to modify the inner stream.
This commit is contained in:
@ -183,7 +183,7 @@ used as the next argument to the closure, otherwise generation stops.
|
||||
|
||||
Ok(iter
|
||||
.flatten()
|
||||
.into_pipeline_data(engine_state.ctrlc.clone()))
|
||||
.into_pipeline_data(call.head, engine_state.ctrlc.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
use nu_engine::command_prelude::*;
|
||||
use nu_protocol::ListStream;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Seq;
|
||||
@ -119,36 +120,32 @@ pub fn run_seq(
|
||||
let step = if free.len() > 2 { free[1] } else { 1.0 };
|
||||
let last = { free[free.len() - 1] };
|
||||
|
||||
if !contains_decimals {
|
||||
// integers only
|
||||
Ok(PipelineData::ListStream(
|
||||
nu_protocol::ListStream::from_stream(
|
||||
IntSeq {
|
||||
count: first as i64,
|
||||
step: step as i64,
|
||||
last: last as i64,
|
||||
span,
|
||||
},
|
||||
engine_state.ctrlc.clone(),
|
||||
),
|
||||
None,
|
||||
))
|
||||
let stream = if !contains_decimals {
|
||||
ListStream::new(
|
||||
IntSeq {
|
||||
count: first as i64,
|
||||
step: step as i64,
|
||||
last: last as i64,
|
||||
span,
|
||||
},
|
||||
span,
|
||||
engine_state.ctrlc.clone(),
|
||||
)
|
||||
} else {
|
||||
// floats
|
||||
Ok(PipelineData::ListStream(
|
||||
nu_protocol::ListStream::from_stream(
|
||||
FloatSeq {
|
||||
first,
|
||||
step,
|
||||
last,
|
||||
index: 0,
|
||||
span,
|
||||
},
|
||||
engine_state.ctrlc.clone(),
|
||||
),
|
||||
None,
|
||||
))
|
||||
}
|
||||
ListStream::new(
|
||||
FloatSeq {
|
||||
first,
|
||||
step,
|
||||
last,
|
||||
index: 0,
|
||||
span,
|
||||
},
|
||||
span,
|
||||
engine_state.ctrlc.clone(),
|
||||
)
|
||||
};
|
||||
|
||||
Ok(stream.into())
|
||||
}
|
||||
|
||||
struct FloatSeq {
|
||||
|
Reference in New Issue
Block a user