nushell
nushell copied to clipboard
Make `--numbered` iterators use a flat list of parameters
Related problem
No response
Describe the solution you'd like
Instead of each -n {|it| [ $it.index $it.item ]}, the block signature should look like each {|index, item| [ $index $item ]}. It removes one layer of indirection and would throw an error if you use incorrect number of parameters.
This applies to all iterator commands that accept the --numbered option, such as reduce.
Describe alternatives you've considered
No response
Additional context and details
No response
This might need a bit of design. Currently there's only one signature per command. In this case, we kinda want to have "overloads" of the signature, so that based on the flags you pass, you can get different shapes for the block
The obvious solution to this is to NOT change --numbered, but deprecate it and allow the normal each to take 1 or 2-param blocks with no error:
OLD:
each -n {|elem| mv $elem.item ($elem.index + 1 | into string | $in+ '.jpg')}
NEW:
each {|name num| mv $name ($num + 1 | into string | $in + '.jpg')}
reduce can be expanded to take a 2 or 3-param block with no error.
By the way, did you know that reduce can currently take 1-param blocks with no error? [1 2 3] | reduce {|e| $e + 1 } is valid.