nushell icon indicating copy to clipboard operation
nushell copied to clipboard

Make `--numbered` iterators use a flat list of parameters

Open kubouch opened this issue 3 years ago • 2 comments

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

kubouch avatar Feb 22 '22 15:02 kubouch

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

sophiajt avatar Feb 25 '22 12:02 sophiajt

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.

webbedspace avatar Oct 30 '22 12:10 webbedspace