Allow iteration blocks to have an optional extra index parameter (alternative to -n flags) (#6994)

Alters `all`, `any`, `each while`, `each`, `insert`, `par-each`, `reduce`, `update`, `upsert` and `where`,
so that their blocks take an optional parameter containing the index.
This commit is contained in:
Leon
2022-11-21 23:35:11 +10:00
committed by GitHub
parent 899383c30c
commit 833825ae9a
19 changed files with 486 additions and 74 deletions

View File

@@ -119,3 +119,13 @@ fn error_reduce_empty() {
assert!(actual.err.contains("needs input"));
}
#[test]
fn uses_optional_index_argument() {
let actual = nu!(
cwd: ".", pipeline(
r#"[18 19 20] | reduce -f 0 {|elem accum index| $accum + $index } | to nuon"#
));
assert_eq!(actual.out, "3");
}