nushell/crates/nu-command/tests/commands/mod.rs
Ian Manske 0918050ac8
Deprecate group in favor of chunks (#13377)
# Description
The name of the `group` command is a little unclear/ambiguous.
Everything I look at it, I think of `group-by`. I think `chunks` more
clearly conveys what the `group` command does. Namely, it divides the
input list into chunks of a certain size. For example,
[`slice::chunks`](https://doc.rust-lang.org/std/primitive.slice.html#method.chunks)
has the same name. So, this PR adds a new `chunks` command to replace
the now deprecated `group` command.

The `chunks` command is a refactored version of `group`. As such, there
is a small performance improvement:
```nushell
# $data is a very large list
> bench { $data | chunks 2 } --rounds 30 | get mean
474ms 921µs 190ns

# deprecation warning was disabled here for fairness
> bench { $data | group 2 } --rounds 30 | get mean
592ms 702µs 440ns



> bench { $data | chunks 200 } --rounds 30 | get mean
374ms 188µs 318ns

> bench { $data | group 200 } --rounds 30 | get mean
481ms 264µs 869ns 



> bench { $data | chunks 1 } --rounds 30 | get mean
642ms 574µs 42ns

> bench { $data | group 1 } --rounds 30 | get mean
981ms 602µs 513ns
```

# User-Facing Changes
- `group` command has been deprecated in favor of new `chunks` command.
- `chunks` errors when given a chunk size of `0` whereas `group` returns
chunks with one element.

# Tests + Formatting
Added tests for `chunks`, since `group` did not have any tests.

# After Submitting
Update book if necessary.
2024-07-16 03:49:00 +00:00

134 lines
1.6 KiB
Rust

mod alias;
mod all;
mod any;
mod append;
mod assignment;
mod break_;
mod bytes;
mod cal;
mod cd;
mod chunks;
mod compact;
mod complete;
mod config_env_default;
mod config_nu_default;
mod continue_;
mod conversions;
#[cfg(feature = "sqlite")]
mod database;
mod date;
mod debug_info;
mod def;
mod default;
mod detect_columns;
mod do_;
mod drop;
mod du;
mod each;
mod echo;
mod empty;
mod error_make;
mod every;
mod exec;
mod export_def;
mod fill;
mod filter;
mod find;
mod first;
mod flatten;
mod for_;
mod format;
mod generate;
mod get;
mod glob;
mod griddle;
mod group_by;
mod hash_;
mod headers;
mod help;
mod histogram;
mod ignore;
mod insert;
mod inspect;
mod interleave;
mod into_datetime;
mod into_filesize;
mod into_int;
mod join;
mod last;
mod length;
mod let_;
mod lines;
mod loop_;
mod ls;
mod match_;
mod math;
mod merge;
mod mktemp;
mod move_;
mod mut_;
mod network;
mod nu_check;
mod open;
mod par_each;
mod parse;
mod path;
mod platform;
mod prepend;
mod print;
#[cfg(feature = "sqlite")]
mod query;
mod random;
mod range;
mod redirection;
mod reduce;
mod reject;
mod rename;
mod return_;
mod reverse;
mod rm;
mod roll;
mod rotate;
mod run_external;
mod save;
mod select;
mod semicolon;
mod seq;
mod seq_char;
mod seq_date;
mod skip;
mod sort;
mod sort_by;
mod source_env;
mod split_by;
mod split_column;
mod split_row;
mod str_;
mod table;
mod take;
mod tee;
mod terminal;
mod to_text;
mod touch;
mod transpose;
mod try_;
mod ucp;
#[cfg(unix)]
mod ulimit;
mod debug;
mod umkdir;
mod uname;
mod uniq;
mod uniq_by;
mod update;
mod upsert;
mod url;
mod use_;
mod where_;
mod which;
mod while_;
mod with_env;
mod wrap;
mod zip;