Class CopyWithRecorder
- All Implemented Interfaces:
GroovyObject
copyWith { } block. It does
not mutate anything: property assignments and prop.modify { } calls
are recorded as a (possibly dotted) path-keyed map which is then handed to
the nested-aware copyWith(Map) for reconstruction.
Reads of a property return a child recorder bound to the extended path, so
address.city = 'NYC' records 'address.city'.
The reserved name old resolves to the original (root) object —
aligning with the old of @Ensures/@Contract in
design-by-contract — so a value may be derived from the pre-state:
address.city = old.address.city.reverse() or, cross-field,
name = old.company.name. The concise single-field shorthand
address.city.modify { it.reverse() } remains for the common
transform-this-same-field case.
On a navigated path the recorder intercepts modify, so a same-named
real method on the value type is shadowed there. old is the escape
hatch: past old the RHS is the real object, so a genuine
modify(Closure) (or any other domain method) runs and its result is
recorded — e.g. balance = old.balance.modify { it + 50 }. old
may equally be preferred purely for style, when .modify on a path
could be misread, even if no real method exists.
- Since:
- 6.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetProperty(String name) Retrieves a property value.invokeMethod(String name, Object args) Invokes the given method.voidsetProperty(String name, Object value) Sets the given property to the new value.Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
-
Constructor Details
-
CopyWithRecorder
-
-
Method Details
-
getProperty
Description copied from interface:GroovyObjectRetrieves a property value.- Parameters:
name- the name of the property of interest- Returns:
- the given property
-
setProperty
Description copied from interface:GroovyObjectSets the given property to the new value.- Parameters:
name- the name of the property of interestvalue- the new value for the property
-
invokeMethod
Description copied from interface:GroovyObjectInvokes the given method.- Parameters:
name- the name of the method to callargs- the arguments to use for the method call- Returns:
- the result of invoking the method
-