Skip to content

Commit

Permalink
fix: separed functions.dart import
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Dec 18, 2022
1 parent b7388c2 commit f6bd3d9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```
Expand All @@ -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();
```
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 14 additions & 0 deletions lib/src/function.dart → lib/functions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
library result_dart;

import 'package:result_dart/result_dart.dart';

/// Returns the given `a`.
///
/// Same as `id`.
Expand Down Expand Up @@ -33,3 +37,13 @@ T identity<T>(T a) => a;
/// final withId = result.when((success) => '$success', id);
/// ```
T id<T>(T a) => a;

/// Build a [Result] that returns a [Failure].
Result<S, F> successOf<S extends Object, F extends Object>(S success) {
return Result<S, F>.success(success);
}

/// Build a [Result] that returns a [Failure].
Result<S, F> failureOf<S extends Object, F extends Object>(F failure) {
return Result<S, F>.failure(failure);
}
1 change: 0 additions & 1 deletion lib/result_dart.dart
Original file line number Diff line number Diff line change
@@ -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';
1 change: 1 addition & 0 deletions test/src/async_result_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:result_dart/functions.dart';
import 'package:result_dart/result_dart.dart';
import 'package:test/test.dart';

Expand Down
5 changes: 3 additions & 2 deletions test/src/result_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<String, int>(4);
final result = failureOf<String, int>(4);
final result2 = result.map((success) => 'change');

expect(result2.getOrNull(), isNull);
Expand Down

0 comments on commit f6bd3d9

Please sign in to comment.