mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 23:39:48 +02:00
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:
@@ -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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user