Skip to content

reduce: supply <acc> to the closure as pipeline input as well - #13461

Merged
fdncred merged 1 commit into
nushell:mainfrom
Bahex:reduce-pipeline-input
Jul 30, 2024
Merged

fdncred merged 1 commit into
nushell:mainfrom
Bahex:reduce-pipeline-input

Conversation

@Bahex

@Bahex Bahex commented Jul 26, 2024

Copy link
Copy Markdown
Member

resolve #13459

Description

Make reduce supply the accumulator value to closure as pipeline input.

User-Facing Changes

Mostly described in #13459

  • Should not be a breaking change.
  • Allows cleaner patterns like ... | reduce {|it| merge $it}

Tests + Formatting

cargo test --package nu-cli --test main -- commands::reduce and toolkit test stdlib report no issues

@devyn devyn left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, should have just included my comments this way - please maintain compatibility by adding the acc arg. Thanks!

@devyn devyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I was wrong, I forgot that run_with_value() adds the arg as well. I think this is fine. Sorry about that.

@devyn devyn added status:wait-until-after-nushell-release deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way labels Jul 27, 2024
@fdncred
fdncred merged commit 0576794 into nushell:main Jul 30, 2024
@fdncred

fdncred commented Jul 30, 2024

Copy link
Copy Markdown
Contributor

Thanks

@hustcer hustcer added this to the v0.97.0 milestone Jul 30, 2024
@NotTheDr01ds

NotTheDr01ds commented Aug 1, 2024 •

Copy link
Copy Markdown
Contributor

I think this is a great change, but it could really use examples and tests. This seems like something that could easily get unintentionally broken in the future without tests in place.

@Bahex
Bahex deleted the reduce-pipeline-input branch March 22, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecated:pr-commands (deprecated: too vague) This PR changes our commands in some way status:wait-until-after-nushell-release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reduce supply accumulator as pipeline input to the closure

5 participants