Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on In defense of PowerShell.
Here's map/filter/reduce. Golf welcome.
@(1, 2, 3) ` | % { $_ + 1 } ` | ? { $_ -gt 2 } ` | Measure-Object -Sum | Select Sum
$reduce = { param ([scriptblock]$reducer) begin { $initialised = $false } process { if (-not $initialised) { $agg = $_ $initialised = $true } else { $agg = &$reducer $agg $_ } } end { $agg } }
@(1, 2, 3) | &$reduce { param($agg, $i) $agg + $i }
There are no comments on this comment yet.
Here's map/filter/reduce. Golf welcome.
You can write a generic reduce like this: And then use it like this: