canReturnSame property
bool
canReturnSame
Whether the mapper can return the same instance it was given.
This can be used to optimize a mapper.
Example
class Example {
static const kind = ImmutableKind<Example>(
name: 'Example',
blank: Example(),
walk: _walk,
);
static Example _walk(Mapper f, Example t) {
// Map all fields:
final someField = f(t.someField, 'someField');
// Optimization: Check whether we can return the same instance.
if (f.canReturnSame) {
return t;
}
return Example(someField: someField);
}
final String someField;
const Example({this.someField});
}
Implementation
bool get canReturnSame => false;