Skip to content

Instantly share code, notes, and snippets.

@featzima
Last active June 7, 2019 09:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save featzima/0e2e2ceb07e2e9818ec43580f5c8a74d to your computer and use it in GitHub Desktop.
Save featzima/0e2e2ceb07e2e9818ec43580f5c8a74d to your computer and use it in GitHub Desktop.
class Setter<T> {
final T value;
Setter(this.value);
}
Setter<T> set<T>(T value) {
return Setter<T>(value);
}
class Person {
final String firstName;
final String secondName;
final int age;
Person(this.firstName, this.secondName, this.age);
Person copy({Setter<String> firstName, Setter<String> secondName, Setter<int> age}) {
return Person(
firstName?.value ?? this.firstName,
secondName?.value ?? this.secondName,
age?.value ?? this.age);
}
@override
String toString() => "Person{ firstName=$firstName, secondName=$secondName, age=$age }";
}
void main() {
final person = Person("Dmytro", "Glynskyi", 30);
final updatedPerson = person.copy(age: set(32));
print(updatedPerson);
}
@featzima
Copy link
Author

featzima commented Jun 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment