Closed
Description
In the following example I would like to declare compareFn as having the type E x E -> int.
Dart offers no way to do this. An attempt to declare the type directly conflicts with the syntax of a local function definition. Local typedefs are not supported.
class Methods<E> {
final compareFn; // This needs improving
Methods(bool compare(E a, E b)) : compareFn = compare;
bool lessThan(E a, E b) => compareFn(a, b) < 0;
}
main() {
var m = new Methods<int>((int a, int b) => a.compareTo(b));
print('1 < 2 = ${m.lessThan(1, 2)}');
print('2 < 2 = ${m.lessThan(2, 2)}');
}
It seems that the tightest bound is a binary function returning int. The best of the poor alternatives is to have a top-level typedef for Dynamic x Dynamic -> int.