From 229e536e219dfd3f538d9910c6373d7bbd0c67a8 Mon Sep 17 00:00:00 2001 From: SandroMaglione Date: Mon, 25 Mar 2024 06:15:25 +0900 Subject: [PATCH] rename `Fail` to `Failure` --- packages/fpdart/lib/src/effect.dart | 35 +++++++++++++++-------------- packages/fpdart/lib/src/either.dart | 2 +- packages/fpdart/lib/src/exit.dart | 8 +++---- packages/fpdart/lib/src/option.dart | 4 ++-- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/fpdart/lib/src/effect.dart b/packages/fpdart/lib/src/effect.dart index c311760..88d6813 100644 --- a/packages/fpdart/lib/src/effect.dart +++ b/packages/fpdart/lib/src/effect.dart @@ -176,7 +176,7 @@ final class Effect extends IEffect { try { return execute().then(Right.new); } catch (err, stack) { - return Left(Fail(onError(err, stack), stack)); + return Left(Failure(onError(err, stack), stack)); } }, ); @@ -184,7 +184,7 @@ final class Effect extends IEffect { /// {@category constructors} factory Effect.fromNullable(R? value, {required L Function() onNull}) => Effect._( - (_) => value == null ? Left(Fail(onNull())) : Right(value), + (_) => value == null ? Left(Failure(onNull())) : Right(value), ); /// {@category constructors} @@ -198,7 +198,7 @@ final class Effect extends IEffect { ); /// {@category constructors} - factory Effect.fail(L value) => Effect._((_) => Left(Fail(value))); + factory Effect.fail(L value) => Effect._((_) => Left(Failure(value))); /// {@category constructors} factory Effect.succeed(R value) => Effect._((_) => Right(value)); @@ -303,7 +303,7 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => Right(Left(error)), + Failure(error: final error) => Right(Left(error)), Die() => Left(cause), }, Right(value: final value) => Right(Right(value)), @@ -316,7 +316,7 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail() => Right(None()), + Failure() => Right(None()), Die() => Left(cause), }, Right(value: final value) => Right(Some(value)), @@ -340,7 +340,7 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => Right(onFailure(error)), + Failure(error: final error) => Right(onFailure(error)), Die() => Left(cause), }, Right(value: final value) => Right(onSuccess(value)), @@ -371,7 +371,8 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => onFailure(error)._unsafeRun(env), + Failure(error: final error) => + onFailure(error)._unsafeRun(env), Die() => Left(cause), }, Right(value: final value) => onSuccess(value)._unsafeRun(env), @@ -398,10 +399,10 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => Right(error), + Failure(error: final error) => Right(error), Die() => Left(cause), }, - Right(value: final value) => Left(Fail(value)), + Right(value: final value) => Left(Failure(value)), }, ), ); @@ -414,7 +415,7 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => Left(Fail(f(error))), + Failure(error: final error) => Left(Failure(f(error))), Die() => Left(cause), }, Right(value: final value) => Right(value), @@ -426,7 +427,7 @@ final class Effect extends IEffect { Effect mapErrorCause(C Function(Cause l) f) => Effect._( (env) => _unsafeRun(env).then( (exit) => switch (exit) { - Left(value: final cause) => Left(Fail(f(cause))), + Left(value: final cause) => Left(Failure(f(cause))), Right(value: final value) => Right(value), }, ), @@ -438,7 +439,7 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => Left(Fail(fl(error))), + Failure(error: final error) => Left(Failure(fl(error))), Die() => Left(cause), }, Right(value: final value) => Right(fr(value)), @@ -465,8 +466,8 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => f(error)._unsafeRun(env).then( - (_) => Left(Fail(error)), + Failure(error: final error) => f(error)._unsafeRun(env).then( + (_) => Left(Failure(error)), ), Die() => Left(cause), }, @@ -483,7 +484,7 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => orElse(error)._unsafeRun(env), + Failure(error: final error) => orElse(error)._unsafeRun(env), Die() => Left(cause), }, Right(value: final value) => @@ -509,7 +510,7 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => + Failure(error: final error) => Left(Die.current(onError(error))), Die() => Left(cause), }, @@ -527,7 +528,7 @@ final class Effect extends IEffect { (env) => _unsafeRun(env).then( (exit) => switch (exit) { Left(value: final cause) => switch (cause) { - Fail(error: final error) => f(error)._unsafeRun(env), + Failure(error: final error) => f(error)._unsafeRun(env), Die() => Left(cause), }, Right(value: final value) => diff --git a/packages/fpdart/lib/src/either.dart b/packages/fpdart/lib/src/either.dart index f1de423..c59098e 100644 --- a/packages/fpdart/lib/src/either.dart +++ b/packages/fpdart/lib/src/either.dart @@ -155,7 +155,7 @@ final class Left extends Either { const Left(this.value); @override - Effect get asEffect => Effect._((_) => Left(Fail(value))); + Effect get asEffect => Effect._((_) => Left(Failure(value))); @override Either andThen(C Function(R value) f) => Left(value); diff --git a/packages/fpdart/lib/src/exit.dart b/packages/fpdart/lib/src/exit.dart index de225cf..b646142 100644 --- a/packages/fpdart/lib/src/exit.dart +++ b/packages/fpdart/lib/src/exit.dart @@ -20,7 +20,7 @@ final class Die extends Cause { Die(error, StackTrace.current, stackTrace); @override - bool operator ==(Object other) => (other is Fail) && other.error == error; + bool operator ==(Object other) => (other is Failure) && other.error == error; @override int get hashCode => error.hashCode; @@ -32,16 +32,16 @@ final class Die extends Cause { } /// Failed with an expected error -final class Fail extends Cause { +final class Failure extends Cause { final L error; @override final StackTrace? stackTrace; - const Fail(this.error, [this.stackTrace]); + const Failure(this.error, [this.stackTrace]); @override - bool operator ==(Object other) => (other is Fail) && other.error == error; + bool operator ==(Object other) => (other is Failure) && other.error == error; @override int get hashCode => error.hashCode; diff --git a/packages/fpdart/lib/src/option.dart b/packages/fpdart/lib/src/option.dart index 7d22876..5540c2f 100644 --- a/packages/fpdart/lib/src/option.dart +++ b/packages/fpdart/lib/src/option.dart @@ -69,7 +69,7 @@ sealed class Option extends IEffect { Effect provide(L Function() onNone) => Effect._( (env) => switch (this) { - None() => Left(Fail(onNone())), + None() => Left(Failure(onNone())), Some(value: final value) => Right(value), }, ); @@ -134,7 +134,7 @@ final class None extends Option { @override Effect get asEffect => // ignore: cast_from_null_always_fails - Effect._((_) => Left(Fail(null as Never))); + Effect._((_) => Left(Failure(null as Never))); @override Option flatMap(Option Function(Never r) f) => this;