Skip to content

Commit

Permalink
refactor: Rename result async early return
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Jan 29, 2024
1 parent 8bf1736 commit 69b3a4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/src/result/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ sealed class Result<S, F extends Object> {
/// This should be used at the top level of a function as above. Passing "$" to any other functions, nesting, or
/// attempting to bring "$" out of the original scope should be avoided. Also, using the method [catchError] on the futures after
/// the `[$]` operator might lead to unexpected behaviour.
static Future<Result<S, F>> earlyAsync<S, F extends Object>(
static Future<Result<S, F>> async<S, F extends Object>(
// ignore: library_private_types_in_public_api
_AsyncResultEarlyReturnFunction<S, F> fn,
) async {
Expand Down
18 changes: 9 additions & 9 deletions test/result/future_result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ void main() {
//************************************************************************//

group("Early Return", () {
FutureResult<int, String> earlyReturnErr() => Result.earlyAsync(($) {
FutureResult<int, String> earlyReturnErr() => Result.async(($) {
return Future.value(Err("return error"));
});
FutureResult<int, String> earlyReturnOk() => Result.earlyAsync(($) {
FutureResult<int, String> earlyReturnOk() => Result.async(($) {
return Future.value(Ok(2));
});
FutureResult<int, String> regularOk() async {
Expand All @@ -189,7 +189,7 @@ void main() {

test('No Exit', () async {
FutureResult<int, String> add3(int val) {
return Result.earlyAsync(($) async {
return Result.async(($) async {
int x = await regularOk()[$];
int y = Ok(1)[$];
int z = Ok(1).mapErr((err) => err.toString())[$];
Expand All @@ -202,7 +202,7 @@ void main() {

test('No Exit 2', () async {
FutureResult<int, String> add3(int val) {
return Result.earlyAsync(($) async {
return Result.async(($) async {
int x = await earlyReturnOk()[$];
int y = Ok(1)[$];
int z = Ok(1).mapErr((err) => err.toString())[$];
Expand All @@ -215,7 +215,7 @@ void main() {

test('With Exit', () async {
FutureResult<int, String> testDoNotation() =>
Result.earlyAsync(($) async {
Result.async(($) async {
int y = Ok(1)[$];
int z = Ok(1).mapErr((err) => err.toString())[$];
int x = await regularErr()[$];
Expand All @@ -226,7 +226,7 @@ void main() {

test('With Exit 2', () async {
FutureResult<int, String> testDoNotation() =>
Result.earlyAsync(($) async {
Result.async(($) async {
int y = Ok(1)[$];
int z = Ok(1).mapErr((err) => err.toString())[$];
int x = await earlyReturnErr()[$];
Expand All @@ -241,7 +241,7 @@ void main() {

test('Normal Ok', () async {
FutureResult<int, String> testDoNotation() =>
Result.earlyAsync(($) async {
Result.async(($) async {
int y = 3;
int z = 2;
int x = 1;
Expand All @@ -252,7 +252,7 @@ void main() {

test('Normal Err', () async {
FutureResult<int, String> testDoNotation() =>
Result.earlyAsync(($) async {
Result.async(($) async {
int y = 3;
int z = 2;
int x = 1;
Expand All @@ -262,7 +262,7 @@ void main() {
});

test('Wrong type', () async {
FutureResult<int, String> testDoNotation() => Result.earlyAsync(($) {
FutureResult<int, String> testDoNotation() => Result.async(($) {
// wrongType()[$]; // does not compile as expected
wrongType();
return Future.value(Err(""));
Expand Down

0 comments on commit 69b3a4d

Please sign in to comment.