Created
April 12, 2023 12:27
-
-
Save shiguruikai/ee08f19acbe6a0f683291f32342670f5 to your computer and use it in GitHub Desktop.
PowerShellでwindowed関数的なやつ。
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
[OutputType("System.Array")] | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline)] | |
[psobject]$InputObject, | |
[Parameter(Mandatory, Position = 0)] | |
[int]$Size, | |
[Parameter()] | |
[int]$Step = 1 | |
) | |
begin { | |
if ($Size -le 0 -or $Step -le 0) { | |
throw "Both size and step must be greater than 0." | |
} | |
$buffer = [System.Collections.Generic.List[psobject]]::new() | |
} | |
process { | |
$InputObject | ForEach-Object { | |
[void]$buffer.Add($_) | |
} | |
} | |
end { | |
return 0..(($buffer.Count - $Size) / $Step) ` | |
| ForEach-Object { $_ * $Step } ` | |
| ForEach-Object { , $buffer[$_..($_ + $Size - 1)] } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment