You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
reduce supply accumulator as pipeline input to the closure #13459
The parameter order of reduce can be confusing, as it is a left associative operation yet the parameter order is |item, accumulator| unlike some other languages (e.g. Rust) where it's the other way around.
Describe the solution you'd like
Nushell already has an extra way of passing data into a function, the pipeline input $in. This can be utilized to differentiate between the two parameters.
Some commands that are basically binary operators accept their left operand in this manner
$left| merge $right
Supplying data to a closure as both an argument and as the pipeline input is a common pattern in other commands like each and filter so this has some precedent.
It makes applying commands like merge a little cleaner:
This does not suggest the accumulator should not be available as the second argument. Nushell closures ignore extra arguments which makes both of these possible
... | each {...}
... | each {|it| ...}
Keeping the current order of parameters would make this a (mostly) backwards compatible change as it is unlikely that existing usages depend on the closures pipeline input being empty.
Describe alternatives you've considered
Changing the order of parameters would cause additional confusion and be a breaking change for no technical benefit as it does not allow any new patterns.
Activity
reduce: supply <acc> to the closure as pipeline input as well (nushel…