Skip to content

Commit

Permalink
feat: Added FutureOr in AsyncResult.MapError
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Jan 26, 2023
1 parent b3581d0 commit 5e16d57
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 118 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.0.5] - 2023-01-26

* feat: Added FutureOr in AsyncResult.MapError
## [1.0.4] - 2023-01-26

* feat: Added FutureOr in AsyncResult.Map
Expand Down
7 changes: 4 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ packages:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
result_dart:
Expand All @@ -14,6 +15,6 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.1"
version: "1.0.5"
sdks:
dart: ">=2.15.1 <3.0.0"
dart: ">=2.15.1 <4.0.0"
19 changes: 16 additions & 3 deletions lib/src/async_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ 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>(FutureOr<W> Function(S success) fn) {
AsyncResult<W, F> map<W extends Object>(
FutureOr<W> Function(S success) fn,
) {
return then(
(result) => result.map(fn).fold(
(success) async {
Expand All @@ -41,8 +43,19 @@ extension AsyncResultExtension<S extends Object, F extends Object> //

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

/// Change a [Success] value.
Expand Down
Loading

0 comments on commit 5e16d57

Please sign in to comment.