Skip to content

Commit dc7d90d

Browse files
Lint cleanup + .fromComposition constructors (#165)
2 parents 417c569 + 37b2d91 commit dc7d90d

41 files changed

Lines changed: 348 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/fpdart/example/logger/logger.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Logger {
6868
var outputEvent = OutputEvent(level, output);
6969
try {
7070
_output.output(outputEvent);
71-
} catch (e, s) {
71+
} on Exception catch (e, s) {
7272
print(e);
7373
print(s);
7474
}

packages/fpdart/example/logger/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Logger {
3939
var outputEvent = OutputEvent(level, output);
4040
try {
4141
_output.output(outputEvent);
42-
} catch (e, s) {
42+
} on Exception catch (e, s) {
4343
print(e);
4444
print(s);
4545
}

packages/fpdart/example/src/either/chain_either.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Future<void> placeOrder() async {
5050
await ordersRepository.addOrder(uid, order);
5151
// third await call
5252
await cartRepository.setCart(uid, const Cart());
53-
} catch (e) {
53+
} on Exception catch (e) {
5454
// TODO: Handle exceptions from any of the methods above
5555
}
5656

packages/fpdart/example/src/list/overview.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ void main() {
88
[1, 2, 3, 4].head;
99

1010
/// Dart: Throws a [StateError] ⚠️
11-
[].first;
11+
<int>[].first;
1212

1313
/// fpdart: `None()`
14-
[].head;
14+
<int>[].head;
1515
}

packages/fpdart/example/src/task/task_and_future.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ Future<bool> withFuture() async {
2020

2121
try {
2222
usernameOrName = await getUsername();
23-
} catch (e) {
23+
} on Exception catch (e) {
2424
try {
2525
usernameOrName = decodeName(await getEncodedName());
26-
} catch (e) {
26+
} on Exception catch (e) {
2727
throw Exception("Missing both username and name");
2828
}
2929
}
3030

3131
try {
3232
email = await getEmail();
33-
} catch (e) {
33+
} on Exception catch (e) {
3434
throw Exception("Missing email");
3535
}
3636

3737
try {
3838
final usernameOrNamePrefix = addNamePrefix(usernameOrName);
3939
final emailPrefix = addEmailPrefix(email);
4040
return await sendInformation(usernameOrNamePrefix, emailPrefix);
41-
} catch (e) {
41+
} on Exception catch (e) {
4242
throw Exception("Error when sending information");
4343
}
4444
}

packages/fpdart/example/src/task_either/finally.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Future<void> imperative() async {
99
try {
1010
final response = await apiRequestMock();
1111
print(response);
12-
} catch (e) {
12+
} on Exception catch (e) {
1313
print("Error: $e");
1414
} finally {
1515
print("Complete!");

packages/fpdart/example/src/task_either/overview.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:fpdart/fpdart.dart';
44
Future<int> imperative(String str) async {
55
try {
66
return int.parse(str);
7-
} catch (e) {
7+
} on Exception catch (e) {
88
return -1; // What does -1 means? 🤨
99
}
1010
}

packages/fpdart/lib/src/date.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'io.dart';
33
/// Constructs a [DateTime] instance with current date and time in the local time zone.
44
///
55
/// [IO] wrapper around dart `DateTime.now()`.
6-
IO<DateTime> get dateNow => IO(() => DateTime.now());
6+
IO<DateTime> get dateNow => const IO(DateTime.now);
77

88
/// The number of milliseconds since the "Unix epoch" 1970-01-01T00:00:00Z (UTC).
99
///

packages/fpdart/lib/src/either.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ Either<L, R> right<L, R>(R r) => Right<L, R>(r);
1515
/// Shortcut for `Either.left(l)`.
1616
Either<L, R> left<L, R>(L l) => Left<L, R>(l);
1717

18-
final class _EitherThrow<L> {
18+
final class _EitherThrow<L> implements Exception {
1919
final L value;
2020
const _EitherThrow(this.value);
2121
}
2222

2323
typedef DoAdapterEither<L> = R Function<R>(Either<L, R>);
24-
DoAdapterEither<L> _doAdapter<L>() =>
25-
<R>(Either<L, R> either) => either.getOrElse(
26-
(l) => throw _EitherThrow(l),
27-
);
24+
DoAdapterEither<L> _doAdapter<L>() => <R>(either) => either.getOrElse(
25+
(l) => throw _EitherThrow(l),
26+
);
2827

2928
typedef DoFunctionEither<L, R> = R Function(DoAdapterEither<L> $);
3029

@@ -70,7 +69,7 @@ sealed class Either<L, R> extends HKT2<_EitherHKT, L, R>
7069
/// If this [Either] is [Left], return `b`.
7170
@override
7271
C foldLeft<C>(C b, C Function(C acc, R b) f) =>
73-
foldMap<Endo<C>>(dualEndoMonoid(), (b) => (C c) => f(c, b))(b);
72+
foldMap<Endo<C>>(dualEndoMonoid(), (b) => (c) => f(c, b))(b);
7473

7574
/// Use `monoid` to combine the value of [Right] applied to `f`.
7675
@override
@@ -135,8 +134,7 @@ sealed class Either<L, R> extends HKT2<_EitherHKT, L, R>
135134
/// Apply the function contained inside `a` to change the value on the [Right] from
136135
/// type `R` to a value of type `C`.
137136
@override
138-
Either<L, C> ap<C>(covariant Either<L, C Function(R r)> a) =>
139-
a.flatMap((f) => map(f));
137+
Either<L, C> ap<C>(covariant Either<L, C Function(R r)> a) => a.flatMap(map);
140138

141139
/// If this [Either] is a [Right], then return the result of calling `then`.
142140
/// Otherwise return [Left].
@@ -311,7 +309,7 @@ sealed class Either<L, R> extends HKT2<_EitherHKT, L, R>
311309
resultList.add(e._value);
312310
} else {
313311
throw Exception(
314-
"[fpdart]: Error when mapping Either, it should be either Left or Right.",
312+
'[fpdart]: Error when mapping Either, it should be either Left or Right.',
315313
);
316314
}
317315
}
@@ -383,7 +381,7 @@ sealed class Either<L, R> extends HKT2<_EitherHKT, L, R>
383381
resultListRights.add(e._value);
384382
} else {
385383
throw Exception(
386-
"[fpdart]: Error when mapping Either, it should be either Left or Right.",
384+
'[fpdart]: Error when mapping Either, it should be either Left or Right.',
387385
);
388386
}
389387
}
@@ -412,7 +410,7 @@ sealed class Either<L, R> extends HKT2<_EitherHKT, L, R>
412410
/// - If [Option] is [None], then return [Left] containing the result of `onNone`
413411
factory Either.fromOption(Option<R> m, L Function() onNone) => m.match(
414412
() => Either.left(onNone()),
415-
(r) => Either.of(r),
413+
Either<L, R>.of,
416414
);
417415

418416
/// If calling `predicate` with `r` returns `true`, then return `Right(r)`.
@@ -450,7 +448,11 @@ sealed class Either<L, R> extends HKT2<_EitherHKT, L, R>
450448
/// **Note**: Make sure to specify the types of [Either] (`Either<L, R>.safeCast`
451449
/// instead of `Either.safeCast`), otherwise this will always return [Right]!
452450
factory Either.safeCast(
451+
// `dynamic`s are use for safe-casting
452+
//ignore: avoid_annotating_with_dynamic
453453
dynamic value,
454+
// `dynamic`s are use for safe-casting
455+
//ignore: avoid_annotating_with_dynamic
454456
L Function(dynamic value) onError,
455457
) =>
456458
Either.safeCastStrict<L, R, dynamic>(value, onError);
@@ -577,7 +579,7 @@ class Right<L, R> extends Either<L, R> {
577579

578580
@override
579581
TaskEither<L, R2> bindFuture<R2>(Future<Either<L, R2>> Function(R r) f) =>
580-
TaskEither(() async => f(_value));
582+
TaskEither(() => f(_value));
581583

582584
@override
583585
TaskEither<L, R> toTaskEither() => TaskEither.of(_value);

packages/fpdart/lib/src/extension/curry_extension.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ extension UncurryExtension4<Input1, Input2, Input3, Input4, Output>
9090
///
9191
/// Inverse of `curry`.
9292
Output Function(Input1, Input2, Input3, Input4) get uncurry =>
93-
(Input1 input1, Input2 input2, Input3 input3, Input4 input4) =>
94-
this(input1)(input2)(input3)(input4);
93+
(input1, input2, input3, input4) => this(input1)(input2)(input3)(input4);
9594
}
9695

9796
extension CurryExtension5<Input1, Input2, Input3, Input4, Input5, Output>

0 commit comments

Comments
 (0)