< Back
Convert-Reduce
Post
NAME Convert-Reduce
SYNOPSIS
Perform functional-style folding or reducing operations on a sequence or stream of objects in a Powershell pipeline
SYNTAX
Convert-Reduce [-Expression] <ScriptBlock> [-Accumulator] <Object> [-InputObject] <Object[]> [<CommonParameters>]
DESCRIPTION
Apply the given ScriptBlock expression to an accumulating value using each member of the pipelined InputObject.
PARAMETERS
-Expression <ScriptBlock>
The anonymous (in-place) or named (as variable) single-argument lambda function to be applied to each
InputObject element. This must have a double-argument parameter block.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Accumulator <Object>
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-InputObject <Object[]>
The sequence or stream of Objects from the Powershell pipeline.
Required? true
Position? 3
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\># Reduce a list to the sum of its elements.
@(1,2,3) | Convert-Reduce { param($acc,$it) $acc + $it } -Accumulator 0
6
-------------------------- EXAMPLE 2 --------------------------
PS C:\\># Apply a set of XSLT Transforms to an initial XML document, yielding the transformed XML after each
transformation has been applied to the prior transformation
@( $stylesheet1, $stylesheet2, $stylesheet3 ) | Convert-Reduce { param($acc,$it) Transform-Xslt -Output $acc
-Stylesheet $it -Input $acc } -Accumulator $originalXml
RELATED LINKS
SYNOPSIS
Perform functional-style folding or reducing operations on a sequence or stream of objects in a Powershell pipeline
SYNTAX
Convert-Reduce [-Expression] <ScriptBlock> [-Accumulator] <Object> [-InputObject] <Object[]> [<CommonParameters>]
DESCRIPTION
Apply the given ScriptBlock expression to an accumulating value using each member of the pipelined InputObject.
PARAMETERS
-Expression <ScriptBlock>
The anonymous (in-place) or named (as variable) single-argument lambda function to be applied to each
InputObject element. This must have a double-argument parameter block.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Accumulator <Object>
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-InputObject <Object[]>
The sequence or stream of Objects from the Powershell pipeline.
Required? true
Position? 3
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\># Reduce a list to the sum of its elements.
@(1,2,3) | Convert-Reduce { param($acc,$it) $acc + $it } -Accumulator 0
6
-------------------------- EXAMPLE 2 --------------------------
PS C:\\># Apply a set of XSLT Transforms to an initial XML document, yielding the transformed XML after each
transformation has been applied to the prior transformation
@( $stylesheet1, $stylesheet2, $stylesheet3 ) | Convert-Reduce { param($acc,$it) Transform-Xslt -Output $acc
-Stylesheet $it -Input $acc } -Accumulator $originalXml
RELATED LINKS