I know Typescript's type system allows some pretty intricate inferences, and I'm wondering how far I can push dart.
I want to create a simple utility function that delays a Future by currying.
Future<T> Function(Future<T> fut) delay<T>(Duration dur) =>
(fut) async => (await Future.wait(
[Future.delayed(dur), fut],
))[1] as T;
The problem with this is that I have to pass T to the delay function, like this:
final delayedPosition<Position>(Duration(seconds: 3));
// later
await delayedPosition(someFutureThatReturnsAPosition);
Ideally, I'd like Dart to infer the type the future is returning so I wouldn't have to specify it myself.
Is this possible? If so, how would it look?
EDIT:
To be clear, what I want to do is to not have to make delay generic and the return type of function returned from delay be inferred from it's argument. This seems to be causing confusion.
e.g.
// declare delay - I don't know what it should look like
final thingThatDelaysAFutureBy3Seconds = delay(Duration(seconds: 3));
// later
final valFromFuture = await thingThatDelaysAFutureBy3Seconds(someFuture);