Skip to content

Instantly share code, notes, and snippets.

@Chinecherem20199
Created May 16, 2022 11:02
Show Gist options
  • Save Chinecherem20199/d22a2736d5d66456db56074a1b1cc9a5 to your computer and use it in GitHub Desktop.
Save Chinecherem20199/d22a2736d5d66456db56074a1b1cc9a5 to your computer and use it in GitHub Desktop.
Generic_Function_Dart
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