Let's assume I have a generic function that creates list.
List<T> createList<T>() => <T>[];
Can I curry T in createList? The following does not compile:
final createIntList = createList<int>;
Let's assume I have a generic function that creates list.
List<T> createList<T>() => <T>[];
Can I curry T in createList? The following does not compile:
final createIntList = createList<int>;
Well I guess you can't exactly, but try wrapping it in another function like this:
final creareIntList = () => createList<int>();
I know it's not as pretty but it's still a one-liner.
You can partially apply the type argument, but you there is no syntax for it. It's one of the few things in Dart which can only be done using type inference.
If you write:
List<int> Function() createIntList = createList;
then type inference will make this a tear-off equivalent to:
List<int> Function() createIntList = () => createList<int>();
This will be released with Dart v2.15 but can be enabled as an experiment in your analysis_options.yaml file:
analyzer:
enable-experiment:
- constructor-tearoffs