groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <>
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

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.


-----Original Message-----
From: Jochen Theodorou [] 
Sent: Thursday, April 13, 2017 11:39 AM
Subject: Re: How to determine the equality of two closures?

Jason, have you ever trief something like this?

> = { 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.
View raw message