Created
September 9, 2023 11:31
-
-
Save matanshukry/f1d466d65563d3b053a2ccc8e9e27f7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef GenMethod<T> = String Function(T value); | |
class CustomValue { | |
final String data1; | |
final String data2; | |
CustomValue(this.data1, this.data2); | |
} | |
GenMethod<int> getNumToString() { | |
return (value) => value.toString(); | |
} | |
GenMethod<CustomValue> getCustomValueToString() { | |
return (value) => '${value.data1} ${value.data2}'; | |
} | |
class MyData<T> { | |
final GenMethod<T> method; | |
MyData(this.method); | |
} | |
String dataToString<T>(MyData<T> anyData, T value) { | |
return anyData.method(value); | |
} | |
void main() { | |
final datas = [ | |
MyData<int>(getNumToString()), | |
MyData<CustomValue>(getCustomValueToString()), | |
]; | |
print(datas.runtimeType); | |
final data = datas[0]; | |
print(data.runtimeType); | |
final value = dataToString(data, 2); | |
print(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment