Skip to content

Commit

Permalink
doc: Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Dec 7, 2024
1 parent 5f8a424 commit a3f49c7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions book/src/libs/option/option.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ print('Profile: $profile, Preferences: $preferences');
Currently in Dart, one cannot rebind variables and `Option` does not support type promotion like nullable types.
This makes using `Option` less ergonomic in some scenarios.
```dart
Option<int> xOpt = ...;
Option<int> xOpt = optionFunc();
int x;
switch(xOpt) {
Some(:final v):
Expand All @@ -131,7 +131,15 @@ switch(xOpt) {
```
vs
```dart
int? x = ...;
int? x = nullableFunc();
if(x == null){
return;
}
// use `int` x
```
Fortunately, since `Option` is an extension type of `T?`. This can be overcome with no runtime cost.
```dart
int? x = optionFunc().value;
if(x == null){
return;
}
Expand Down

0 comments on commit a3f49c7

Please sign in to comment.