forked from extern/nushell
group-by can generate custom grouping key by block evaluation. (#2172)
This commit is contained in:
committed by
GitHub
parent
8551e06d9e
commit
f2c4d22739
@ -7,16 +7,16 @@ use nu_value_ext::as_string;
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn group(
|
||||
values: &Value,
|
||||
grouper: &Option<Box<dyn Fn(&Value) -> Result<String, ShellError> + Send>>,
|
||||
grouper: &Option<Box<dyn Fn(usize, &Value) -> Result<String, ShellError> + Send>>,
|
||||
tag: impl Into<Tag>,
|
||||
) -> Result<Value, ShellError> {
|
||||
let tag = tag.into();
|
||||
|
||||
let mut groups: IndexMap<String, Vec<Value>> = IndexMap::new();
|
||||
|
||||
for value in values.table_entries() {
|
||||
for (idx, value) in values.table_entries().enumerate() {
|
||||
let group_key = if let Some(ref grouper) = grouper {
|
||||
grouper(&value)
|
||||
grouper(idx, &value)
|
||||
} else {
|
||||
as_string(&value)
|
||||
};
|
||||
|
@ -7,7 +7,7 @@ use crate::utils::data::group;
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn split(
|
||||
value: &Value,
|
||||
splitter: &Option<Box<dyn Fn(&Value) -> Result<String, ShellError> + Send>>,
|
||||
splitter: &Option<Box<dyn Fn(usize, &Value) -> Result<String, ShellError> + Send>>,
|
||||
tag: impl Into<Tag>,
|
||||
) -> Result<Value, ShellError> {
|
||||
let tag = tag.into();
|
||||
|
Reference in New Issue
Block a user