diff --git a/crates/nu-command/src/filters/reduce.rs b/crates/nu-command/src/filters/reduce.rs index ed3c61ec32..8aa77719b9 100644 --- a/crates/nu-command/src/filters/reduce.rs +++ b/crates/nu-command/src/filters/reduce.rs @@ -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]) } }