Use [scriptblock], imho, it is much simpler than using functions here. It was a scripting task.
function ForAll([scriptblock]$predicate) { BEGIN { $allTrue = $true } PROCESS { if (!(& $predicate $_)) { $allTrue = $false } } END { $allTrue } } $aList = (0..4) $bList = (1..4) $aList | ForAll {$args[0] -le -10 } # returns false $bList | ForAll {$args[0] -le 10 }
$ args [0] denotes the first argument passed to the script block - in this case, it is $ _.
source share