Closed
Description
Sometimes constructors need to have generics that don't appear in the class itself in order to fully express their type relationships. new Map.fromIterable()
is a good example:
Map.fromIterable(Iterable elements, {K key(element), V value(element)});
If elements
has a generic type, the key()
and value()
callbacks are guaranteed to be passed an argument of that type, but there's currently no way to express that. Using generic types here blocks inference and makes it very difficult to use this API in strong mode. I propose that we be able to declare:
Map.fromIterable<E>(Iterable<E> elements, {K key(E element), V value(E element)});
which would be called like new Map<String, String>.fromIterable<int>(...)
. This syntax allows the user to omit the generic argument to the constructor while retaining it for the class itself if desired.
Metadata
Metadata
Assignees
Labels
No labels