Created
December 17, 2017 03:21
-
-
Save bgshacklett/17f0daa3b357a8a4390f6e4c4fa7ebe8 to your computer and use it in GitHub Desktop.
An Implementation of the Reduce Function for PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Reduce-Object | |
{ | |
[CmdletBinding()] | |
Param | |
( | |
[Parameter(Mandatory = $true)] | |
$InitialValue, | |
[Parameter(ValueFromPipeline = $true)] | |
$InputObject, | |
[Parameter()] | |
$ScriptBlock | |
) | |
Begin { $result = $InitialValue } | |
Process | |
{ | |
$commandContext = | |
@{ | |
'ScriptBlock' = $ScriptBlock | |
'ArgumentList' = $InputObject,$result | |
} | |
$result = Invoke-Command @commandContext | |
} | |
End { $result } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment