Skip to content

Commit

Permalink
feat: Added FutureOr in AsyncResult.Map
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Jan 26, 2023
1 parent 9a1e793 commit b3581d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
## [1.0.3] - 2021-12-22
## [1.0.4] - 2023-01-26

* feat: Added FutureOr in AsyncResult.Map

## [1.0.3] - 2022-12-22

* fix: AsyncResult recover

## [1.0.2] - 2021-12-18
## [1.0.2] - 2022-12-18

* fix: separed functions.dart import

## [1.0.1] - 2021-12-17
## [1.0.1] - 2022-12-17

* fix: recover operator return a `Result` instead a `Failure`.

## [1.0.0+2] - 2021-12-16
## [1.0.0+2] - 2022-12-16

* Initial release

13 changes: 11 additions & 2 deletions lib/src/async_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ extension AsyncResultExtension<S extends Object, F extends Object> //

/// Returns a new `AsyncResult`, mapping any `Success` value
/// using the given transformation.
AsyncResult<W, F> map<W extends Object>(W Function(S success) fn) {
return then((result) => result.map(fn));
AsyncResult<W, F> map<W extends Object>(FutureOr<W> Function(S success) fn) {
return then(
(result) => result.map(fn).fold(
(success) async {
return Success(await success);
},
(failure) {
return Failure(failure);
},
),
);
}

/// Returns a new `Result`, mapping any `Error` value
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: result_dart
description: Result for dart. It is an implementation based on Kotlin Result and Swift Result.
version: 1.0.3
version: 1.0.4
repository: https://github.com/Flutterando/result_dart

environment:
Expand Down
1 change: 1 addition & 0 deletions test/src/async_result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void main() {
.map((success) => success * 2);

expect(result.getOrNull(), 2);
expect(const Failure(2).toAsyncResult().map(identity), completes);
});

test('mapError', () async {
Expand Down

0 comments on commit b3581d0

Please sign in to comment.