mirror of
https://github.com/nushell/nushell
synced 2024-12-25 04:23:10 +00:00
docs(reduce): add example demonstrating accumulator as pipeline input (#14593)
# Description Add an example to `reduce` that shows accumulator can also be accessed pipeline input. # User-Facing Changes N/A # Tests + Formatting - 🟢 toolkit fmt - 🟢 toolkit clippy - 🟢 toolkit test - 🟢 toolkit test stdlib # After Submitting N/A
This commit is contained in:
parent
baf86dfb0e
commit
3c632e96f9
1 changed files with 11 additions and 2 deletions
|
@ -88,6 +88,15 @@ impl Command for Reduce {
|
|||
"Concatenate a string with itself, using a range to determine the number of times.",
|
||||
result: Some(Value::test_string("StrStrStr")),
|
||||
},
|
||||
Example {
|
||||
example: r#"[{a: 1} {b: 2} {c: 3}] | reduce {|it| merge $it}"#,
|
||||
description: "Merge multiple records together, making use of the fact that the accumulated value is also supplied as pipeline input to the closure.",
|
||||
result: Some(Value::test_record(record!(
|
||||
"a" => Value::test_int(1),
|
||||
"b" => Value::test_int(2),
|
||||
"c" => Value::test_int(3),
|
||||
))),
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -135,8 +144,8 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_examples() {
|
||||
use crate::test_examples;
|
||||
use crate::{test_examples_with_commands, Merge};
|
||||
|
||||
test_examples(Reduce {})
|
||||
test_examples_with_commands(Reduce {}, &[&Merge])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue