Repository: nushell/nushell
File: crates/nu-command/src/filters/drop/nth.rs (Rust)

Code before:
                                let start_usize = start as usize;
                                min_unbounded_start = Some(
                                    min_unbounded_start.map_or(start_usize, |s| s.min(start_usize)),
                                );
                            }
                        }
                    }
                    Range::FloatRange(_) => {
                        return Err(ShellError::UnsupportedInput {
                            msg: "float range not supported".into(),
                            input: "value originates from here".into(),
                            msg_span: head,
                            input_span: value.span(),
                        });
                    }
                }
            } else {
                return Err(ShellError::TypeMismatch {
                    err_message: "Expected int or range".into(),
                    span: value.span(),
                });
            }
        }

        rows_to_drop.sort_unstable();
        rows_to_drop.dedup();

        let input = if let Some(cutoff) = min_unbounded_start {
            input
                .into_iter()
                .take(cutoff)
                .into_pipeline_data_with_metadata(
                    head,
                    engine_state.signals().clone(),
                    metadata.clone(),
                )
        } else {
            input
        };

        Ok(DropNthIterator {
            input: input.into_iter(),
            rows: rows_to_drop,
            current: 0,
        }
        .into_pipeline_data_with_metadata(
            head,
            engine_state.signals().clone(),
            metadata.clone(),
        ))
    }

Review comment (bug):
~~I know this isn't from your implementation, but while we're changing things could you add `rows_to_drop.reverse()` here, and then change `self.rows.first()` to `self.rows.back()` and `self.rows.remove(0)` to `self.rows.pop()`? It bugs me that we're shifting all of the rows each iteration instead of just popping off the back~~

nevermind, this isn't correct because the final row might be after the final iterator element. Instead, could we use `VecDeque` and `pop_front`?

Code after:
                                    msg: "The upper bound must be greater than the lower bound"
                                        .into(),
                                    input: "value originates from here".into(),
                                    msg_span: head,
                                    input_span: value.span(),
                                });
                            }
                            rows_to_drop.extend((start as usize)..(end as usize));
                        }
                        Bound::Unbounded => {
                            let start_usize = start as usize;
                            min_unbounded_start = Some(
                                min_unbounded_start.map_or(start_usize, |s| s.min(start_usize)),
                            );
                        }
                    }
                }
                Range::FloatRange(_) => {
                    return Err(ShellError::UnsupportedInput {
                        msg: "float range not supported".into(),
                        input: "value originates from here".into(),
                        msg_span: head,
                        input_span: value.span(),
                    });
                }
            }
        } else {
            return Err(ShellError::TypeMismatch {
                err_message: "Expected int or range".into(),
                span: value.span(),
            });
        }
    }

    rows_to_drop.sort_unstable();
    rows_to_drop.dedup();

    Ok((VecDeque::from(rows_to_drop), min_unbounded_start))
}

struct DropNthIterator {
    input: PipelineIterator,
    rows: VecDeque<usize>,
    current: usize,
}

impl Iterator for DropNthIterator {
    type Item = Value;

    fn next(&mut self) -> Option<Self::Item> {
        loop {