dart-lang / dart-lang/language

Create cascade operator for immutable classes that return mutated copies

Open
#430 6 comments 1 reaction 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

Currently, when working with immutable classes, such as are used in Redux, etc,
a lot of boilerplate code is written for each class to allow for mutated copies. This is usually written in the form of:
```dart
class MyClass {
final String myName;
final int myAge;

MyClass copyWith({String myName, int myAge}){
return MyClass(myName: myName ?? this.myName,
myAge: myAge ?? this.myAge);
}
}
```
Actually, this is used often in Flutter. If we could use the same type of idea as
`var myNewClass = myClass..name = "newName"; ` where `myClass` retained all the old information would render these entire functions useless and same loads of time.

I know to reuse the cascade operator could be confusing, and single and triple dot notation are already taken...

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Start by reviewing the proposed immutable-class cascade behavior and the existing cascade and spread-notation constraints; done would require an agreed Dart language design specifying the syntax and semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.