Accessing non-final local variables from a lambda expression

Neal Gafter neal at gafter.com
Fri Feb 26 15:41:20 PST 2010


On Fri, Feb 26, 2010 at 2:59 PM, John Nilsson <john at milsson.nu> wrote:
> Why not something like this instead?
> <T> Iterable<T> everyOther(Iterable<T> input) {
>     return zipWithIndex(input).filter(#(long i, T t)(i%2==0)).map(#(long i,
> T t)(t));
> }

Very clever.

> Point being, wouldn't it be better, from a concurrency point of view, to
> encourage a functional style of programming instead of focusing on
> supporting shared mutable state?

Where it's practical, yes.  But there is a difference between
encouraging a functional style and discouraging an imperative style.
I admire the solution, but it isn't realistic to expect people to come
up with it without significantly more time invested than is required
for the simple solution.  Most programmers have a job to do and a life
outside work.


More information about the lambda-dev mailing list