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:
Bahex 2024-12-16 00:26:14 +03:00 committed by GitHub
parent baf86dfb0e
commit 3c632e96f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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])
}
}