added example.
This commit is contained in:
parent
22379c9846
commit
70283100fc
|
@ -36,7 +36,7 @@ impl Command for Reduce {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Aggregate a list to a single value using an accumulator closure."
|
"Aggregate a list (starting from the left) to a single value using an accumulator closure."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_terms(&self) -> Vec<&str> {
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
|
@ -50,6 +50,11 @@ impl Command for Reduce {
|
||||||
description: "Sum values of a list (same as 'math sum')",
|
description: "Sum values of a list (same as 'math sum')",
|
||||||
result: Some(Value::test_int(10)),
|
result: Some(Value::test_int(10)),
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
example: "[ 1 2 3 4 ] | reduce {|it, acc| $acc - $it }",
|
||||||
|
description: r#"`reduce` accumulates value from left to right, equivalent to (((1 - 2) - 3) - 4)."#,
|
||||||
|
result: Some(Value::test_int(-8)),
|
||||||
|
},
|
||||||
Example {
|
Example {
|
||||||
example:
|
example:
|
||||||
"[ 8 7 6 ] | enumerate | reduce --fold 0 {|it, acc| $acc + $it.item + $it.index }",
|
"[ 8 7 6 ] | enumerate | reduce --fold 0 {|it, acc| $acc + $it.item + $it.index }",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user