Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. Import-Module functional
  2.  
  3. function map($f) {
  4. $reducer = {Param($a, $b) @($a) + @(&$f $b)}
  5. @(@()) + $input | Compress-Object $reducer
  6. }
  7.  
  8. function filter($f) {
  9. $reducer = {Param($a, $b) if (&$f $b) {@($a) + @($b)} else {$a}}
  10. @(@()) + $input | Compress-Object $reducer
  11. }
  12.  
  13. $odd = {Param($a) $a % 2}
  14. $square = {Param($a) $a * $a}
  15. 1..10 | map $square | filter $odd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement