Funky Function Filters in Perl6
A while back I wrote about Funky Function Filters. Let me refresh your memory - we have a Python and a Ruby snippet and we translate it into Perl5. The code is a toy to show some fancy shmancy lambda (unnamed functions) usage. The idea is to take a list of functions, filter them, and then with the remaining ones show what happens with parameters from -10 to 10.
Python example:
for f in filter(lambda f: f(-1)>=f(1),
[lambda x:x, lambda x:x**2, lambda x:x**3]):
for x in range(-10, 11):
print x, f(x)
Ruby translation:
for f in [lambda { |x| x }, lambda { |x| x**2 }, lambda { |x| x**3 }
].select { |f| f.call(-1) >= f.call(1) }
for x in -10..10
print x, f.call(x)
end
end
My perl5 translation:
