From f6bd3d93aab79759a86e6be927a0a67d1d63f807 Mon Sep 17 00:00:00 2001 From: Jacob Moura Date: Sun, 18 Dec 2022 16:49:40 -0300 Subject: [PATCH] fix: separed functions.dart import --- CHANGELOG.md | 10 ++++++++-- README.md | 9 +++++++++ example/pubspec.lock | 2 +- lib/{src/function.dart => functions.dart} | 14 ++++++++++++++ lib/result_dart.dart | 1 - test/src/async_result_test.dart | 1 + test/src/result_test.dart | 5 +++-- 7 files changed, 36 insertions(+), 6 deletions(-) rename lib/{src/function.dart => functions.dart} (75%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99b4519..3248432 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ +## [1.0.2] - 2021-12-18 + +* fix: separed functions.dart import + +## [1.0.1] - 2021-12-17 + +* fix: recover operator return a `Result` instead a `Failure`. + ## [1.0.0+2] - 2021-12-16 * Initial release -## [1.0.1] - 2021-12-17 -* fix: recover operator return a `Result` instead a `Result`. diff --git a/README.md b/README.md index 5d9fee3..3474e83 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,9 @@ return Success('Something Pretty'); // Using Result factory return Result.success('Something Pretty'); +// import 'package:result_dart/functions.dart' +return successOf('Something Pretty'); + // Using extensions return 'Something Pretty'.toSuccess(); ``` @@ -156,6 +159,9 @@ return Failure(Exception('something ugly happened...')); // Using Result factory return Result.failure('something ugly happened...'); +// import 'package:result_dart/functions.dart' +return failureOf('Something Pretty'); + // Using extensions return 'something ugly happened...'.toFailure(); ``` @@ -411,6 +417,9 @@ Some results do not need a specific return. Use the Unit type to signal an **emp ### Help with functions that return their parameter: +NOTE: use import 'package:result_dart/functions.dart' + + Sometimes it is necessary to return the parameter of the function as in this example: ```dart diff --git a/example/pubspec.lock b/example/pubspec.lock index bb616c0..01ef7de 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -14,6 +14,6 @@ packages: path: ".." relative: true source: path - version: "1.0.0+1" + version: "1.0.1" sdks: dart: ">=2.15.1 <3.0.0" diff --git a/lib/src/function.dart b/lib/functions.dart similarity index 75% rename from lib/src/function.dart rename to lib/functions.dart index 9c3964f..2739177 100644 --- a/lib/src/function.dart +++ b/lib/functions.dart @@ -1,3 +1,7 @@ +library result_dart; + +import 'package:result_dart/result_dart.dart'; + /// Returns the given `a`. /// /// Same as `id`. @@ -33,3 +37,13 @@ T identity(T a) => a; /// final withId = result.when((success) => '$success', id); /// ``` T id(T a) => a; + +/// Build a [Result] that returns a [Failure]. +Result successOf(S success) { + return Result.success(success); +} + +/// Build a [Result] that returns a [Failure]. +Result failureOf(F failure) { + return Result.failure(failure); +} diff --git a/lib/result_dart.dart b/lib/result_dart.dart index 962f010..d5cd72f 100644 --- a/lib/result_dart.dart +++ b/lib/result_dart.dart @@ -1,7 +1,6 @@ library result_dart; export 'src/async_result.dart'; -export 'src/function.dart'; export 'src/result.dart'; export 'src/result_extension.dart'; export 'src/unit.dart'; diff --git a/test/src/async_result_test.dart b/test/src/async_result_test.dart index 4da0a1d..ed5da76 100644 --- a/test/src/async_result_test.dart +++ b/test/src/async_result_test.dart @@ -1,3 +1,4 @@ +import 'package:result_dart/functions.dart'; import 'package:result_dart/result_dart.dart'; import 'package:test/test.dart'; diff --git a/test/src/result_test.dart b/test/src/result_test.dart index 3110f07..a5a9ec4 100644 --- a/test/src/result_test.dart +++ b/test/src/result_test.dart @@ -1,4 +1,5 @@ import 'package:meta/meta.dart'; +import 'package:result_dart/functions.dart'; import 'package:result_dart/result_dart.dart'; import 'package:test/test.dart'; @@ -104,14 +105,14 @@ Given a success result, group('Map', () { test('Success', () { - const result = Success(4); + final result = successOf(4); final result2 = result.map((success) => '=' * success); expect(result2.getOrNull(), '===='); }); test('Error', () { - const result = Failure(4); + final result = failureOf(4); final result2 = result.map((success) => 'change'); expect(result2.getOrNull(), isNull);