Trivial SAM convertion
Remi Forax
forax at univ-mlv.fr
Tue Apr 2 06:26:59 PDT 2013
On 04/02/2013 03:22 PM, Brian Goetz wrote:
>> During my attempts to *lambdafying* my code, I came to places like this:
>>
>>
>> *Predicate<File> isDir = File::isDirectory;*
>> **
>> *
>> *
>> *Predicate<File> isFile = isDir.negate();*
>> **
>> *
>> FileFilter isFileFilter = isFile::test;
>>
>> *
>> *At first, naively I just wrote:
>> *
>> *FileFilter isFileFilter = isFile;
>>
>> *
>> *After realizing my mistake, I wondered 'Why not *?' If we have two SAM
>> interfaces with identical signatures (test & accept) then one can be
>> converted to other.
> Yes, the EG discussed the issue of "SAM to SAM conversion" at length.
> The deciding factor was that an existing language feature already gives
> you most of what you want:
>
> FilterFilter isFileFilter = isFile::test;
>
> Going farther did not seem worthwhile. The alternatives were:
> - a special syntax for the conversion
> - a silent magic conversion
>
> Given that the above is not syntactically awful, and nicely explicit,
> prudence dictated that we stop there.
yes, and the VM (or the lambda metafactory in fact) can optimize
the case where isFile is a constant lambda (which is the case in your
example)
to create a constant lambda too.
This is not currently done but should be done when the dust will settle.
Rémi
More information about the lambda-dev
mailing list