groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <Jason.Winneb...@windstream.com>
Subject RE: How to determine the equality of two closures?
Date Thu, 13 Apr 2017 16:03:57 GMT
That's cool, so that defines lastValue as a field of the actual closure class?

The issue with using a field is the watch not using the map would fail when performing multiple
watches:

person.watch({skills}....
person.watch({name}...

In those two values, the lastValue field would confuse the state between the {skills} watch
and the {name} watch. Also I didn't want to complicate the example but in the real implementation
the watch is a utility class shared between many objects and classes and not a closure so
my watch state map key is the watched instance + watch closure class and the map is the field
of a real class. In real a scripting DSL example I would have probably added watch to Object
metaclass which delegates to a WatchManager implementation.

Jason

-----Original Message-----
From: Jochen Theodorou [mailto:blackdrag@gmx.org] 
Sent: Thursday, April 13, 2017 11:39 AM
To: users@groovy.apache.org
Subject: Re: How to determine the equality of two closures?

Jason, have you ever trief something like this?

>  person.watch = { cond, action, elseAction ->
>    def value = person.with(cond).clone()
>    @groovy.transform.Field lastValue
>    if (value != lastValue) action(lastValue, value) else elseAction()
>    lastValue = value
>  }

bye Jochen

This email message and any attachments are for the sole use of the intended recipient(s).
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all copies of the
original message and any attachments.
Mime
View raw message