Skip to content

Commit

Permalink
rename Fail to Failure
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroMaglione committed Mar 24, 2024
1 parent b73849d commit 229e536
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
35 changes: 18 additions & 17 deletions packages/fpdart/lib/src/effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
try {
return execute().then(Right.new);
} catch (err, stack) {
return Left(Fail(onError(err, stack), stack));
return Left(Failure(onError(err, stack), stack));
}
},
);

/// {@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}
Expand All @@ -198,7 +198,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
);

/// {@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));
Expand Down Expand Up @@ -303,7 +303,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => Right(Left(error)),
Failure<L>(error: final error) => Right(Left(error)),
Die() => Left(cause),
},
Right(value: final value) => Right(Right(value)),
Expand All @@ -316,7 +316,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>() => Right(None()),
Failure<L>() => Right(None()),
Die() => Left(cause),
},
Right(value: final value) => Right(Some(value)),
Expand All @@ -340,7 +340,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => Right(onFailure(error)),
Failure<L>(error: final error) => Right(onFailure(error)),
Die() => Left(cause),
},
Right(value: final value) => Right(onSuccess(value)),
Expand Down Expand Up @@ -371,7 +371,8 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => onFailure(error)._unsafeRun(env),
Failure<L>(error: final error) =>
onFailure(error)._unsafeRun(env),
Die() => Left(cause),
},
Right(value: final value) => onSuccess(value)._unsafeRun(env),
Expand All @@ -398,10 +399,10 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => Right(error),
Failure<L>(error: final error) => Right(error),
Die() => Left(cause),
},
Right(value: final value) => Left(Fail(value)),
Right(value: final value) => Left(Failure(value)),
},
),
);
Expand All @@ -414,7 +415,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => Left(Fail(f(error))),
Failure<L>(error: final error) => Left(Failure(f(error))),
Die() => Left(cause),
},
Right(value: final value) => Right(value),
Expand All @@ -426,7 +427,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
Effect<E, C, R> mapErrorCause<C>(C Function(Cause<L> 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),
},
),
Expand All @@ -438,7 +439,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => Left(Fail(fl(error))),
Failure<L>(error: final error) => Left(Failure(fl(error))),
Die() => Left(cause),
},
Right(value: final value) => Right(fr(value)),
Expand All @@ -465,8 +466,8 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => f(error)._unsafeRun(env).then(
(_) => Left(Fail(error)),
Failure<L>(error: final error) => f(error)._unsafeRun(env).then(
(_) => Left(Failure(error)),
),
Die() => Left(cause),
},
Expand All @@ -483,7 +484,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => orElse(error)._unsafeRun(env),
Failure<L>(error: final error) => orElse(error)._unsafeRun(env),
Die() => Left(cause),
},
Right(value: final value) =>
Expand All @@ -509,7 +510,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) =>
Failure<L>(error: final error) =>
Left(Die.current(onError(error))),
Die() => Left(cause),
},
Expand All @@ -527,7 +528,7 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
(env) => _unsafeRun(env).then(
(exit) => switch (exit) {
Left(value: final cause) => switch (cause) {
Fail<L>(error: final error) => f(error)._unsafeRun(env),
Failure<L>(error: final error) => f(error)._unsafeRun(env),
Die() => Left(cause),
},
Right(value: final value) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/fpdart/lib/src/either.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ final class Left<L, R> extends Either<L, R> {
const Left(this.value);

@override
Effect<Never, L, R> get asEffect => Effect._((_) => Left(Fail(value)));
Effect<Never, L, R> get asEffect => Effect._((_) => Left(Failure(value)));

@override
Either<L, C> andThen<C>(C Function(R value) f) => Left(value);
Expand Down
8 changes: 4 additions & 4 deletions packages/fpdart/lib/src/exit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class Die extends Cause<Never> {
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;
Expand All @@ -32,16 +32,16 @@ final class Die extends Cause<Never> {
}

/// Failed with an expected error
final class Fail<L> extends Cause<L> {
final class Failure<L> extends Cause<L> {
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;
Expand Down
4 changes: 2 additions & 2 deletions packages/fpdart/lib/src/option.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ sealed class Option<R> extends IEffect<Never, Never, R> {

Effect<V, L, R> provide<L, V>(L Function() onNone) => Effect._(
(env) => switch (this) {
None() => Left(Fail(onNone())),
None() => Left(Failure(onNone())),
Some(value: final value) => Right(value),
},
);
Expand Down Expand Up @@ -134,7 +134,7 @@ final class None extends Option<Never> {
@override
Effect<Never, Never, Never> get asEffect =>
// ignore: cast_from_null_always_fails
Effect._((_) => Left(Fail(null as Never)));
Effect._((_) => Left(Failure(null as Never)));

@override
Option<C> flatMap<C>(Option<C> Function(Never r) f) => this;
Expand Down

0 comments on commit 229e536

Please sign in to comment.