Skip to content

Commit

Permalink
Generate callback and predicate function types in term of the more ge…
Browse files Browse the repository at this point in the history
…neral mapping function.
  • Loading branch information
renggli committed Oct 12, 2024
1 parent b3e784d commit 5ec9542
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 56 deletions.
6 changes: 4 additions & 2 deletions bin/generate_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ Future<void> generateCallback() async {
out.writeln('/// Function types for generic callbacks.');
out.writeln('library;');
out.writeln();
out.writeln("import 'mapping.dart';");

for (var i = 0; i < max; i++) {
out.writeln('/// Callback function type with $i positional '
'argument${i == 1 ? '' : 's'}.');
out.writeln('typedef Callback$i${generify(generateTypes(i))} = '
'void Function(${listify(generateTypeAndArgs(i))});');
'Map$i${generify([...generateTypes(i), 'void'])};');
out.writeln();
}

Expand Down Expand Up @@ -58,12 +59,13 @@ Future<void> generatePredicate() async {
out.writeln('/// Function type for generic predicate functions.');
out.writeln('library;');
out.writeln();
out.writeln("import 'mapping.dart';");

for (var i = 0; i < max; i++) {
out.writeln('/// Predicate function type with $i positional '
'argument${i == 1 ? '' : 's'}.');
out.writeln('typedef Predicate$i${generify(generateTypes(i))} = '
'bool Function(${listify(generateTypeAndArgs(i))});');
'Map$i${generify([...generateTypes(i), 'bool'])};');
out.writeln();
}

Expand Down
44 changes: 17 additions & 27 deletions lib/src/functional/types/callback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,41 @@
/// Function types for generic callbacks.
library;

import 'mapping.dart';

/// Callback function type with 0 positional arguments.
typedef Callback0 = void Function();
typedef Callback0 = Map0<void>;

/// Callback function type with 1 positional argument.
typedef Callback1<T1> = void Function(T1 arg1);
typedef Callback1<T1> = Map1<T1, void>;

/// Callback function type with 2 positional arguments.
typedef Callback2<T1, T2> = void Function(T1 arg1, T2 arg2);
typedef Callback2<T1, T2> = Map2<T1, T2, void>;

/// Callback function type with 3 positional arguments.
typedef Callback3<T1, T2, T3> = void Function(T1 arg1, T2 arg2, T3 arg3);
typedef Callback3<T1, T2, T3> = Map3<T1, T2, T3, void>;

/// Callback function type with 4 positional arguments.
typedef Callback4<T1, T2, T3, T4> = void Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4);
typedef Callback4<T1, T2, T3, T4> = Map4<T1, T2, T3, T4, void>;

/// Callback function type with 5 positional arguments.
typedef Callback5<T1, T2, T3, T4, T5> = void Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
typedef Callback5<T1, T2, T3, T4, T5> = Map5<T1, T2, T3, T4, T5, void>;

/// Callback function type with 6 positional arguments.
typedef Callback6<T1, T2, T3, T4, T5, T6> = void Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
typedef Callback6<T1, T2, T3, T4, T5, T6> = Map6<T1, T2, T3, T4, T5, T6, void>;

/// Callback function type with 7 positional arguments.
typedef Callback7<T1, T2, T3, T4, T5, T6, T7> = void Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
typedef Callback7<T1, T2, T3, T4, T5, T6, T7>
= Map7<T1, T2, T3, T4, T5, T6, T7, void>;

/// Callback function type with 8 positional arguments.
typedef Callback8<T1, T2, T3, T4, T5, T6, T7, T8> = void Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
typedef Callback8<T1, T2, T3, T4, T5, T6, T7, T8>
= Map8<T1, T2, T3, T4, T5, T6, T7, T8, void>;

/// Callback function type with 9 positional arguments.
typedef Callback9<T1, T2, T3, T4, T5, T6, T7, T8, T9> = void Function(T1 arg1,
T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
typedef Callback9<T1, T2, T3, T4, T5, T6, T7, T8, T9>
= Map9<T1, T2, T3, T4, T5, T6, T7, T8, T9, void>;

/// Callback function type with 10 positional arguments.
typedef Callback10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> = void Function(
T1 arg1,
T2 arg2,
T3 arg3,
T4 arg4,
T5 arg5,
T6 arg6,
T7 arg7,
T8 arg8,
T9 arg9,
T10 arg10);
typedef Callback10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
= Map10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, void>;
44 changes: 17 additions & 27 deletions lib/src/functional/types/predicate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,41 @@
/// Function type for generic predicate functions.
library;

import 'mapping.dart';

/// Predicate function type with 0 positional arguments.
typedef Predicate0 = bool Function();
typedef Predicate0 = Map0<bool>;

/// Predicate function type with 1 positional argument.
typedef Predicate1<T1> = bool Function(T1 arg1);
typedef Predicate1<T1> = Map1<T1, bool>;

/// Predicate function type with 2 positional arguments.
typedef Predicate2<T1, T2> = bool Function(T1 arg1, T2 arg2);
typedef Predicate2<T1, T2> = Map2<T1, T2, bool>;

/// Predicate function type with 3 positional arguments.
typedef Predicate3<T1, T2, T3> = bool Function(T1 arg1, T2 arg2, T3 arg3);
typedef Predicate3<T1, T2, T3> = Map3<T1, T2, T3, bool>;

/// Predicate function type with 4 positional arguments.
typedef Predicate4<T1, T2, T3, T4> = bool Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4);
typedef Predicate4<T1, T2, T3, T4> = Map4<T1, T2, T3, T4, bool>;

/// Predicate function type with 5 positional arguments.
typedef Predicate5<T1, T2, T3, T4, T5> = bool Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);
typedef Predicate5<T1, T2, T3, T4, T5> = Map5<T1, T2, T3, T4, T5, bool>;

/// Predicate function type with 6 positional arguments.
typedef Predicate6<T1, T2, T3, T4, T5, T6> = bool Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
typedef Predicate6<T1, T2, T3, T4, T5, T6> = Map6<T1, T2, T3, T4, T5, T6, bool>;

/// Predicate function type with 7 positional arguments.
typedef Predicate7<T1, T2, T3, T4, T5, T6, T7> = bool Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7);
typedef Predicate7<T1, T2, T3, T4, T5, T6, T7>
= Map7<T1, T2, T3, T4, T5, T6, T7, bool>;

/// Predicate function type with 8 positional arguments.
typedef Predicate8<T1, T2, T3, T4, T5, T6, T7, T8> = bool Function(
T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8);
typedef Predicate8<T1, T2, T3, T4, T5, T6, T7, T8>
= Map8<T1, T2, T3, T4, T5, T6, T7, T8, bool>;

/// Predicate function type with 9 positional arguments.
typedef Predicate9<T1, T2, T3, T4, T5, T6, T7, T8, T9> = bool Function(T1 arg1,
T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9);
typedef Predicate9<T1, T2, T3, T4, T5, T6, T7, T8, T9>
= Map9<T1, T2, T3, T4, T5, T6, T7, T8, T9, bool>;

/// Predicate function type with 10 positional arguments.
typedef Predicate10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> = bool Function(
T1 arg1,
T2 arg2,
T3 arg3,
T4 arg4,
T5 arg5,
T6 arg6,
T7 arg7,
T8 arg8,
T9 arg9,
T10 arg10);
typedef Predicate10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
= Map10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, bool>;

0 comments on commit 5ec9542

Please sign in to comment.