Issue Details (XML | Word | Printable)

Key: GROOVY-1439
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Ben Yu
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

Allow conversion from closure to interface

Created: 28/Jul/06 12:21 AM   Updated: 13/Oct/06 08:22 AM   Resolved: 13/Oct/06 08:22 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0-RC-1

Time Tracking:
Not Specified

File Attachments: 1. Java Source File FromClosure.java (2 kB)



 Description  « Hide

It is relatively easy to adapt a closure to a one-method interface. And such conversion should be very useful for implementing functors from within groovy.

syntax can be:

{a->a.name=="a"} as Predicate

The attached class is a dynamic proxy that implements this adapter functionality. It is currently used in a category class to enable a syntax like "Predicate.impl {...}".

Just hook it up to the "as" keyword should make it work.



Jochen Theodorou made changes - 22/Sep/06 09:16 AM
Field Original Value New Value
Fix Version/s 1.0-RC-1 [ 12104 ]
Patch attached Yes
Jochen Theodorou added a comment - 13/Oct/06 08:22 AM

I applied a modified version of the patch and added a test


Jochen Theodorou made changes - 13/Oct/06 08:22 AM
Assignee Guillaume Laforge [ guillaume ] Jochen Theodorou [ blackdrag ]
Resolution Fixed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]