Skip to content

Instantly share code, notes, and snippets.

@leohmoraes
Last active August 13, 2020 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leohmoraes/ce2ed2e00562f2358b42c341c82b5047 to your computer and use it in GitHub Desktop.
Save leohmoraes/ce2ed2e00562f2358b42c341c82b5047 to your computer and use it in GitHub Desktop.
dart2 - High Order Function
// https://youtu.be/4EzUtx-Q58I?t=1370
// High-order Function
int MyInt = 10;
// Add 1 to [1] //adiciona 1
int add1(int a) => a + 1;
//Halve [a] //metade
int halve(int a) => a ~/ 2;
// Aplicar no segundo
int applyOn2(int Function(int) fn) => fn(2);
void main() {
print('applyOn2(add1): ${applyOn2(add1)}');
print('applyOn2(halve): ${applyOn2(halve)}');
}
//Teste: https://dartpad.dev/ce2ed2e00562f2358b42c341c82b5047
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment