Advertisement
cwchen

[Perl 6] Higher-order function combo (method call).

Nov 28th, 2017
3,699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.17 KB | None | 0 0
  1. my $n = (1..10)
  2.     .grep({ $_ mod 2 != 0 })
  3.     .map({ $_ ** 2 })
  4.     .reduce: { $^a + $^b };
  5.  
  6. $n == 1 ** 2 + 3 ** 2 + 5 ** 2 + 7 ** 2 + 9 ** 2 or die "Wrong value";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement