Created
May 16, 2022 10:59
-
-
Save Chinecherem20199/2d27efac516823c6a8213ccab2d068d6 to your computer and use it in GitHub Desktop.
Generic_Function_Dart
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
void main() { | |
var doubleValues = [10.2, 2.2, 3.0, 4.5, 5.5, 6.0, 7.4, 80.0, 9.0]; | |
var stringValues = ['@','*', '&' ]; | |
var newDoubleVlues = <double>[]; | |
var newStringValue = <String>[]; | |
//listOperation(doubleValues, (double val) => newDoubleValues.add(val *3)); | |
listOperation(doubleValues,(double val) => newDoubleVlues.add(val * 5)); | |
listOperation(stringValues,(String val)=> newStringValue.add(val * 2)); | |
print(newDoubleVlues); | |
print(newStringValue); | |
} | |
void listOperation<T>(List<T> list, void Function(T) action) { | |
for (var item in list) { | |
action(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment