Skip to content

Instantly share code, notes, and snippets.

@MariaMelnik
Created December 12, 2019 11:07
Show Gist options
  • Save MariaMelnik/1cc6ffaf567f75b91f39053989eeb8ea to your computer and use it in GitHub Desktop.
Save MariaMelnik/1cc6ffaf567f75b91f39053989eeb8ea to your computer and use it in GitHub Desktop.
dart: generics
import 'dart:async';
void main() {
final listOfTasks = [Task<int, int>(1, calc), Task<int, int>(3, calc)];
final task = listOfTasks.first;
method(task: task);
//тут я не могу узнать дженерик тип таски
}
typedef FutureOr<O> TaskFunction<I, O>(I arg);
class Task<I,O>{
final O arg;
final TaskFunction<I,O> fun;
Task(this.arg, this.fun);
}
// void method({Task task}){
void method<I,O>({Task<I,O> task}){
print(task.runtimeType);
Bundle(task.fun);
}
int calc(int arg){
return 1337;
}
class Bundle{
final Function run;
Bundle(this.run);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment