Skip to content
This repository was archived by the owner on Sep 3, 2023. It is now read-only.

Conversation

@SlavaKozlov
Copy link

@SlavaKozlov SlavaKozlov commented Oct 6, 2020

Per suggestion on Medium, I added an initial (or seed) value parameter to the Reduce-Object function (parameter name is -InitValue).

This is useful in multiple piping steps to avoid having to find a way to insert the inti value midstream.

Instead of this:
$values = Step1 | Step2 | Step3
$result = @($init) + $values | Reduce-Object $accumulator

We can do this:
$result = Step1 | Step2 | Step3 | Reduce-Object $accumulator -InitValue $init

Added unit test as well.
Thx

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant