Last active
June 7, 2019 09:19
-
-
Save featzima/0e2e2ceb07e2e9818ec43580f5c8a74d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run in DartPad