Skip to content

Commit 72ad80a

Browse files
committed
Revert some updates and bump version to 4.0.0
1 parent dc1e94d commit 72ad80a

File tree

9 files changed

+37
-583
lines changed

9 files changed

+37
-583
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
## [3.2.0] - 12/08/2022
1+
## 4.0.0 - 12/21/2022
2+
3+
* Major release. [BREAKING]
4+
* Drop the support for every parse/helper method and keep the [Result] simple as it was its initial purpose.
5+
* Rename `onSuccess` and `onError` to `whenSuccess` and `whenError` to match the `when` method.
26

7+
## [3.2.0] - 12/08/2022
38

49
* **Change to `flatMap` in `AsyncResult` allowing synchronous `Result` chaining**:<br>
510
We noticed that we can receive a `FutureOr` instead of a `Future` in the `flatMap` anonymous function, more specifically in the `AsyncResult`.
@@ -26,8 +31,6 @@ Result<int, String> newResult = result.swap();
2631

2732
* fix doc
2833

29-
30-
3134
## [3.1.0] - 12/05/2022
3235
* 100% Test Coverage!!.
3336
* Refactor `AsyncResult`.

README.md

Lines changed: 14 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ Result package for dart inspired by the work of [dartz](https://pub.dev/packages
55
This package is perfect to those of you who just want the Multiple results
66
functionality from dartz. 👌
77

8-
##### Old version:
8+
## About version 4.0.0 and previous releases
99

10-
If you're looking for a non null-safety version, you can find it in [here](https://github.com/higorlapa/result/tree/no-null-safety)
10+
Versions 3.0.0 to 3.2.0 represented the common effort in making this package better. That's why so many breaking changes
11+
in just a small time.
1112

13+
Once these updates stopped (because they decided to fork the project) I decided to remove these updates
14+
and keep it simple as it was always supposed to be. It's open to suggestions and you should not expect
15+
more of these breaking changes any time soon. The package will keep evolving and responding to dart's updates.
1216

1317
## Use **Result** type:
1418

@@ -51,7 +55,7 @@ Result<String, Exception> getSomethingPretty() {
5155
5256
```
5357

54-
#### Handling the Result with `when` or `fold`:
58+
#### Handling the Result with `when`:
5559

5660
```dart
5761
void main() {
@@ -69,25 +73,22 @@ void main() {
6973
7074
}
7175
```
72-
** OBS: As we are going through a transition process, the `when` and `fold` syntax are identical.
73-
Use whichever one you feel most comfortable with and help us figure out which one should remain in the pack.
7476

75-
76-
#### Handling the Result with `onSuccess` or `onError`
77+
#### Handling the Result with `whenSuccess` or `whenError`
7778

7879
```dart
7980
final result = getSomethingPretty();
80-
// notice the [onSuccess] or [onError] will only be executed if
81+
// notice that [whenSuccess] or [whenError] will only be executed if
8182
// the result is a Success or an Error respectivaly.
82-
final output = result.onSuccess((name) {
83+
final output = result.whenSuccess((name) {
8384
// handle here the success
8485
return "";
8586
});
8687
8788
final result = getSomethingPretty();
8889
8990
// [result] is NOT an Error, this [output] will be null.
90-
final output = result.onError((exception) {
91+
final output = result.whenError((exception) {
9192
// handle here the error
9293
return "";
9394
});
@@ -121,133 +122,14 @@ void main() {
121122
}
122123
```
123124

124-
## Transforming a Result
125-
126-
#### Mapping success value with `map`
127-
128-
```dart
129-
void main() {
130-
final result = getResult()
131-
.map((e) => MyObject.fromMap(e));
132-
133-
result.tryGetSuccess(); //Instance of 'MyObject'
134-
}
135-
```
136-
137-
#### Mapping error value with `mapError`
138-
139-
```dart
140-
void main() {
141-
final result = getResult()
142-
.mapError((e) => MyException(e));
143-
144-
result.tryGetError(); //Instance of 'MyException'
145-
146-
}
147-
```
148-
149-
#### Chain others [Result] by any `Success` value with `flatMap`
150-
151-
```dart
152-
153-
Result<String, MyException> checkIsEven(String input){
154-
if(input % 2 == 0){
155-
return Success(input);
156-
} else {
157-
return Error(MyException('isn`t even!'));
158-
}
159-
}
160-
161-
void main() {
162-
final result = getNumberResult()
163-
.flatMap((s) => checkIsEven(s));
164-
}
165-
```
166-
#### Chain others [Result] by `Error` value with `flatMapError`
167-
168-
```dart
169-
170-
void main() {
171-
final result = getNumberResult()
172-
.flatMapError((e) => checkError(e));
173-
}
174-
```
175-
176-
#### Add a pure `Success` value with `pure`
177-
178-
```dart
179-
void main() {
180-
final result = getSomethingPretty().pure(10);
181-
182-
String? mySuccessResult;
183-
if (result.isSuccess()) {
184-
mySuccessResult = result.tryGetSuccess(); // 10
185-
}
186-
}
187-
```
188-
189-
#### Add a pure `Error` value with `pureError`
190-
191-
```dart
192-
void main() {
193-
final result = getSomethingPretty().pureError(10);
194-
if (result.isError()) {
195-
result.tryGetError(); // 10
196-
}
197-
}
198-
```
199-
#### Swap a `Result` with `swap`
200-
201-
```dart
202-
void main() {
203-
Result<String, int> result =...;
204-
Result<int, String> newResult = result.swap();
205-
}
206-
```
207-
208125
## Unit Type
209126

210127
Some results do not need a specific return. Use the Unit type to signal an empty return.
211128

212129
```dart
213130
Result<Unit, Exception>
214131
```
132+
## ResultOf
215133

216-
## Use **AsyncResult** type:
217-
218-
`AsyncResult<S, E>` represents an asynchronous computation.
219-
Use this component when working with asynchronous **Result**.
220-
221-
**AsyncResult** has some of the operators of the **Result** object to perform data transformations (**Success** or **Error**) before executing the Future.
222-
223-
The operators of the **Result** object available in **AsyncResult** are:
224-
225-
- map
226-
- mapError
227-
- flatMap
228-
- flatMapError
229-
- pure
230-
- pureError
231-
- swap
232-
233-
`AsyncResult<S, E>` is a **typedef** of `Future<Result<S, E>>`.
234-
235-
```dart
236-
237-
AsyncResult<String, Exception> fetchProducts() async {
238-
try {
239-
final response = await dio.get('/products');
240-
final products = ProductModel.fromList(response.data);
241-
return Success(products);
242-
} on DioError catch (e) {
243-
return Error(ProductException(e.message));
244-
}
245-
}
246-
247-
...
248-
249-
final state = await fetch()
250-
.map((products) => LoadedState(products))
251-
.mapLeft((error) => ErrorState(error))
252-
253-
```
134+
You may have noticed the `ResultOf` typedef. It represents a better readability for `Result`, but as
135+
it would be another breaking change, leaving it as an alias would be good enough.

example/lib/cpf_validator.dart

Lines changed: 0 additions & 75 deletions
This file was deleted.

lib/multiple_result.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
library multiple_result;
22

3-
export 'src/async_result.dart';
43
export 'src/result.dart';
54
export 'src/unit.dart';

lib/src/async_result.dart

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)